동일한 스크립트를 Rhino에서 V8로 일괄 이전

이 페이지에서는 Apps Script 및 Apps Script API를 사용하여 동일한 스크립트를 V8으로 이전하는 방법을 설명합니다.

Rhino가 지원 중단되기 전에 Rhino 런타임을 사용하는 모든 스크립트를 이전해야 합니다(2026년 1월 31일 이후). Rhino에서 실행되는 동일한 스크립트가 여러 개 있는 경우 Apps Script API를 사용하여 모두 V8으로 이전할 수 있습니다.

환경 설정

  1. Apps Script 대시보드 설정에서 Apps Script API를 사용 설정합니다.
    1. Apps Script 대시보드 설정으로 이동합니다.
    2. API가 사용 중지되어 있으면 Google Apps Script API를 클릭한 다음 Google Apps Script API 전환 버튼을 사용 설정합니다.
  2. 표준 Google Cloud 프로젝트를 만들거나 기존 프로젝트를 재사용합니다.
  3. Cloud 프로젝트에서 OAuth 동의 화면을 구성합니다.
  4. Cloud 프로젝트에서 Apps Script API를 사용 설정합니다.

    Apps Script API 사용 설정

  5. Apps Script 프로젝트를 만들고 Apps Script 프로젝트를 Cloud 프로젝트에 할당합니다.

    1. Apps Script 대시보드에서 또는 script.new로 이동하여 독립형 Apps Script 프로젝트를 만듭니다.
    2. 프로젝트 설정 프로젝트 설정의 아이콘를 클릭합니다.
    3. Google Cloud Platform (GCP) 프로젝트 섹션에서 프로젝트 변경을 클릭합니다.
    4. Cloud 프로젝트의 프로젝트 번호를 입력합니다.
    5. 프로젝트 설정을 클릭합니다.

스크립트 이전

다음 코드 샘플은 Apps Script API를 사용하여 각 Apps Script 프로젝트의 파일을 V8 호환 파일 세트로 대체하여 동일한 스크립트를 Rhino에서 V8으로 이전하는 방법을 보여줍니다.

이전하려는 스크립트 프로젝트에 대한 편집자 액세스 권한이 있어야 합니다.

function updateRhinoScripts() {
  // An array of script IDs of script projects to migrate.
  // TODO(developer): Replace with your script IDs.
  const scriptIds = ['abcdef12345678', 'abcdef12345678'];
  // An array of file objects to replace the existing files in each script project.
  // Remember to include all files for the script, excluded files are deleted.
  // TODO(developer): Replace with your script files.
  const filesToUpdate = {
    "files": [
      {
        "name": "Code",
        "type": "SERVER_JS",
        "source": "// New updates\nfunction myFunction() {\n  console.log('Hello, world!');\n}"
      },
      {
        "name": "appsscript",
        "type": "JSON",
        "source": JSON.stringify({
          "timeZone": "America/New_York",
          "dependencies": {},
          "exceptionLogging": "STACKDRIVER",
          "runtimeVersion": "V8"
        })
      }
    ]
  };
  updateMultipleAppsScripts(scriptIds, filesToUpdate);
}

function updateMultipleAppsScripts(scriptIds, filesToUpdate) {
  // 'scriptIds' should be an array of script IDs
  // 'filesToUpdate' should be an array of objects, each with:
  // name: The filename (For example, "Code", "Utilities")
  // source: The source code for that file.
  scriptIds.forEach(function (scriptId) {
    // Makes the API request.
    const response = UrlFetchApp.fetch(
      `https://script.googleapis.com/v1/projects/${scriptId}/content`,
      {
        method: "PUT",
        headers: {
          Authorization: `Bearer ${ScriptApp.getOAuthToken()}`
        },
        contentType: "application/json",
        payload: JSON.stringify(filesToUpdate),
        muteHttpExceptions: true
      }
    );
    if (response.getResponseCode() !== 200) {
      console.log(`Error updating script ${scriptId}: ${response.getContentText()}`);
    } else {
      console.log(`Script ${scriptId} updated successfully!`);
    }
  });
}

Apps Script 프로젝트에서 Apps Script API를 사용하려면 매니페스트 파일에 다음 OAuth 범위를 추가해야 합니다.

  • "https://www.googleapis.com/auth/script.projects"
  • "https://www.googleapis.com/auth/script.external_request"

편집기에 매니페스트 파일을 노출하려면 Project Settings(프로젝트 설정) 프로젝트 설정의 아이콘를 클릭하고 Show 'appsscript.json' manifest file in editor(편집기에 'appsscript.json' 매니페스트 파일 표시) 체크박스를 선택합니다. 다음은 적절한 OAuth 범위가 있는 샘플 매니페스트 파일입니다.

{
  "timeZone": "America/Denver",
  "dependencies": {
  },
  "oauthScopes": [
  "https://www.googleapis.com/auth/script.projects",
  "https://www.googleapis.com/auth/script.external_request"
],
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}