Issue with scopes when switching Google Apps Script projects to V8 runtime

638 Views Asked by At

Due to Google Apps Script forcefully pushing "Rhino" to "V8" engine, Applications are moving from Rhino to V8 automatically. So our applications are asking "scopes" that need to be specified manually in "appscript.json" file.

Please check the below image:

Application Issue

File :-

Code.gs

When I update like below, it works fine.

appsscript.json

Our concern is that we have more than 100 applications in production, we cannot update this manually everytime. Can you please help us how to update without any issue in production?

1

There are 1 best solutions below

0
Oleg Valter is with Ukraine On

Using clasp

You can update the manifest files in batch by using the CLASP project (it uses Apps Script API under the hood) and a utility script in Node.js or your poison of choice to control the workflow. General steps you need to take are:

  1. Clone a project with clasp clone "YourScriptIdHere"

  1. Update the appsscript.json file with the required scopes. Since manifest is saved at the root of the project, I would do something like this (with Node.js):
const { writeFile } = require("fs").promises;

const addScope = async (scopes) => {

  const pathToManifest = "appscript.json";

  const manifest = require(pathToManifest);

  const { oauthScopes = [] } = manifest;

  oauthScopes || ( manifest.oauthScopes = oauthScopes ); //guard against first scope

  oauthScopes.push(...scopes);

  await writeFile(pathToManifest, JSON.stringify(manifest));
}


  1. Push the updates to the project with clasp push. Since you are changing the manifest, use the --force option or you will have to approve each upload. Note that as of 2020, the project does not yet support partial updates, so all files will be replaced. Use .claspignore file to ensure you do not accidentally push the whole node_modules folder or similar.

  1. Redeploy the projects with clasp deploy. The command is customizable, so do not worry about having multiple deployments.