Appscript is built on Apps script api
Considering you are familiar with Appscript in this article we will go through the cli tool “Clasp” released by Google which allows developers to code offline a new project or clone a project rather than using their online script editor. This gives the feasibility to develop bigger codebases in your favourite tools & editors.
Make sure you have node version ≥ 4.7.4 . If needed you can install it from here
Now install Clasp cli using npm
npm i @google/clasp -g
Before you start using Clasp you will have to login, as you would while using firebase cli
After this you will be asked to login with a link provided on the terminal. The access token and such user specific details is kept in ~/.clasprc.json.
To initialize a project
clasp create SCRIPT_NAME_HERE
This initializes you project and creates two files in the current directory “appsscript.json” & “.clasp.json” and a new script file in your account, you can check it out at https://script.google.com with the filename as SCRIPT_NAME_HERE.
or you can clone a project using
clasp clone SCRIPT_ID_HERE
To find your script id GOTO the script editor > File > Project preferences > Info >> Look of script Id here.
Project structure on script.google.com:
local cloned project structure:
clone a local configuration file
.clasp.json is created.
this can be customised
scriptId : "" # required,
rootDir : "" # default current directory
Now lets walkthrough the basic cli commands in clasp.
clasp login --no-localhost
# --no-localhost this will instead allow you to enter # code instead of running local server anything is ok.
To pull a project
To push files to project
To open the current project in script.google.com
clasp open # in the project directory
Listing all deployment ids
Deploy current project
clasp deploy [version] [description]
by providing version number you can manage your deployment versions as off git. Currently clasp doesnt provide any kind of git level version management although git can be used inside the project and to ignore like in git clasp has a .claspignore file.
Redeploying the same version
clasp redeploy <previousDeploymentId> <version> <description>
Create a new version with some description
clasp version [description]
To list all versions of projects