From bf772ed9f433d710ad3cb5cd55d6a82cf0f8daba Mon Sep 17 00:00:00 2001 From: "ry.yamafuji" Date: Sun, 7 Dec 2025 18:38:04 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=83=97=E3=83=AC=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=B7=E3=83=BC=E3=83=88=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 54 +++++++++++++++++++++++++++++++++++++- gas-sample/.clasp.json | 16 +++++++++++ gas-sample/Code.js | 4 +++ gas-sample/appsscript.json | 7 +++++ readme/gcs.md | 0 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 gas-sample/.clasp.json create mode 100644 gas-sample/Code.js create mode 100644 gas-sample/appsscript.json create mode 100644 readme/gcs.md diff --git a/README.md b/README.md index a0bdefd..d8eea06 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,55 @@ # gas-common-dev -Google Apps Scriptに関する共通ソース +Google Apps Scriptに関する共通ソース + +## Develop + +Google Apps Script (GAS) は通常ブラウザのエディタで書きますが、 +VS Code でローカル開発 → GAS にデプロイ → ローカルである程度テストという流れも可能です。 + +#### GASの開発に必要なもの + +* Node.js / npm +* Google アカウント +* clasp +* VS Code + +#### 開発構築 + +```sh +# clasp をインストール +npm install -g @google/clasp +# GAS へのログイン +clasp login +# GASプロジェクトを作成する(JS) +mkdir gas-sample +cd gas-sample +clasp create --type standalone --title "Sample GAS Project" +# スプレッドシートの場合 +clasp create --type sheets --title "My Sheet Project" +``` + +作成されたCode.jsにソースを書きます + +Code.js +```js +function helloWorld() { + const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); + sheet.getRange(1, 1).setValue("Hello from JavaScript!"); +} +``` + +GASにデプロイする + +```sh +clasp push +# 強制 +# clasp push --force +``` + +デプロイしたプロジェクトをスプレッドシートと紐づける必要があります + +```sh +clasp create --type sheets --title "My Sheet Project" +``` + diff --git a/gas-sample/.clasp.json b/gas-sample/.clasp.json new file mode 100644 index 0000000..1d995a8 --- /dev/null +++ b/gas-sample/.clasp.json @@ -0,0 +1,16 @@ +{ + "scriptId": "1JhI9GMgJpjI-ogbtfOFYCRhlMd3NnlkQs6dNuvS0JwyuwMPG8Wct-OuM", + "rootDir": "", + "scriptExtensions": [ + ".js", + ".gs" + ], + "htmlExtensions": [ + ".html" + ], + "jsonExtensions": [ + ".json" + ], + "filePushOrder": [], + "skipSubdirectories": false +} \ No newline at end of file diff --git a/gas-sample/Code.js b/gas-sample/Code.js new file mode 100644 index 0000000..7b3abcf --- /dev/null +++ b/gas-sample/Code.js @@ -0,0 +1,4 @@ +function helloWorld() { + const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); + sheet.getRange(1, 1).setValue("Hello from JavaScript!"); +} \ No newline at end of file diff --git a/gas-sample/appsscript.json b/gas-sample/appsscript.json new file mode 100644 index 0000000..3cf1d24 --- /dev/null +++ b/gas-sample/appsscript.json @@ -0,0 +1,7 @@ +{ + "timeZone": "America/New_York", + "dependencies": { + }, + "exceptionLogging": "STACKDRIVER", + "runtimeVersion": "V8" +} \ No newline at end of file diff --git a/readme/gcs.md b/readme/gcs.md new file mode 100644 index 0000000..e69de29