11import { Command } from '@contentstack/cli-command' ;
22import { cliux , flags , isAuthenticated , managementSDKClient } from '@contentstack/cli-utilities' ;
3- import { getMergeStatusWithContentTypes , handleErrorMsg , selectContentMergePreference , selectContentMergeCustomPreferences , generateMergeScripts } from '../../../utils' ;
3+ import {
4+ getMergeStatusWithContentTypes ,
5+ handleErrorMsg ,
6+ selectContentMergePreference ,
7+ selectContentMergeCustomPreferences ,
8+ generateMergeScripts ,
9+ } from '../../../utils' ;
410import os from 'os' ;
511
612/**
713 * Command to generate entry migration scripts for a completed merge job.
814 * Validates that merge is complete before allowing script generation.
915 */
1016export default class BranchGenerateScriptsCommand extends Command {
17+ static readonly aliases : string [ ] = [ ] ;
1118 static readonly description : string = 'Generate entry migration scripts for a completed merge job' ;
1219
1320 static readonly examples : string [ ] = [
1421 'csdx cm:branches:generate-scripts -k bltxxxxxxxx --merge-uid merge_abc123' ,
1522 'csdx cm:branches:generate-scripts --stack-api-key bltxxxxxxxx --merge-uid merge_abc123' ,
1623 ] ;
1724
18- static readonly usage : string = 'cm:branches:generate-scripts -k <value> --merge-uid <value>' ;
19-
2025 static readonly flags = {
26+ 'merge-uid' : flags . string ( {
27+ description : 'Merge job UID to generate scripts for.' ,
28+ required : true ,
29+ } ) ,
2130 'stack-api-key' : flags . string ( {
2231 char : 'k' ,
2332 description : 'Provide your stack API key.' ,
2433 required : true ,
2534 } ) ,
26- 'merge-uid' : flags . string ( {
27- description : 'Merge job UID to generate scripts for.' ,
28- required : true ,
29- } ) ,
3035 } ;
3136
32- static readonly aliases : string [ ] = [ ] ;
37+ static readonly usage : string = 'cm:branches:generate-scripts -k <value> --merge-uid <value>' ;
3338
3439 /**
3540 * Generates entry migration scripts for a completed merge job.
@@ -47,9 +52,11 @@ export default class BranchGenerateScriptsCommand extends Command {
4752 handleErrorMsg ( err ) ;
4853 }
4954
50- const { 'stack-api-key ' : stackAPIKey , 'merge-uid ' : mergeUID } = generateScriptsFlags ;
55+ const { 'merge-uid ' : mergeUID , 'stack-api-key ' : stackAPIKey } = generateScriptsFlags ;
5156
52- const stackAPIClient = await ( await managementSDKClient ( { host : this . cmaHost } ) ) . stack ( {
57+ const stackAPIClient = await (
58+ await managementSDKClient ( { host : this . cmaHost } )
59+ ) . stack ( {
5360 api_key : stackAPIKey ,
5461 } ) ;
5562
@@ -70,10 +77,10 @@ export default class BranchGenerateScriptsCommand extends Command {
7077 const { uid } = mergeStatusResponse ;
7178
7279 // Ask user for merge preference
73- let mergePreference = await selectContentMergePreference ( ) ;
80+ const mergePreference = await selectContentMergePreference ( ) ;
7481
7582 // Get content types data
76- const contentTypes = mergeStatusResponse . content_types ?? { added : [ ] , modified : [ ] , deleted : [ ] } ;
83+ const contentTypes = mergeStatusResponse . content_types ?? { added : [ ] , deleted : [ ] , modified : [ ] } ;
7784
7885 const updateEntryMergeStrategy = ( items , mergeStrategy ) => {
7986 items &&
@@ -83,10 +90,10 @@ export default class BranchGenerateScriptsCommand extends Command {
8390 } ;
8491
8592 const mergePreferencesMap = {
93+ ask_preference : 'custom' ,
94+ existing : 'merge_existing' ,
8695 existing_new : 'merge_existing_new' ,
8796 new : 'merge_new' ,
88- existing : 'merge_existing' ,
89- ask_preference : 'custom' ,
9097 } ;
9198 const selectedMergePreference = mergePreferencesMap [ mergePreference ] ;
9299
@@ -120,13 +127,13 @@ export default class BranchGenerateScriptsCommand extends Command {
120127 ) ;
121128
122129 let migrationCommand : string ;
123- const compareBase = mergeStatusResponse . compare_branch ?? mergeStatusResponse . base_branch ;
124- const baseBranch = mergeStatusResponse . base_branch ?? 'main' ;
130+ const compareBranch = mergeStatusResponse ?. merge_details ?. compare_branch ;
131+ const baseBranch = mergeStatusResponse ?. merge_details ?. base_branch ;
125132
126133 if ( os . platform ( ) === 'win32' ) {
127- migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${ scriptFolderPath } --config compare-branch:${ compareBase } file-path:./${ scriptFolderPath } --branch ${ baseBranch } --stack-api-key ${ stackAPIKey } ` ;
134+ migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${ scriptFolderPath } --config compare-branch:${ compareBranch } file-path:./${ scriptFolderPath } --branch ${ baseBranch } --stack-api-key ${ stackAPIKey } ` ;
128135 } else {
129- migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${ scriptFolderPath } --config {compare-branch:${ compareBase } ,file-path:./${ scriptFolderPath } } --branch ${ baseBranch } --stack-api-key ${ stackAPIKey } ` ;
136+ migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${ scriptFolderPath } --config {compare-branch:${ compareBranch } ,file-path:./${ scriptFolderPath } } --branch ${ baseBranch } --stack-api-key ${ stackAPIKey } ` ;
130137 }
131138
132139 cliux . print (
0 commit comments