diff --git a/README.md b/README.md index d75fe82..697c19d 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,7 @@ $ storyblok sync --type --source --target * `type`: describe the command type to execute. Can be: `folders`, `components`, `stories`, `datasources` or `roles`. It's possible pass multiple types separated by comma (`,`). * `source`: the source space to use to sync * `target`: the target space to use to sync +*`datasource-disable-dimensions-value-sync`: Enables syncing of datasources without their corresponding dimension values. #### Examples diff --git a/src/cli.js b/src/cli.js index 00160b1..dab40b8 100755 --- a/src/cli.js +++ b/src/cli.js @@ -272,6 +272,7 @@ program .requiredOption('--source ', 'Source space id') .requiredOption('--target ', 'Target space id') .option('--components-groups ', 'Synchronize components based on their group UUIDs separated by commas') + .option('--datasource-disable-dimensions-value-sync', 'Enables syncing of datasources without their corresponding dimension values.') .action(async (options) => { console.log(`${chalk.blue('-')} Sync data between spaces\n`) @@ -284,7 +285,8 @@ program type, target, source, - componentsGroups + componentsGroups, + datasourceDisableDimensionsValueSync, } = options const _componentsGroups = componentsGroups ? componentsGroups.split(',') : null @@ -297,13 +299,14 @@ program throw new Error(`The type ${_type} is not valid`) } }) - + await tasks.sync(_types, { api, token, target, source, - _componentsGroups + _componentsGroups, + datasourceDisableDimensionsValueSync }) console.log('\n' + chalk.green('✓') + ' Sync data between spaces successfully completed') diff --git a/src/tasks/sync-commands/datasources.js b/src/tasks/sync-commands/datasources.js index e6d1e65..9427a2c 100644 --- a/src/tasks/sync-commands/datasources.js +++ b/src/tasks/sync-commands/datasources.js @@ -4,7 +4,7 @@ const api = require('../../utils/api') class SyncDatasources { /** - * @param {{ sourceSpaceId: string, targetSpaceId: string, oauthToken: string }} options + * @param {{ sourceSpaceId: string, targetSpaceId: string, oauthToken: string, datasourceDisableDimensionsValueSync: boolean }} options */ constructor (options) { this.targetDatasources = [] @@ -13,6 +13,7 @@ class SyncDatasources { this.targetSpaceId = options.targetSpaceId this.oauthToken = options.oauthToken this.client = api.getClient() + this.datasourceDisableDimensionsValueSync = options.datasourceDisableDimensionsValueSync } async sync () { @@ -139,11 +140,14 @@ class SyncDatasources { ) const { data } = await this.createDatasourcesDimensions(datasourcesToAdd[i].dimensions, newDatasource.data.datasource) await this.syncDatasourceEntries(datasourcesToAdd[i].id, newDatasource.data.datasource.id) - console.log( - ` ${chalk.blue('-')} Sync dimensions values...` - ) - await this.syncDatasourceDimensionsValues(datasourcesToAdd[i], data.datasource) - console.log(` ${chalk.green('✓')} Created datasource ${datasourcesToAdd[i].name}`) + if (!this.datasourceDisableDimensionsValueSync) { + console.log( + ` ${chalk.blue('-')} Sync dimensions values...` + ) + await this.syncDatasourceDimensionsValues(datasourcesToAdd[i], data.datasource) + + console.log(` ${chalk.green('✓')} Created datasource ${datasourcesToAdd[i].name}`) + } } else { await this.syncDatasourceEntries(datasourcesToAdd[i].id, newDatasource.data.datasource.id) console.log(` ${chalk.green('✓')} Created datasource ${datasourcesToAdd[i].name}`) @@ -191,7 +195,9 @@ class SyncDatasources { await this.syncDatasourceEntries(sourceDatasource.id, datasourcesToUpdate[i].id) - await this.syncDatasourceDimensionsValues(sourceDatasource, datasourceToSyncDimensionsValues) + if (!this.datasourceDisableDimensionsValueSync) { + await this.syncDatasourceDimensionsValues(sourceDatasource, datasourceToSyncDimensionsValues) + } console.log(`${chalk.green('✓')} Updated datasource ${datasourcesToUpdate[i].name}`) } else { await this.syncDatasourceEntries(sourceDatasource.id, datasourcesToUpdate[i].id) diff --git a/src/tasks/sync.js b/src/tasks/sync.js index d0b5f33..3f95f3b 100644 --- a/src/tasks/sync.js +++ b/src/tasks/sync.js @@ -16,6 +16,7 @@ const SyncSpaces = { this.oauthToken = options.token this.client = api.getClient() this.componentsGroups = options._componentsGroups + this.datasourceDisableDimensionsValueSync = options.datasourceDisableDimensionsValueSync }, async getStoryWithTranslatedSlugs (sourceStory, targetStory) { @@ -247,7 +248,8 @@ const SyncSpaces = { const syncDatasourcesInstance = new SyncDatasources({ sourceSpaceId: this.sourceSpaceId, targetSpaceId: this.targetSpaceId, - oauthToken: this.oauthToken + oauthToken: this.oauthToken, + datasourceDisableDimensionsValueSync: this.datasourceDisableDimensionsValueSync }) try {