I’m starting a new project, and the requirements for this project is to write some Google App Script, copy the source code over to BitBucket. Thankfully there’s an easy way to store Google App Script locally to your computer and then push those changes back to Google as well as
git commit changes and have the code stored safely on a remote repository.
Here’s how you too can set up your computer and environment up.
google/clasp jump onto your terminal, and if you haven’t (as I haven’t yet), initialise npm in your folder:
$ npm init This utility will walk you through creating a package.json file. ...
After progressing through all the prompts I then run the command to install
npm install clasp:
$ npm install clasp Installing @google/clasp... Installed @google/[email protected]
Your terminal prompt should inform you of the success of your
google/clasp module installation.
Login to clasp
google/clasp know where to pull and push scripts to it needs to connect to your Gmail account. Therefore, the first command you need to run once you’ve successfully installed it is
$ clasp login
A link then pops up underneath the prompt and when you click on it you will be redirected to a Google login screen where you will need to enter your credentials and provide the necessary permissions for the script to function properly. You will know everything is successful when you see back in your terminal window:
If you have already started a Google App Script project you may be able to clone it to your current project. There are two ways you can try to pull in a project’s script:
clasp cloneand then select from the options presented by using your up and down arrow keys to navigate through the list.
$ clasp clone ? Clone which script? (Use arrow keys) > ABC ...
If, however, you have many scripts, and the script you’re looking for isn’t presented you will need to exit from the prompt window using
- Enter the specific Script ID as a parameter to your clone command, like so:
$ clasp clone ABC123...
ABC123... is the Script ID you can obtain by opening up your Google App Script console for the project you’re hoping to clone and clicking on File > Project Properties. From the modal window that pops up, copy the Script ID hash.
If needed you might want to exclude certain files from
clasp pushing them into your script folder in Google. If so, create a
.claspignore file and populate it with files you don’t want to push up.
.claspignore looks as follows:
.DS_Store node_modules/** node_modules/**/.*/** node_modules/**/.* .idea .git
To update your code on the Google Server you just need to
push your code back up.
$ clasp push
You can check your code is working by opening your project’s Google App Script code.
In this short article you’ve learned the following:
- How to copy a project in Google Apps to your local computer using the
- How to exclude certain files and folders from your project.
- How to make local changes and push your changes up to Google Apps.
If you have your code wrapped as a library which other code references you’ll need to create a version and then reference the new version in your code dependencies.
If you’d like to discover how you can create a library for your common Google Apps code, or to prevent someone from editing your code on your Google Sheets or other Google Apps, then check out my next post on creating a Google Apps library.
In Microsoft Word you can control whether or not you want to see the white space characters in your document. This helps to check you haven't incorrectly inserted a tab where a space should have gone...
Very similar to our previous article on how to make a header row in Google Sheets, in this article we'll show how you can lock a column in Google Sheets. To lock a column in Google Sheets easily...