Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@google/clasp
Advanced tools
Develop Apps Script projects locally using clasp (Command Line Apps Script Projects).
To get started, try out the codelab!
🗺️ Develop Locally: clasp
allows you to develop your Apps Script projects locally. That means you can check-in your code into source control, collaborate with other developers, and use your favorite tools to develop Apps Script.
🔢 Manage Deployment Versions: Create, update, and view your multiple deployments of your project.
📁 Structure Code: clasp
automatically converts your flat project on script.google.com into folders. For example:
tests/slides.gs
tests/sheets.gs
tests/
slides.js
sheets.js
First download clasp
:
sudo npm i @google/clasp -g
Then enable Apps Script API: https://script.google.com/home/usersettings
(If that fails, run this:)
sudo npm i -g grpc @google/clasp --unsafe-perm
clasp
clasp login [--no-localhost]
clasp logout
clasp create [scriptTitle] [scriptParentId]
clasp clone <scriptId>
clasp pull
clasp push [--watch]
clasp open [scriptId]
clasp deployments
clasp deploy [version] [description]
clasp redeploy <deploymentId> <version> <description>
clasp version [description]
clasp versions
clasp list
clasp logs [--json] [--open]
Logs the user in. Saves the client credentials to an rc file.
--no-localhost
: Do not run a local server, manually enter code instead.--ownkey
: Save .clasprc.json file to current working directory.Logs out the user by deleting client credentials.
clasp logout
Creates a new script project.
scriptTitle
: An optional project title.scriptParentId
: An optional project parent Id. The Drive ID of a parent file that the created script project is bound to. This is usually the ID of a Google Doc, Google Sheet, Google Form, or Google Slides file. If not set, a standalone script project is created.clasp create
clasp create "My Script"
clasp create "My Script" "1D_Gxyv*****************************NXO7o"
Fetches a project from either a provided or saved script id. Updates local files with Apps Script project.
clasp pull
Force writes all local files to the script management server.
clasp push
Ignores files:
Lists files that will be written to the server on push
.
clasp status
Ignores files:
Opens the clasp
project on script.google.com. Provide a scriptId
to open a different script.
scriptId
: The optional script project to open.clasp open
clasp open [scriptId]
List deployments of a script
clasp deployments
Creates a version and deploys a script. The response gives the version of the deployment.
version
: The version number.description
: The deployment description.clasp deploy
clasp deploy 4
clasp deploy 7 "Updates sidebar logo."
Undeploys a deployment of a script.
deploymentId
: deploymentId The deployment ID.clasp "undeploy 123"
Updates deployments of a script.
deploymentId
: deploymentId The deployment ID.version
: version The target deployment version.description
: description The reason why the script was redeployed.clasp redeploy 123 3 "Why I updated the deployment"
List versions of a script.
clasp versions
Creates an immutable version of the script.
description
: description The description of the script version.clasp version
clasp version "Bump the version."
Lists your most recent 10 Apps Script projects.
clasp list # helloworld1 – xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
Prints out 5 most recent the StackDriver logs.
json
: json Output logs in json format.open
: open Open StackDriver logs in a browser.Remotely executes an Apps Script function. This function runs your script in the cloud. You must supply the functionName params. For now, it can only run functions that do not require other authorization.
functionName
: functionName The function in the script that you want to run.clasp run 'sendEmail'
Displays the help function.
clasp help
clasp open
.Resources > Cloud Platform project...
project-id-xxxxxxxxxxxxxxxxxxx
into .clasp.json
. It should look like this:{
"scriptId":"14Ht4FoesbNDhRbbTMI_IyM9uQ27EXIP_p2rK8xCOECg5s9XKpHp4fh3f",
"projectId": "project-id-xxxxxxxxxxxxxxxxxxx"
}
Now you can run clasp logs
for this project.
clasp logs
Use clasp logs
to see recent log messages from StackDriver. For example:
clasp logs
ERROR Sat Apr 07 2018 10:58:31 GMT-0700 (PDT) myFunction my log error
INFO Sat Apr 07 2018 10:58:31 GMT-0700 (PDT) myFunction info message
clasp logs --json
: See the logs in JSON format.clasp logs --open
: Open the StackDriver logs in your browser..claspignore
)Like .gitignore
, .claspignore
allows you to ignore files that you do not wish to not upload on clasp push
. Steps:
.claspignore
in your project's root directory.clasp push
. Note: The .claspignore
file is parsed with Anymatch, which is different from .gitignore
, especially for directories. To ignore a directory, use syntax like **/node_modules/**
.A sample .claspignore
ignoring everything except the manifest and build/main.js
:
**/**
!build/main.js
!appsscript.json
.clasp.json
)When running clone
or create
, a file named .clasp.json
is created in the current directory to describe clasp
's configuration for the current project. The following configuration values can be used in it:
scriptId
(required)Specifies the id of the Google Script project that clasp will target. It is the part located inbetween /d/
and /edit
in your project's URL: https://script.google.com/d/<SCRIPT_ID>/edit
.
rootDir
(optional)Specifies the local directory in which clasp will store your project files. If not specified, clasp will default to the current directory.
The library requires Node version >= 4.7.4. Use this script to check your version and upgrade Node if necessary:
node -v # Check Node version
sudo npm install n -g
sudo n latest
The Apps Script CLI uses TypeScript to provide autocompletion and linting when developing. Use an IDE like Visual Studio Code for TypeScript autocompletion.
tsc
: npm install -g typescript
clasp
: sudo npm uninstall -g @google/clasp
node_modules
.npm i
sudo npm run build;
clasp <command>
(If you see build errors, run sudo npm run build-fresh
)
sudo npm run build;
npm run test
See tests/ for more information.
npm run lint
to find common style errors.The core "How To" section of the docs is generated from JSDoc comments from index.ts
.
Run npm run docs
to build the "How To" section. Copy/paste that section into the README.md.
clasp
to npm (admin)index.js
locally. .gitignore
/.npmignore
will hide js/ts files appropriately.npm version [major|minor|patch] -m "Bump version to %s"
npm run publish
The main purpose of this tool is to enable local Apps Script development. If you have a core feature or use-case you'd like to see, find a GitHub issue or create a detailed proposal of the use-case. PRs are very welcome! See the issues (especially good first issue and help wanted).
tests/test.ts
, try cases that the PR may affect.npm run lint
.⚡ Powered by the Apps Script API.
FAQs
Develop Apps Script Projects locally
The npm package @google/clasp receives a total of 16,706 weekly downloads. As such, @google/clasp popularity was classified as popular.
We found that @google/clasp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.