Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dstcruz/purescript-gas-template

A template to get started using Purescript with Google Apps Script
https://github.com/dstcruz/purescript-gas-template

google-apps-script purescript

Last synced: 25 days ago
JSON representation

A template to get started using Purescript with Google Apps Script

Awesome Lists containing this project

README

        

* Purescript-GAS-Template

A minimal template to get you jump-started using [[https://developers.google.com/apps-script][Google Apps Script]] with [[https://www.purescript.org][Purescript]].

See ~src/App/Sample.purs~ for the simplest of interactions. Once you build and
publish this code to your spreadsheet (see Publish below), you will be able to:

- In a cell, put the formula ~=HELLO("world")~ to see "Hello wold" returned by your purescript code.

- See a new menu called "FromPurescript", with 2 entries which make a toast appear with a message.

** Environment

If you have Nix, you can run the ~nix-shell~ with the dependencies already in place.

** Init

To init, follow standand npm/yarn procedure:

#+BEGIN_SRC shell
yarn install
#+END_SRC

** Build

See ~package.json~ for build, clean, publish scripts.

** Publish

This package uses [[https://developers.google.com/apps-script/guides/clasp][google's clasp]] to upload the script to google servers. You will
need to first login in order to be able to execute the ~clasp push~ command run by
the ~publish~ script. Login in is as simple as

#+BEGIN_SRC shell
npx clasp login
#+END_SRC

You will also need to create a Spreadsheet, open "Tools > Script Editor", name
the script, and capture the ~scriptId~ from the Script Editor's "View > Project properties"
menu. Insert that value into ~.clasp.json~.

** Building notes

As a first step, we build the purescript code with ~spago~. Once that is done,
we call ~webpack~ to bundle things up with our ~index.js~ file as the entry
point. Since google doesn't understand plain, modern, javascript, ~webpack~
transpiles (via ~babel~), and then uses the [[https://github.com/fossamagna/gas-webpack-plugin][gas-webpack-plugin]] to massage
the javascript into code that google's app engine likes. ~GAS~ expects that all declarations be top-level,
so this plugin detects expressions assigned to ~global~ and generates a top-level declaration for it.