Starter template for Google App Script development in local.
GitHub Template Create a repo from this template on GitHub
- Fix the project_id in
.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`
- Compile & transpile your scripts with esbuild.
# `bundle.js` are output to the `dist` directory
npm run build
-
(First time only) Copy
src/appsscript.json
to thedist
directory. See the Known Issues -
Push your scripts to Google Apps Script with clasp.
# Upload and open your scripts.
npm run deploy
- The clasp requires
appsscript.json
(manifest of Google Apps Script) to be included in thedist
, but it is not automated (I haven't figured out how to do it automatically with esbuild).