Skip to content

gotofritz/copier-template-clasp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

copier-template-clasp

A copier template for a Clasp project, that allow you to code Google Apps Script locally with typescript. This is based on PopGoesTheWza own template - he was one of Clasp's main contributors

I have written about the why in a blog post. Read on for the hows

Prerequisites

This is Copier boilerplate (if you are unfamiliar with it, it's kind of a Python version of the old Yeoman and shares similarities with Plop.js). To seed your own project you will need Python >= 3.7. If you don't have Python installed I suggest using pyenv to manage it (pyenv is similar to Node's nvm). On a Mac:

❯ brew install pyenv
...

# latest stable version at the time of writing
❯ pyenv install 3.11
...

❯ pyenv global 3.11
❯ pip install copier
...

To run the project you will also need the clasp tool

# npm, pnpm, yarn, or any of these shinier alternatives all work
❯ npm install -g @google/clasp
...

And if you want the repo in watch mode, so that it automatically bundles the project when you save, you need fswatch

❯ brew install fswatch
...

Generating a project from the boilerplate

Once all the prerequisites are installed you can simply create a project with

# NOTE: `--trust` is needed to run the tasks which do most of the work.
# Their definition is in ./copier.yml
# If you don't feel comfortable passing that option, just replicate
# commands from the _tasks section of that file in the CLI yourself, e.g.
# cd {{project_name}}
# (p)npm install
# ...
❯ copier copy https://github.com/gotofritz/copier-template-clasp my-project-folder --trust
...

the tool will ask you a few questions, and then create the project and git repo for you. You will probably have to sign into your Google Account to authorise clasp to push code.

Development cycle

The boilerplate will create both the local Typescript files and the remote Sheet / Doc / whatever you specified. Open your Drive in your browser and find the document there (the name will be your answer to the "Title of your app" question when you cloned the project)

Once you are set up it's a matter of making local changes, transpiling to JS, pushing to Google, refreshing your document in your browser. You can do the pushing manually, with

❯ npm run build-push
...

or you can let the watch script run, and it will push code for you

❯ npm run build-push
[18:02:33] File change detected. Starting incremental compilation...

[18:02:33] Found 0 errors. Watching for file changes.

Tests

I haven't managed to get tests to run yet. Clasps expects a single file without modules, and most Typescript test runners expect modules. Haven't yet found a way to make both work the same time. d

Licence

BSD Zero Clause License

About

A copier template for a clasp project, that allow you to code Google Apps Script locally with typescript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published