AppsScriptPulse

Building the Ultimate Google Apps Script Front Ends. Part 2: Bundling NPM Modules

Hey there, friends! šŸ‘‹ Our Emojibar ā€” yes, thatā€™s what weā€™re calling it now ā€” is coming along nicely! In the previous post, we learned how to bundle the project with Vite and vite-plugin-singlefile, and itā€™s now time to add some real functionality!

To complete our Emojibar, weā€™ll use two NPM modules:

  • Unicode-Emoji-JSON:Ā We need a complete list of emojis, and this simple module provides them in JSON format. Perfect!
  • ToastifyJS:Ā When users click on an emoji, itā€™ll be copied into their buffer. Just so they have some feedback, weā€™ll show them a confirmation toast. This library is great for this purpose.

Weā€™ll also add search and navigation functionality, meaning that weā€™ll have the entire backbone of the application ready by the end of this post.

Source: Building the Ultimate Google Apps Script Front Ends. Part 2: Bundling NPM Modules

Building the Ultimate Google Apps Script Front Ends, Part 1: Bundling with Vite šŸš€

 

Last week, we talked about the best way to build front-ends for Google Apps Script. Today, letā€™s roll up our sleeves and dive in! šŸ˜Ž

Source: Building the Ultimate Google Apps Script Front Ends, Part 1: Bundling with Vite šŸš€

The Ultimate Google Apps Script Front-End Development Guide. Part 0: The Worst and the Best Practices

Welcome to the Ultimate Google Ultimate Google Apps Script Front-End Development Guide!

If you are reading this post, then you likely have experience with Google Apps Script. Essentially, there are three types of front-ends that you can create with Apps Script:

  • Web apps
  • Modal/modeless dialogues
  • Sidebars

In this blog post series, we will only discuss HTML front-ends, as this is where you can create the most powerful and sophisticated user experiences. Unfortunately, the Card Service is outside the scope of this series, and it is not nearly as powerful as an HTML front-end. With that in mind, Google, how about allowing HTML front-ends for Workspace add-ons?

Source: The Ultimate Google Apps Script Front-End Development Guide. Part 0: The Worst and the Best Practices

Using design patterns in Google Apps Script

Google Apps Script is a JavaScript-based language that has access to Google Workspace-specific libraries for Gmail, Google Sheets, Google Forms, Google Drive, etc., and allows you to quickly and efficiently automate your tasks and program business applications.

A lot of users try and quickly learn GAS and use it to make their lives easier. Itā€™s all great, however the code we sometimes tend to come across on StackOverflow and other sites lacks best practices, hence I thought it was time to start bringing them up and I will start today with design patterns.

I’m all for copy/paste coding and it one of the things I love about the Google Apps Script developer community, there are lots of great snippets out there and in Pulse we’ve now over 800 posts and counting. When you start going beyond quick script solutions into more complex projects investing time planning how you’ll structure your code can save you headaches and frustrations further down the line.

Using design patterns are one way to produce better code that is more readable which in turn is more maintainable and can lead to faster development. This post from Dmitry Kostyuk a nice opportunity to learn about a design pattern for a very common use case of maintaining data in a Google Sheet from a third party API.

Source: Using Design Patterns in Google Apps Script

Using ChatGPT to Generate Fake Data in Your Spreadsheet with Google Apps Script

ChatGPT is pretty much a universal API: one endpoint to get any data.

Fake data is useful for testing purposes. At times, real data is too sensitive, and sometimes you do not have access to real data before production, but you need to begin working with something. Here is where fake data comes in.

We used to have a great library for fake data calledĀ Faker.js; however, Marak, the author, became so frustrated that he could not monetize the solution that heĀ pushed an update that broke everything, which led to him being blocked on GitHub and NPM. As a result, the library is no longer maintained. ChatGPT, however, is not going anywhere.

Source: Using ChatGPT to Generate Fake Data in Your Spreadsheet with Google Apps Script

Three pitfalls to avoid when using the onEdit trigger in Google Apps Script

Illustration by ahmiruddinhidayat111198 on freepik.com https://www.freepik.com/author/fahmiruddinhidayat111198

  1. Making a Single Function Do Everything
  2. Expecting onEdit to Catch All Changes by Default

Source: Three Pitfalls to Avoid When Using the onEdit Trigger in Google Apps Script

If you use clasp with Google Apps Script, you need this environment switching utility right now!

When working in a team and/or with a client, you want to have multiple environments. At minimum, you probably want a dev environment (or multiple ones) in which you are working, and a test environment in which the client or your team can run acceptance tests before production. Of course, they must both be separate from the production environment. To push your code to the correct environment, you need to either update theĀ .clasp.jsonĀ file manually or keep multiple copies of your script with differentĀ .clasp.json files. Fortunately, things have just become significantly easier, as I recently built an app for this purpose calledĀ clasp-env,Ā which is available onĀ NPM. See the source link for details.

Source: “If You Use Clasp With Google Apps Script, You Need This Utility Right Now”

How to Build an API Wrapper in Google Apps Script

No Google Apps Script SDK for your favorite API? No problem!

Iā€™ve never seen a Google Apps Script SDK made available as part of an API, as, surprise surprise, itā€™s not the most popular choice for professional development. Itā€™s time to start changing that, so we will learn to build our own!

[Editor note: Really impressive work from Dmitry providing a framework you can use to develop your own service for interacting with 3rd party APIs. The post includes lots of clear instructions and guidance to help you understand and learn about approaches for structuring your Google Apps Script code projects]

Source: How to Build an API Wrapper in Google Apps Script

How to Write Google Apps Script Code Locally in VS Code and Deploy It With clasp

Google Apps Script Power Up

Why Write GAS Code Locally?

When it came out, the new Google Apps Script IDE was, of course, a big deal. Itā€™s way better than the legacy one. It brought syntax highlighting, keyboard shortcuts, command palette and just a much better UI experience.

In fact the reason itā€™s so good is that itā€™s built on top of VS CodeĀ Monaco editor. But itā€™s definitely still far away from what a real VS Code installation can do. You can get all the functionality of the online IDE and much more more: autocomplete, custom themes, installation of modules, linting, snippets, etc.

The bare minimum that you would need is :

  • AĀ VS CodeĀ installation (duh!)
  • Node.jsĀ + NPM : a JavaScript runtime with a built-in module installer;
  • Autocomplete;
  • clasp: a CLI utility to sync your GAS code

Letā€™s get into it!

Source: How to Write Google Apps Script Code Locally in VS Code and Deploy It With clasp

How to Use Service Accounts and OAuth2 in Google Apps Script

Image: Dmitry Kostyuk

Give your scripts privileges that your users donā€™t have … In 99% of all cases, authorizations in Google Apps Script are extremely straightforward. When a user executes their script, they run it as themselves with their respective authorization scopes. … However, what if you need to give more rights to your app beyond what your intended users will have? … This is where service accounts come in.

A useful post to find out more about service accounts and how to use them with Google Apps Script. The tutorial put together by Dmitry Kostyuk includes example code for using a service accounts with Firestore, BigQuery and the Admin Directory API.

Source: How to Use Service Accounts and OAuth2 in Google Apps Script