Skip to content

IkumaTadokoro/esbuild-gas-template

Repository files navigation

Google Apps Script Template powered by esbuild

Starter template for Google App Script development in local.

image

How to use

Preparations(First time only)

  1. Install clasp
npm install -g clasp
  1. Login Google
clasp login
  1. npm install

Setup Project

GitHub Template Create a repo from this template on GitHub

  1. Create your project
npm run gen -name=<YOUR_PROJECT>
# ex) npm run gen -name=sample-project
# Above command creates app/sample-project with template
  1. Fix the project_id in app/<YOUR_PROJECT>/.clasp.json to your GAS project.
{
  "scriptId": "<YOUR_SCRIPT_ID>",
  "rootDir": "./dist"
}
  1. 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 of index.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
  1. Compile & transpile your scripts with esbuild.
npm run -w <YOUR_PROJECT> build
# or
cd app/<YOUR_PROJECT>
npm run build
  1. Push your scripts to Google Apps Script with clasp.
cd app/<YOUR_PROJECT>
clasp push
# open project in browser
clasp open

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published