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