To develop and manage Apps Script projects from your terminal rather than the
Apps Script editor, you can use an open-source tool called clasp
.
The clasp
codelab provides an overview of all
clasp
features.
Features
Develop locally
clasp
lets you to develop your Apps Script projects locally. You can
write code on your own computer and upload it to Apps Script when you're
done. You can also download existing Apps Script projects so that you can edit
them when you're offline. Since the code is local, you can use your favorite
development tools like git
when building Apps Script
projects.
Manage deployment versions
Create, update, and view your multiple deployments of your project.
Structure code
clasp
allows you to organize your code into directories, which are preserved
when you upload them to script.google.com. For example:
# On script.google.com: ├── tests/slides.gs └── tests/sheets.gs # Locally: ├── tests/ │ ├─ slides.gs │ └─ sheets.gs
Requirements
clasp
is written in Node.js and distributed via
the npm
tool. Prior to using clasp
, you must have
Node.js version 4.7.4 or later installed.
Installing Node.js requires administrative privileges.
Installation
Once you've installed Node.js, you can use the following npm
command to
install clasp
:
npm install @google/clasp -g
After installation, you can use the clasp
command from any directory on
your computer.
Using clasp
You can use clasp
to handle a variety of tasks from the command line. This
section describes common operations you can use when developing with clasp
.
Login
This command logs in and authorizes management of your Google account's Apps Script projects. Once it is run, you are asked to sign into a Google account where your Apps Script projects are stored.
clasp login
Logout
This command logs out of the command line tool. You must re-login using
clasp login
to re-authenticate with Google before continuing to use clasp
.
clasp logout
Create a new Apps Script project
This command creates a new script in the current directory with an optional script title.
clasp create [scriptTitle]
This command also creates two files in the current directory:
- A
.clasp.json
file storing the script ID. - An
appsscript.json
project manifest file containing project metadata.
Clone an existing project
This command clones an existing project in the current directory. The script must be created or shared with your Google account. You specify the script project to clone by providing its script ID.
To find the Script ID of the project, follow the below steps:
- Open Apps Script project.
- At the left, click Project Settings .
Under IDs, copy the Script ID.
clasp clone <scriptId>
Download a script project
This command downloads the Apps Script project from Google Drive to your computer's file system.
clasp pull
Upload a script project
This command uploads all of a script project's files from your computer to Google Drive.
clasp push
List project versions
This command lists the number and description of each of a script project's versions.
clasp versions
Deploy a published project
You can deploy script projects as web apps, add-ons, or executables. You can
create deployments in the script editor,
in the project manifest, or using clasp
.
To deploy a project with clasp
, first create an immutable version of the Apps
Script project. A version is a "snapshot" of a script project and is similar to
a read-only branched release.
clasp version [description]
This command displays the newly created version number. Using that number, you can deploy and undeploy instances of your project:
clasp deploy [version] [description]
clasp undeploy <deploymentId>
This command updates an existing deployment with a new version and description:
clasp redeploy <deploymentId> <version> <description>
List deployments
This command lists the script project's deployment IDs, versions, and their descriptions.
clasp deployments
Open the project in the Apps Script editor
This command opens a script project in the Apps Script editor. The editor is launched as a new tab in your default web browser.
clasp open
Contribute to the clasp
open-source project
Contribute to clasp
on GitHub.