npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clasp-env

v1.0.1

Published

CLI clasp environment switcher

Downloads

18

Readme

Welcome to clasp-env 👋

Version Documentation License: ISC Twitter: wildhogsm GitHub LinkedIn Wurkspaces.dev

CLI clasp environment switcher 🏠 Homepage

Usage

Run the following command (without prior installation):

npx clasp-env --folder <path_to_folder> --scriptId <apps_script_project_id>

Run Tests

npm run test

Project Description

The Strategy

clasp-env is a command-line utility that allows you to switch between different Google Apps Script environments. When you write your code locally and deploy your Google Apps Script code with clasp, it creates a .clasp.json file that contains the scriptId property. This tells clasp which project it needs to push the code to.

When working in a team and/or with a client, you want to have multiple environments. At minimum, you probably want a dev environment (or multiple ones) in which you are working, and a test environment in which the client or your team can run acceptance tests before production. Of course, they must both be separate from the production environment.

clasp-env allows you to update the scriptId property in the .clasp.json file so that the code gets pushed to the intented project environment. The <path> indicates the path to the folder where the .clasp.json file is located.

It takes two arguments, <path_to_folder> and <apps_script_project_id>, both of which are mandatory. It then looks up the .clasp.json file in the folder and sets its scriptId to the one specified in the parameter.

Include in package.json Scripts

You don’t want to type out the folder paths and IDs every time you want to change the scripts, so it’s best to save them in the package.json's scripts property like so:

{
  "scripts": {
    "clasp/dev": "npx clasp-env --folder <path_to_folder> --scriptId <dev_apps_script_project_id>",
    "clasp/prod": "npx clasp-env --folder <path_to_folder> --scriptId <prod_apps_script_project_id>"
  }
}

To switch to the prod environment, simply run npm run clasp/prod in the terminal and the scriptId property will be updated.

It’s also a good idea to combine clasp-env with the clasp push command. Accordingly, as soon as you switch environments, clasp will begin pushing your code to the project. The -w option at the end stands for “watch,” meaning that clasp will push your code every time you save a file:

{
  "scripts": {
    "push/dev": "npx clasp-env --folder <path_to_folder> --scriptId <dev_apps_script_project_id> && cd <path_to_folder> && clasp push -w",
    "push/prod": "npx clasp-env --folder <path_to_folder> --scriptId <prod_apps_script_project_id> && cd <path_to_folder> && clasp push -w"
  }
}

To switch to the prod environment and push your code there, run npm run push/prod in the terminal.

Note that the folder must be a relative path from the project root. A typical project structure may look something like this:

my-app/
├─ node_modules/
├─ gas/
│  ├─ Code.js
│  ├─ appsscript.json
│  ├─ .clasp.json
├─ src/
│  ├─ index.js
├─ .gitignore
├─ package.json
├─ package-lock.json
├─ README.md

The Google Apps Script files, including .clasp.json, are in the gas folder; thus, the command should look like this:

npx clasp-env --folder gas –-scriptId 1k1bnhRoqrESBvS95ZJncRYpsgSdM4anxwo3yI2Egs_Q

.gitignore

If you use git with your projects, you’ll also want to add .clasp.json files to .gitignore so that it’s not considered a change in the source code every time you switch environments. You can accomplish this by adding this line to the .gitignore file: **/.clasp.json

Related Articles

Author

👤 Dmitry Kostyuk

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator