Google Apps Script for Developers

Google Apps Script makes it’s straightforward so that you can combine information and performance from Gmail, Google Drive, Google Maps, YouTube, and most different Google APIs. Apps Script is JavaScript underneath the hood so that you don’t need to be taught a brand new language and also you don’t need to handle any servers since all of your code runs on the Google Cloud, not your browser.

On this video tutorial, you’ll discover ways to develop Google Apps Script initiatives regionally in your pc inside Visible Studio Code. You’ll be able to write your code in trendy JavaScript, neatly organized in modules, and the construct setting will use Babel and Webpack to remodel your code right into a model of JavaScript that’s suitable with Apps Script.

Trendy Growth with Google Apps Script

There are fairly a couple of benefits with having a neighborhood growth setting vis-a-vis writing code within the Apps Script Cloud IDE.

  1. You’ll be able to write code with ES6 Courses, Arrow Capabilities, Modules, Destructing and use all the opposite trendy JavaScript options.
  2. The event expertise inside VS Code is unmatched and instruments like ESLint and Prettier make it simpler so that you can catch errors early within the growth.
  3. The construct and deployment course of could be fully automated with npm scripts and CLASP, Google’s command line utility for Apps Script.
  4. VS Code has built-in help for Git and integrates with supply management suppliers like Github and Gitlab. It’s subsequently simpler to trace modifications and restore earlier variations of the code.
  5. You’ll be able to rapidly combine JavaScript libraries like LoDash, Second, Underscore and any of the NPM packages into your code.
  6. You need to use trendy frameworks like React, Vue.js and Angular to construct the HTML frontend that connects to the backend with the Google Script Consumer API.

Getting Began with the Apps Script Starter

The Starter equipment is a boilerplate for rapidly getting began with native Apps Script growth regionally inside VS Code. Open your terminal and run the next instructions:

1. Clone the Github repository to a neighborhood folder

git clone https://github.com/labnol/apps-script-start my-project

2. Change to the challenge folder

cd my-project

three. Set up all of the challenge dependencies and utilities

npm set up

four. Join CLASP to your Google account

npx clasp login

5. Create a brand new Google Apps Script challenge in your Google Drive with CLASP

npx clasp create "My Undertaking" --rootDir ./dist

This command will create a brand new .clasp.json file in your challenge folder that hyperlinks the native folder along with your Apps Script challenge. Throughout construct, Webpack will bundle all of your code in a single JavaScript file and add it to the ./dist folder that Clasp will push to your Apps Script challenge.

Subsequent, open the present challenge folder inside VS Code with the code . command. It contains some pattern code however we’ll begin with a clean folder so delete every thing that’s contained in the src folder.

Contained in the src folder, create a brand new file – e mail.js – and write a easy arrow operate that prints an inventory of all the e-mail addresses linked to your Gmail account.

apps-script-starter (1).png

Subsequent, create an index.js file (entry level) within the src folder, import the e-mail operate that you just’ve created contained in the e mail.js file and add it to the worldwide object. It is a requirement of the Webpack plugin for Google Apps Script.

You can too add a operate expression to the worldwide object immediately, like doGet within the instance beneath.

htmlservice-doget.png

Now that your JavaScript code is prepared, open the appsscript.json file in your challenge folder and modify the oAuthScopes property to solely embody the scopes which might be required by your challenge.

Subsequent, bounce to the command line terminal and run the deploy command to push your code to the Apps Script challenge.

npm run deploy

After the deployment is full, open the related script within the browser with the CLASP open command.

npx clasp open

Contained in the Apps Script Editor, go to the Run menu and select the getEmailAddress operate from the listing. Open the logs and you must see your e mail addresses within the window.

Then go to the Publish menu, select Deploy as internet app and open the URL in a brand new browser tab to examine this system output. That’s how straightforward it’s to construct initiatives with the Google Apps Script starter equipment.

Utilizing Git with Google Apps Script

Create a brand new repository in Github and make a remark of the URL of the brand new repository. Subsequent, open the terminal and run the next instructions to push your Apps Script challenge to Github.

github-apps-script.png

Additionally see: Most Helpful Google Apps Scripts

The identical strategy is utilized by Digital Inspiration for constructing in style Google add-ons together with Gmail Mail Merge, Google Types Notifications and Doc Studio.