Skip to content

Commit

Permalink
Merge pull request #93 from storyblok/feature/SHAPE-2922
Browse files Browse the repository at this point in the history
Feature/shape 2922
  • Loading branch information
Christian Zoppi authored May 17, 2024
2 parents 71d5c4a + 5dc5938 commit 8a3c914
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ $ storyblok sync --type <COMMAND> --source <SPACE_ID> --target <SPACE_ID>
* `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

Expand Down
6 changes: 5 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ program
.option('--operations <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>', '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 <UUIDs>", "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`);

Expand All @@ -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;

Expand All @@ -343,6 +346,7 @@ program
startsWith,
filterQuery,
_componentsGroups,
_componentsFullSync,
});

console.log("\n" + chalk.green("✓") + " Sync data between spaces successfully completed");
Expand Down
6 changes: 5 additions & 1 deletion src/tasks/sync-commands/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion src/tasks/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8a3c914

Please sign in to comment.