r/GoogleAppsScript • u/bas-man-tko • Mar 22 '24
Question Local development with Clasp (MacOS) with existing code base
Hi.
Let me start by saying I am not a skilled or overly experienced Javascript developer.
A few years ago I wrote some Google script code to parse emails, and populate a spreadsheet, as well as add events to my calendar. This all works well. I developed it in the Google Script web interface.
I also set up Clasp so that I could down the code and commit it to Git Hub for safekeeping.
Recently I have wanted to update the code and would like to add tests using Jest.
I found this link starter repo. But it's a bit dated. And I am having trouble working into my existing code base.
Can anyone point me in the direction of a more up-to-date setup?
Much appreciated.
1
u/HellDuke Mar 23 '24
That repository seems a bit odd as it doesn't really even provide anything. All you need is clasp to push, pull and even run the code (though you need to deploy a version of the script before you can run it via clasp). The date things show up in things like instructions how to enable V8 as it's enabled on all Google Scripts by default unless you specifically opted to keep a script on an older version. Same with the .claspignore there is no reason to get any sort of file, you get one when you clone a project with clasp anyway, you can just add files you want to avoid pushing for whatever reason.
1
u/bas-man-tko Mar 23 '24
It seems geared towards working with vscode. Providing code completion for Google script commands. As well as testing using jest. Though not for Google script functions.
I have developed my own script to remove imports and export statements that I need to do testing locally. Unless there is an easier option? I will publish the script once I have cleaned it up.
Now I am looking for a more current minimal node package.json template to start such projects. If anyone would be willing to share their initial template, I would appreciate it.
1
u/HellDuke Mar 23 '24
You can't really test a Google Apps Script localy, the script still runs on Google servers and affects your actual accounts, the only thing you can do is execute the remote script from a local machine via command line as opposed to using the web IDE
1
u/bas-man-tko Mar 29 '24
Yes, You can NOT test Google supplied functions. This is well understood. But you can test your helper functions that help you massage your data.
1
u/HellDuke Mar 29 '24
At the end of the day Google Apps script is just javascript so yeah, I suppose if your functions do not use any of the google services those can be tested locally as any javascript application
1
u/bas-man-tko Mar 29 '24
Here is my code for allowing me to do local development and testing using VSCode.
Things to note:
Original code resides in
srcOriginal codes contains import and export statements as well as eslint-disable statements.
clasp uses
distas the directory for pushing to Google Scripts.pulling code should no longer be done.
Pushing code from the root of the project:
./bin/build.sh (script listed below)
clasp push