CLASP
New 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) π
Source: https://developers.google.com/apps-script/guides/typescript
Source: https://github.com/google/clasp/blob/master/docs/typescript.md
- 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 --watch
TypeScript Modules, exports and imports π
Source: https://github.com/google/clasp/blob/master/docs/typescript.md#the-namespace-statement-workaround
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 directly
Steps if using Javascript (JS) π
- Add js_lib
git submodule add ../js_lib.git
Converting an existing Javascript (JS) project to TypeScript (TS) π
- Copy over from template to update ignore and hooks last step in new
- Remove
js_lib
if in use see removal instructions for submodule - Change all
.js
files to.ts
files - Follow normal instructions from New TS project
Useful Commands π
clasp clone <scriptID>
Clone an existing projectclasp pull
Download a script projectclasp push
Upload a script projectclasp open
Open 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