Example usage of ClojureScript in Google Apps Script.
- Clone this repo.
- Write your cljs code like normal in
src/*
. - For functions you want to expose to the outside world,
^:export
their symbols (see src/cljs_apps_script/core.cljs for examples). - To run/test your code locally, build with
source scripts/build
(run from the project root) and openindex.html
in your browser. To auto-rebuild on changes tosrc/*
, dosource scripts/watch
. - To use your code in Google Apps Script, first build it with
source scripts/release
, then copy-and-paste the compiled JavaScript fromrelease/cljs_apps_script_<current-project-version>.js
into your Google Apps script.
I've tweaked the scripts/release.clj
to do the following:
- Add the current project version (from project.clj) as a comment at the top the compiled JS – that way you can keep track of what version is in Google Apps Script.
- Add the release version to the filename of the compiled JS, like so:
release/cljs_apps_script_<current-project-version>.js
If you don't update your project version between builds it will overwrite the previous build since the version is in the build filename. Also, since the release version number is baked into filename, you'll need to change the version number in index_release.html to test the most recent version.
Exported functions can be found at <namespace>.<namespace-qualifier>.<function-name>
, e.g. cljs_apps_script.core.say_hello()
. The -
(dashes) in any function names are replaced with _
(underscores).
If you wanted to, say, use an ^:export
ed function as a custom function in Google Apps Script, include something like:
/** @customfunction */
function sayHello(x) {
return cljs_apps_script.core.say_hello(x);
}
at the bottom of your code in Google Apps Script.
- Automate export of compiled JS into Google Apps Script directly (ref.: https://developers.google.com/apps-script/import-export).
This Leiningen project was initially created with the Mies template and so I got all the scripts from there and tweaked them to my use.
MIT (see LICENSE)