@@ -7,10 +7,9 @@ import {
77 getBranchFromAlias ,
88 CLIProgressManager ,
99} from '@contentstack/cli-utilities' ;
10- import { setupBranches , setupExportDir , writeExportMetaFile } from '../utils' ;
1110import startModuleExport from './modules' ;
12- import startJSModuleExport from './modules-js' ;
1311import { ExportConfig , Modules } from '../types' ;
12+ import { setupBranches , setupExportDir } from '../utils' ;
1413
1514class ModuleExporter {
1615 private managementAPIClient : ContentstackClient ;
@@ -48,46 +47,55 @@ class ModuleExporter {
4847 }
4948
5049 async exportByBranches ( ) : Promise < void > {
51- // loop through the branches and export it parallel
52- for ( const [ index , branch ] of this . exportConfig . branches . entries ( ) ) {
53- try {
54- this . exportConfig . branchName = branch . uid ;
55- this . stackAPIClient . stackHeaders . branch = branch . uid ;
56- this . exportConfig . branchDir = path . join ( this . exportConfig . exportDir , branch . uid ) ;
57-
58- // Reset progress manager for each branch (except the first one which was initialized in export command)
59- if ( index >= 0 ) {
60- CLIProgressManager . clearGlobalSummary ( ) ;
61- CLIProgressManager . initializeGlobalSummary (
62- `EXPORT-${ branch . uid } ` ,
63- branch . uid ,
64- `Exporting "${ branch . uid } " branch content...` ,
65- ) ;
66- }
67-
68- log . info ( `Exporting content from branch ${ branch . uid } ` , this . exportConfig . context ) ;
69- writeExportMetaFile ( this . exportConfig , this . exportConfig . branchDir ) ;
70- await this . export ( ) ;
71-
72- // Print branch-specific summary
73- if ( index <= this . exportConfig . branches . length - 1 ) {
74- CLIProgressManager . printGlobalSummary ( ) ;
75- }
76-
77- log . success ( `The content of branch ${ branch . uid } has been exported successfully!` , this . exportConfig . context ) ;
78- } catch ( error ) {
79- handleAndLogError (
80- error ,
81- { ...this . exportConfig . context , branch : branch . uid } ,
82- messageHandler . parse ( 'FAILED_EXPORT_CONTENT_BRANCH' , { branch : branch . uid } ) ,
83- ) ;
84- throw new Error ( messageHandler . parse ( 'FAILED_EXPORT_CONTENT_BRANCH' , { branch : branch . uid } ) ) ;
50+ let targetBranch ;
51+
52+ if ( this . exportConfig . branchName ) {
53+ // User specified a branch - export only that branch
54+ targetBranch = this . exportConfig . branches . find ( ( branch ) => branch . uid === this . exportConfig . branchName ) ;
55+ if ( ! targetBranch ) {
56+ throw new Error ( `Branch '${ this . exportConfig . branchName } ' not found in available branches` ) ;
57+ }
58+ } else {
59+ // No specific branch mentioned - export only the main branch
60+ targetBranch = this . exportConfig . branches . find ( ( branch ) => branch . uid === 'main' ) ;
61+ if ( ! targetBranch ) {
62+ throw new Error ( 'No main branch or available branches found' ) ;
8563 }
8664 }
65+
66+ try {
67+ this . exportConfig . branchName = targetBranch . uid ;
68+ this . stackAPIClient . stackHeaders . branch = targetBranch . uid ;
69+ this . exportConfig . branchDir = path . join ( this . exportConfig . exportDir , targetBranch . uid ) ;
70+
71+ // Initialize progress manager for the target branch
72+ CLIProgressManager . clearGlobalSummary ( ) ;
73+ CLIProgressManager . initializeGlobalSummary (
74+ `EXPORT-${ targetBranch . uid } ` ,
75+ targetBranch . uid ,
76+ `Exporting "${ targetBranch . uid } " branch content...` ,
77+ ) ;
78+
79+ log . info ( `Exporting content from '${ targetBranch . uid } ' branch` , this . exportConfig . context ) ;
80+ await this . export ( ) ;
81+ CLIProgressManager . printGlobalSummary ( ) ;
82+
83+ log . success (
84+ `The content of branch ${ targetBranch . uid } has been exported successfully!` ,
85+ this . exportConfig . context ,
86+ ) ;
87+ } catch ( error ) {
88+ handleAndLogError (
89+ error ,
90+ { ...this . exportConfig . context , branch : targetBranch ?. uid } ,
91+ messageHandler . parse ( 'FAILED_EXPORT_CONTENT_BRANCH' , { branch : targetBranch ?. uid } ) ,
92+ ) ;
93+ throw new Error ( messageHandler . parse ( 'FAILED_EXPORT_CONTENT_BRANCH' , { branch : targetBranch ?. uid } ) ) ;
94+ }
8795 }
8896
8997 async export ( ) {
90- log . info ( `Started to export content, version is ${ this . exportConfig . contentVersion } ` , this . exportConfig . context ) ;
98+ log . info ( `Started to export content` , this . exportConfig . context ) ;
9199 // checks for single module or all modules
92100 if ( this . exportConfig . singleModuleExport ) {
93101 return this . exportSingleModule ( this . exportConfig . moduleName ) ;
@@ -99,22 +107,11 @@ class ModuleExporter {
99107 log . info ( `Exporting module: ${ moduleName } ` , this . exportConfig . context ) ;
100108 // export the modules by name
101109 // calls the module runner which inturn calls the module itself
102- if ( this . exportConfig . contentVersion === 2 ) {
103- await startModuleExport ( {
104- stackAPIClient : this . stackAPIClient ,
105- exportConfig : this . exportConfig ,
106- moduleName,
107- } ) ;
108- } else {
109- //NOTE - new modules support only ts
110- if ( this . exportConfig . onlyTSModules . indexOf ( moduleName ) === - 1 ) {
111- await startJSModuleExport ( {
112- stackAPIClient : this . stackAPIClient ,
113- exportConfig : this . exportConfig ,
114- moduleName,
115- } ) ;
116- }
117- }
110+ await startModuleExport ( {
111+ stackAPIClient : this . stackAPIClient ,
112+ exportConfig : this . exportConfig ,
113+ moduleName,
114+ } ) ;
118115 }
119116
120117 async exportSingleModule ( moduleName : Modules ) : Promise < void > {
0 commit comments