首页 > 解决方案 > 将 Google Apps 脚本项目切换到 V8 运行时时的范围问题

问题描述

由于 Google Apps Script 强行将“Rhino”推送到“V8”引擎,应用程序正在自动从 Rhino 迁移到 V8。所以我们的应用程序正在询问需要在“ appscript.json ”文件中手动指定的“范围”。

请检查下图:

应用问题

文件 :-

代码.gs

当我像下面这样更新时,它工作正常。

应用脚本.json

我们担心的是我们有超过 100 个生产应用程序,我们不能每次都手动更新。你能帮助我们如何在生产中没有任何问题的更新吗?

标签: google-apps-scriptv8google-apps-script-apigoogle-apps-script-runtimegoogle-apps-script-project

解决方案


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.

推荐阅读