-
Install clasp. Open a terminal anywhere, and run:
npm i @google/clasp -g
-
Log into clasp. Open a terminal anywhere, and run:
clasp login
-
Create a Google Doc. Open
Tools > Script editor
. Give the project aNAME
and save it. The files in this project template will soon be overriden. -
Open
File > Project properties
and copy the Script ID value. -
Pull a fresh clone of Sketch-n-Script and then
cd Sketch-n-Script
. -
Run
clasp clone NAME
. -
The last step will create a starter skeleton
Code.js
file. Rungit checkout Code.js
to revert to the version fromSketch-n-Script
. -
Create a file
.clasp.json
that contains the the following:{"scriptId":"XXX"}
Replace
XXX
by the Script ID obtained above. -
Try making a change to
Code.js
(e.g. change the string argument to.setSetTile'). Then run
clasp push`.If asked for confirmation, enter
y
for Yes.You might have to go to https://script.google.com/home/usersettings to activate the Script API (change it from Off to On), and then re-run
clasp push
. -
Refresh your script page from the browser, or run
clasp open
to open the script in a new browser window. -
Go to
Run > Run function > onOpen
. Accept the permissions. A menu appears under theAdd-on
menu, click it, thenStart
to open the side bar. -
(I had trouble with the previous step: Instead, I:) Open
Run > Test as add-on...
and then picke a Doc on which to testNAME
. Then, from inside that Doc, go toAdd-ons > NAME > Start
to launch the add-on.
Now the add-on is working for this script.
You can develop the add-on locally or in the online script editor. To push changes made locally, run
clasp push
To pull changes made online, run
clasp pull
/!\ Be careful if you make changes locally AND online. The last two commands will overwrite each other's file.
If you made changes both locally and online, do the following.
Run locally:
git stash
clasp pull
git stash pop
clasp push
So that now the changes have been merged and are in sync. Remember to commit any meaningful changes.
/!\ Always pull your online changes locally before merging other branches locally.
If you don't want that clasp push some files or folders, note that clasp
ignores files
- That start with a .
- That don't have an accepted file extension
- That are ignored (filename matches a glob pattern in the
.claspignore
file)
If running the first time, install the necessary dependencies:
npm install
Typescripts files are located in src/
. To convert them to javascript files in the add-on
folder, run
npm run compile
npm run test
- Make sure all changes are pushed online.
- Make sure
.clasp.json
is referring to the correct script ID. - Go to File > Manage version, enter a name for this version, and click on "Save a new version", then "Ok"
- In the online interface for the script editor, go to: Publish > Deploy as a Google Docs add-on. On the top right, select the name of the version you just saved. Click Update published project. It will lead you to the developer tools where you can update the documentation.
More instructions about the clasp command line can be found here: https://codelabs.developers.google.com/codelabs/clasp/