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

add option enables syncing of datasources without their corresponding dimension values #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -247,6 +247,7 @@ $ storyblok sync --type <COMMAND> --source <SPACE_ID> --target <SPACE_ID>
* `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

Expand Down
10 changes: 8 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ program
.requiredOption('--source <SPACE_ID>', 'Source space id')
.requiredOption('--target <SPACE_ID>', 'Target space id')
.option('--components-groups <UUIDs>', '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`)

Expand All @@ -284,7 +285,8 @@ program
type,
target,
source,
componentsGroups
componentsGroups,
datasourceDisableDimensionsValueSync,
} = options

const _componentsGroups = componentsGroups ? componentsGroups.split(',') : null
Expand All @@ -298,12 +300,16 @@ program
}
})

const filterQuery = filter ? buildFilterQuery(keys, operations, values) : undefined
const token = creds.get().token || null
CaprinaeWT marked this conversation as resolved.
Show resolved Hide resolved

await tasks.sync(_types, {
api,
token,
target,
source,
_componentsGroups
_componentsGroups,
datasourceDisableDimensionsValueSync
})

console.log('\n' + chalk.green('✓') + ' Sync data between spaces successfully completed')
Expand Down
20 changes: 13 additions & 7 deletions src/tasks/sync-commands/datasources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -13,6 +13,7 @@ class SyncDatasources {
this.targetSpaceId = options.targetSpaceId
this.oauthToken = options.oauthToken
this.client = api.getClient()
this.datasourceDisableDimensionsValueSync = options.datasourceDisableDimensionsValueSync
}

async sync () {
Expand Down Expand Up @@ -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}`)
Expand Down Expand Up @@ -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)
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.oauthToken = options.token
this.client = api.getClient()
this.componentsGroups = options._componentsGroups
this.datasourceDisableDimensionsValueSync = options.datasourceDisableDimensionsValueSync
},

async getStoryWithTranslatedSlugs (sourceStory, targetStory) {
Expand Down Expand Up @@ -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 {
Expand Down