Apps scirpt allows you to interact & integrate all these Google products.
If you are not familiar with Apps scripts check out this article:
Apps script is this small scripting language that allows you to develop apps/integrations/addons/extensions for Google suite. Common applications could be storing a form data into Google sheets directly, automating emails etc..
Previously it was only done in Apps script editor. But now the Apps script API allows developers to write apps and extends the functionalities that were limited to the editor.
Considering you are familiar with Apps script 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
clasp login
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:
project_folder/slides.gs
local cloned project structure:
project_folder/slides.js
after create
or 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
# auth code instead of running local server.
To logout
clasp logout
To pull a project
clasp pull
To push files to project
clasp push
To open the current project in script.google.com
clasp open # in the project directory
Listing all deployment ids
clasp deployments
Deploy current project
clasp deploy [version] [description]
by providing version number you can manage your deployment versions. Currently clasp doesnt provide any kind of git level version management although git can be used inside the project.
Ignoring files in clasp, create .claspignore like a .gitignore 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
clasp versions
--
Clasp Github repo : https://github.com/google/clasp
Apps script api : https://developers.google.com/apps-script/api/