メインコンテンツにスキップ

Google-Apps-Script-ScriptSync

This is a Google Apps Script library helps maintain the relevance of a script on the user's end.

AI Summary

ScriptSync

A Google Apps Script library that synchronises user scripts with a template and updates code remotely without developer intervention.

Target Users

Intermediate-to-advanced GAS developers who distribute scripts to many users and need continuous maintenance.

Problems Solved

Once an Apps Script is distributed, updating it requires each user to manually replace the code, creating significant maintenance overhead.

Tags

Main Features

1
Automatic user-side script update

By combining assignTemplate and commit, template changes are copied to the user script and deployed without any user action.

2
Rich file operation methods

APIs such as AddNewFile, renameFile and deleteFile allow programmatic addition, renaming and removal of script files, enabling code-based diff management.

3
Visualise and commit template changes

viewChanges shows pending modifications before commit, while commit/drop lets you apply or discard them, enabling safe upgrades.

Usage Examples

Copy template files to the user script

/**
 * Minimal example that copies every file from a template
 * into the end-user script and commits the changes.
 */
function updateFromTemplate() {
  const TEMPLATE_ID = 'your_template_script_id'; // shared template ID

  // Initialise updater
  const updater = ScriptSync.assignTemplate(TEMPLATE_ID);

  // Fetch file list from the template
  const files = ScriptSync.getScriptFiles(TEMPLATE_ID);

  // Queue each file for update
  files.forEach(f => updater.AddNewFile(f.file));

  // Preview changes (trimmed to 30 chars)
  updater.viewChanges(30);

  // Apply changes to the user script
  updater.commit();
}

The snippet initialises ScriptSync with a template ID, enqueues every template file via AddNewFile and commits, bringing the user script up to date without manual intervention.