Command Line Interface using clasp

clasp is an open-source tool, separate from the Apps Script platform, that lets you develop and manage Apps Script projects from your terminal rather than the Apps Script editor.

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 i @google/clasp -g

After installing, the clasp command is available usable 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 it's script ID. You can find the script ID of a project by opening the project in the Apps Script editor and selecting File > Project properties > Info.

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](/apps-script/concepts/deployments] in the script editor, in the project [manifest](/apps-script/concepts/manifests], 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.

Send feedback about...

Apps Script
Apps Script