CLASP
Chester Wyke April 17, 2023 Updated: April 26, 2025 #MiscNew project setup
- Create New Repo using Git GUI
- Create Scripts project (On Google Scripts, Sheets, etc.)
- Clone Scripts Project into repo folder using clasp
clasp clone <scriptID>
- Copy Hook and .gitignore from template
folder
repos/zTemplates/clasp/CopyContentsToProjectRoot/or create folder to copy from using this zip file.
Steps if using TypeScript (TS)
This version is was based on the then version of https://developers.google.com/apps-script/guides/typescript which linked out to https://github.com/google/clasp/blob/master/docs/typescript.md but they no longer provide typescript. See excerpt from the github readme below.
Drop typescript support
Clasp no longer transpiles typescript code. For typescript projects, use typescript with a bundler like Rollup to transform code prior to pushing with clasp.
- Add Type definitions for Apps Script
npm i -S @types/google-apps-script
-
Add ts_lib
- Part of wykies
git submodule add ../ts_lib.git- Outside of wykies
git submodule add git@github.com:wykies/ts_lib.git -
(Optional) Use the following command to push and watch the ts files. Watch is not required.
clasp push --watchTypeScript Modules, exports and imports
Original Source was: https://github.com/google/clasp/blob/master/docs/typescript.md#the-namespace-statement-workaround but they are dropping typescript support.
Instead of normal imports use the following as import is not supported in GAS
// module.ts
namespace MyLib {
export function foo() {
}
function bar() {
} // this function can only be addressed from within the `MyLib` namespace
}// anyFiles.ts
MyLib.foo(); // address a namespace's exported content directlySteps if using Javascript (JS)
- Add js_lib
git submodule add ../js_lib.gitConverting an existing Javascript (JS) project to TypeScript (TS)
- Copy over from template to update ignore and hooks last step in new
- Remove
js_libif in use see removal instructions for submodule - Change all
.jsfiles to.tsfiles - Follow normal instructions from New TS project
Useful Commands
clasp clone <scriptID>Clone an existing projectclasp pullDownload a script projectclasp pushUpload a script projectclasp openOpen the project in the Apps Script editor
Ignore files
File location
Source: https://github.com/google/clasp#ignore-file-claspignore
Put a .claspignore in the root of the project’s directory.
All paths are relative to root.
Format
Uses multimatch
*matches any number of characters, but not /?matches a single character, but not /**matches any number of characters, including /, as long as it’s the only thing in a path part{}allows for a comma-separated list of “or” expressions!at the beginning of a pattern will negate the match
Example
js_lib/**Installation
Source: https://developers.google.com/apps-script/guides/clasp#installation
First install Install Node.js
npm install @google/clasp -g