This project is a Node-powered template designed for developing Google Apps Script (GAS) projects. It provides a robust development environment that addresses common challenges in GAS development, such as ES6 module support, TypeScript integration, local development for client-side and server-side code, NPM module integration, comprehensive mocking for google.script.run (including success and failure scenarios), unit testing, and CI/CD workflows.
Key Technologies:
- Build Tool: Vite
- Client-Side Framework: Alpine.js
- Styling: Tailwind CSS with Daisy UI
- Linting: ESLint
- Formatting: Prettier
- Testing: Vitest
- Git Hooks: Husky
- GAS CLI:
@google/clasp
The template supports building client-side HtmlService code, server-side Google Apps Script code, and NPM library code, with distinct build processes for each. It also includes a custom Vite plugin to facilitate GAS-specific bundling requirements.
To install the template, use npx apps-script-engine [directory-name] [--ts]. For example, to create a new project in the current directory:
npx apps-script-engine . --tsAfter installation, ensure npm, git, and clasp are installed globally.
- Local Development Server (Client-Side):
This starts a Vite development server, typically on port 5173, for local client-side development with instant loading and auto-reloading.
npm run dev
-
Build Client-Side (
HtmlService) Code:npm run build:ui
Bundles client-side code into
dist/gas/ui. -
Build Server-Side Google Apps Script Code:
npm run build:gas
Bundles server-side code into
dist/gas/serverand extracts public exports intodist/gas/exports.js. -
Build NPM Library Code:
npm run build:node
Bundles library code into
dist/nodefor ES6 and CommonJS module formats. -
Build Copy-and-Paste Code:
npm run build:cp
Bundles
src/app.jsinto a single, minified IIFE file indist/copy-paste/app.iife.js. -
Comprehensive Build (UI and GAS):
npm run build
-
Build All Libraries (Copy-Paste, Node, GAS):
npm run build:lib
- Push Code to Google Apps Script Project:
This command uses
npm run push
claspto push the built code to the configured Apps Script project.
The template supports multiple environments (dev, uat, prod) by copying environment-specific .clasp.json and other configuration files.
-
Switch to Development Environment:
npm run env:dev
-
Switch to UAT Environment:
npm run env:uat
-
Switch to Production Environment:
npm run env:prod
-
Run Prettier and ESLint with auto-fix:
npm run format
This command runs
prettier --writeandeslint --fixon all JavaScript files in thesrcdirectory. -
Check Prettier Formatting:
npm run prettier
-
Fix Prettier Formatting:
npm run prettier:fix
-
Run ESLint Check:
npm run lint
-
Fix ESLint Issues:
npm run lint:fix
- Run Unit Tests:
This command executes tests using Vitest.
npm t
The project uses Husky to configure a pre-commit Git hook. This hook automatically runs npm run format && npm t before each commit, ensuring code quality and test coverage.