Starter template for Google App Script development in local.
- Install clasp
npm install -g clasp
- Login Google
clasp login
npm install
GitHub Template Create a repo from this template on GitHub
- Create your project
npm run gen -name=<YOUR_PROJECT>
# ex) npm run gen -name=sample-project
# Above command creates app/sample-project with template
- Fix the project_id in
app/<YOUR_PROJECT>/.clasp.json
to your GAS project.
{
"scriptId": "<YOUR_SCRIPT_ID>",
"rootDir": "./dist"
}
- Write your code with TypeScript and any npm libraries with ESM styles.
- Google Apps Script requires executable function to be registered globally.
- In this template, the
main
function ofindex.ts
is registered globally, so if you need a single function, you can write the process you want to execute from GAS here(Functions, not registered globally, are treated as private). - If you want to register multiple executable functions, do not forget to register them in global!
import { sum } from './utils'
const main = (): void => {
Logger.log(sum(12, 20))
}
const sub = (): void => {
Logger.log(sum(32, 28))
}
declare let global: any
global.main = main
global.sub = sub // Can be called directly from Google Apps Script as `sub`
- If you want to create reusable function, you should write and import
lib/src/*.ts
- Compile & transpile your scripts with esbuild.
npm run -w <YOUR_PROJECT> build
# or
cd app/<YOUR_PROJECT>
npm run build
- Push your scripts to Google Apps Script with clasp.
cd app/<YOUR_PROJECT>
clasp push
# open project in browser
clasp open