From 859f315a2de92a54326c7f50c548fe5ed67cfb87 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Thu, 18 Jan 2024 19:09:42 +0530 Subject: [PATCH] fix: command not working on window os & script not generated for all CT --- .../src/branch/merge-handler.ts | 48 ++++++++----------- .../src/utils/create-merge-scripts.ts | 18 +++---- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/packages/contentstack-branches/src/branch/merge-handler.ts b/packages/contentstack-branches/src/branch/merge-handler.ts index aa91ede899..f68f36bb6c 100644 --- a/packages/contentstack-branches/src/branch/merge-handler.ts +++ b/packages/contentstack-branches/src/branch/merge-handler.ts @@ -241,7 +241,6 @@ export default class MergeHandler { async executeEntryExpFlow(mergeJobUID: string, mergePayload) { const { mergeContent } = this.mergeSettings; let mergePreference = await selectContentMergePreference(); - let selectedMergePreference; const updateEntryMergeStrategy = (items, mergeStrategy) => { items && @@ -250,25 +249,16 @@ export default class MergeHandler { }); }; - switch (mergePreference) { - case 'existing_new': - selectedMergePreference = 'merge_existing_new'; - updateEntryMergeStrategy(mergeContent.content_types.added, selectedMergePreference); - updateEntryMergeStrategy(mergeContent.content_types.modified, selectedMergePreference); - break; - - case 'new': - selectedMergePreference = 'merge_new'; - updateEntryMergeStrategy(mergeContent.content_types.added, selectedMergePreference); - break; - - case 'existing': - selectedMergePreference = 'merge_existing'; - updateEntryMergeStrategy(mergeContent.content_types.modified, selectedMergePreference); - break; + const mergePreferencesMap = { + 'existing_new': 'merge_existing_new', + 'new': 'merge_new', + 'existing': 'merge_existing', + 'ask_preference': 'custom', + }; + const selectedMergePreference = mergePreferencesMap[mergePreference]; - case 'ask_preference': - selectedMergePreference = 'custom'; + if (selectedMergePreference) { + if (selectedMergePreference === 'custom') { const selectedMergeItems = await selectContentMergeCustomPreferences(mergeContent.content_types); mergeContent.content_types = { added: [], @@ -279,23 +269,25 @@ export default class MergeHandler { selectedMergeItems?.forEach((item) => { mergeContent.content_types[item.status].push(item.value); }); - break; - - default: - cliux.error(`error: Invalid preference ${mergePreference}`); - process.exit(1); + } else { + updateEntryMergeStrategy(mergeContent.content_types.added, selectedMergePreference); + updateEntryMergeStrategy(mergeContent.content_types.modified, selectedMergePreference); + } + } else { + cliux.error(`error: Invalid preference ${mergePreference}`); + process.exit(1); } let scriptFolderPath = generateMergeScripts(mergeContent.content_types, mergeJobUID); if (scriptFolderPath !== undefined) { cliux.success(`\nSuccess! We have generated entry migration files in the folder ${scriptFolderPath}`); - cliux.print('\nWARNING!!! Migration is not intended to be run more than once. Migrated(entries/assets) will be duplicated if run more than once', {color: 'yellow'}); + cliux.print('\nWARNING!!! Migration is not intended to be run more than once. Migrated(entries/assets) will be duplicated if run more than once', { color: 'yellow' }); let migrationCommand: string; - if(os.platform() === 'win32'){ - migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`; - }else{ + if (os.platform() === 'win32') { + migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch} file-path:./${scriptFolderPath} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`; + } else { migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config {compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath}} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`; } diff --git a/packages/contentstack-branches/src/utils/create-merge-scripts.ts b/packages/contentstack-branches/src/utils/create-merge-scripts.ts index 95c2cf1bbc..42882734ec 100644 --- a/packages/contentstack-branches/src/utils/create-merge-scripts.ts +++ b/packages/contentstack-branches/src/utils/create-merge-scripts.ts @@ -34,21 +34,22 @@ export function generateMergeScripts(mergeSummary, mergeJobUID) { const processContentTypes = (contentTypes, messageType) => { if (contentTypes && contentTypes.length > 0) { - processContentType( - { type: 'assets', uid: '', entry_merge_strategy: '' }, - mergeStrategies['asset_create_folder'], - ); contentTypes.forEach((contentType) => { const mergeStrategy = contentType.entry_merge_strategy; if (mergeStrategies.hasOwnProperty(mergeStrategy)) { processContentType(contentType, mergeStrategies[mergeStrategy]); } }); + cliux.print(`Info: ${messageType} content types' entries selected for merge`, { color: 'blue' }); } else { - cliux.print(`No ${messageType} entries selected for merge`, { color: 'yellow' }); + cliux.print(`Info: No ${messageType} content types' entries selected for merge`, { color: 'blue' }); } }; - + + processContentType( + { type: 'assets', uid: '', entry_merge_strategy: '' }, + mergeStrategies['asset_create_folder'], + ); processContentTypes(mergeSummary.modified, 'Modified'); processContentTypes(mergeSummary.added, 'New'); @@ -93,10 +94,11 @@ export function createMergeScripts(contentType: CreateMergeScriptsProps, mergeJo fs.mkdirSync(fullPath); } let filePath: string; + let milliSeconds = date.getMilliseconds().toString().padStart(3, '0') if (contentType.type === 'assets') { - filePath = `${fullPath}/${fileCreatedAt}_create_assets_folder.js`; + filePath = `${fullPath}/${fileCreatedAt}${milliSeconds}_create_assets_folder.js`; } else { - filePath = `${fullPath}/${fileCreatedAt}_${getContentTypeMergeStatus(contentType.entry_merge_strategy)}_${ + filePath = `${fullPath}/${fileCreatedAt}${milliSeconds}_${getContentTypeMergeStatus(contentType.entry_merge_strategy)}_${ contentType.uid }.js`; }