You can develop and test clasp
on your computer by following these steps.
Note:
clasp
uses TypeScript to provide autocompletion and linting when developing. Use an IDE like Visual Studio Code for TypeScript autocompletion.
- Install
tsc
:npm install -g typescript
- Remove your local version of
clasp
:npm uninstall -g @google/clasp
- This will prevent errors when updating
node_modules
.
- This will prevent errors when updating
- Fork the
clasp
repository - Clone it to your device
git clone https://github.com/<your-github-username>/clasp.git
cd clasp
- Install dependencies:
npm install
npm run build
clasp <command>
If you're seeing build errors, try deleting the local node_modules
and re-building clasp
from scratch:
rm package-lock.json
rm -rf node_modules/
npm run build-fresh
This is what @grant's terminal looks like:
sudo npm run build-fresh
Password:
> @google/clasp@1.5.3 build-fresh ~/Documents/github/google/clasp
> npm cache clean --force && npm i && npm run build
npm WARN using --force I sure hope you know what you are doing.
up to date in 2.464s
> @google/clasp@1.5.3 build ~/Documents/github/google/clasp
> tsc --project tsconfig.json && npm i -g --loglevel=error
/usr/local/bin/clasp -> /usr/local/lib/node_modules/@google/clasp/src/index.js
+ @google/clasp@1.5.3
updated 1 package in 2.768s
After seeing that message, you're ready to test out clasp
!
clasp
has some unit tests that help detect errors.
The tests require an existing Apps Script project and corresponding GCP project. Follow the instructions in the Apps Script documentation to create a script with a standard GCP project.
Once created, set the following environment variables. Replace the values with your corresponding script and project IDs.
SCRIPT_ID=15wKnP0deQOjCvCDmpkMo9npnosUYYvaLjNtIFEnOmNxxxxxxxx
PROJECT_ID=stable-century-447xxxxxxx
Build and run tests with these commands:
npm run build;
npm run test
See /test/ for more information.
- Use
npm run lint
to find common style errors. TravisCI will autodetect these errors too. - Download sort-imports for VSC to automatically sort imports.
- Use
npm run prettier
to make the code pretty.
- Build
index.js
locally..gitignore
/.npmignore
will hide js/ts files appropriately. - Bump version:
npm version [major|minor|patch] -m "Bump version to %s"
- Push to GitHub:
git push --tags
- Publish with:
npm run publish