Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/shape 2922 #93

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading