diff --git a/README.md b/README.md index da9620b..fef788b 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,7 @@ $ storyblok sync --type --source --target * `filter`: sync stories based on the given filter. Required Options: Required options: `--keys`, `--operations`, `--values` * `keys`: Multiple keys should be separated by comma. Example: `--keys key1,key2`, `--keys key1` * `operations`: Operations to be used for filtering. Can be: `is`, `in`, `not_in`, `like`, `not_like`, `any_in_array`, `all_in_array`, `gt_date`, `lt_date`, `gt_int`, `lt_int`, `gt_float`, `lt_float`. Multiple operations should be separated by comma. +* `components-full-sync`: If used, the CLI will override the full component object when synching across spaces. #### Examples diff --git a/src/cli.ts b/src/cli.ts index 9173fe8..aebde66 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -304,6 +304,7 @@ program .option('--operations ', 'Operations to be used for filtering. Can be: is, in, not_in, like, not_like, any_in_array, all_in_array, gt_date, lt_date, gt_int, lt_int, gt_float, lt_float. Multiple operations should be separated by comma.') .option('--values ', 'Values to be used for filtering. Any string or number. If you want to use multiple values, separate them with a comma. Multiple values should be separated by comma.') .option("--components-groups ", "Synchronize components based on their group UUIDs separated by commas") + .option("--components-full-sync", "Synchronize components by overriding any property from source to target") .action(async (options) => { console.log(`${chalk.blue("-")} Sync data between spaces\n`); @@ -321,10 +322,12 @@ program keys, operations, values, - componentsGroups + componentsGroups, + componentsFullSync } = options; const _componentsGroups = componentsGroups ? componentsGroups.split(",") : null; + const _componentsFullSync = !!componentsFullSync; const filterQuery = filter ? buildFilterQuery(keys, operations, values) : undefined const token = creds.get().token || null; @@ -343,6 +346,7 @@ program startsWith, filterQuery, _componentsGroups, + _componentsFullSync, }); console.log("\n" + chalk.green("✓") + " Sync data between spaces successfully completed"); diff --git a/src/tasks/sync-commands/components.js b/src/tasks/sync-commands/components.js index 5c9beed..1708e44 100644 --- a/src/tasks/sync-commands/components.js +++ b/src/tasks/sync-commands/components.js @@ -20,6 +20,7 @@ class SyncComponents { this.client = api.getClient() this.presetsLib = new PresetsLib({ oauthToken: options.oauthToken, targetSpaceId: this.targetSpaceId }) this.componentsGroups = options.componentsGroups + this.componentsFullSync = options.componentsFullSync } async sync () { @@ -201,7 +202,10 @@ class SyncComponents { } mergeComponents (sourceComponent, targetComponent = {}) { - const data = { + const data = this.componentsFullSync ? { + // This should be the default behavior in a major future version + ...sourceComponent + } : { ...sourceComponent, ...targetComponent } diff --git a/src/tasks/sync.js b/src/tasks/sync.js index 95a39fb..147c453 100644 --- a/src/tasks/sync.js +++ b/src/tasks/sync.js @@ -16,6 +16,7 @@ const SyncSpaces = { this.targetSpaceId = options.target this.oauthToken = options.token this.componentsGroups = options._componentsGroups + this.componentsFullSync = options._componentsFullSync this.startsWith = options.startsWith this.filterQuery = options.filterQuery }, @@ -232,7 +233,8 @@ const SyncSpaces = { sourceSpaceId: this.sourceSpaceId, targetSpaceId: this.targetSpaceId, oauthToken: this.oauthToken, - componentsGroups: this.componentsGroups + componentsGroups: this.componentsGroups, + componentsFullSync: this.componentsFullSync }) try {