@@ -15,7 +15,7 @@ import {
1515
1616import { Context , ImportConfig } from '../../../types' ;
1717import { ModuleImporter } from '../../../import' ;
18- import { setupImportConfig } from '../../../utils' ;
18+ import { setupImportConfig } from '../../../utils' ;
1919
2020export default class ImportCommand extends Command {
2121 static description = messageHandler . parse ( 'Import content from a stack' ) ;
@@ -149,53 +149,60 @@ export default class ImportCommand extends Command {
149149 let importConfig : ImportConfig = await setupImportConfig ( flags ) ;
150150 // Prepare the context object
151151 const context = this . createImportContext ( importConfig . apiKey , importConfig . authenticationMethod ) ;
152- importConfig . context = { ...context } ;
152+ importConfig . context = { ...context } ;
153153 //log.info(`Using Cli Version: ${this.context?.cliVersion}`, importConfig.context);
154-
154+
155155 // Note setting host to create cma client
156156 importConfig . host = this . cmaHost ;
157157 importConfig . region = this . region ;
158158 if ( this . developerHubUrl ) importConfig . developerHubBaseUrl = this . developerHubUrl ;
159159 if ( this . personalizeUrl ) importConfig . modules . personalize . baseURL [ importConfig . region . name ] = this . personalizeUrl ;
160-
160+
161161 const managementAPIClient : ContentstackClient = await managementSDKClient ( importConfig ) ;
162-
162+
163163 if ( ! flags . branch ) {
164164 try {
165165 // Use stack configuration to check for branch availability
166166 // false positive - no hardcoded secret here
167- // @ts -ignore-next-line secret-detection
167+ // @ts -ignore-next-line secret-detection
168168 const keyProp = 'api_key' ;
169169 const branches = await managementAPIClient
170- . stack ( { [ keyProp ] : importConfig . apiKey } )
171- . branch ( )
172- . query ( )
173- . find ( )
174- . then ( ( { items } : any ) => items ) ;
170+ . stack ( { [ keyProp ] : importConfig . apiKey } )
171+ . branch ( )
172+ . query ( )
173+ . find ( )
174+ . then ( ( { items } : any ) => items ) ;
175175 if ( branches . length ) {
176176 flags . branch = 'main' ;
177177 }
178178 } catch ( error ) {
179179 // Branch not enabled, just the let flow continue
180180 }
181181 }
182+
183+ // Set backupDir early so it's available in error handling
184+ backupDir = importConfig . backupDir ;
185+
182186 const moduleImporter = new ModuleImporter ( managementAPIClient , importConfig ) ;
183187 const result = await moduleImporter . start ( ) ;
184- backupDir = importConfig . backupDir ;
185188
186- if ( ! result ?. noSuccessMsg ) {
189+ if ( ! result ?. noSuccessMsg ) {
187190 const successMessage = importConfig . stackName
188- ? `Successfully imported the content to the stack named ${ importConfig . stackName } with the API key ${ importConfig . apiKey } .`
189- : `The content has been imported to the stack ${ importConfig . apiKey } successfully!` ;
191+ ? `Successfully imported the content to the stack named ${ importConfig . stackName } with the API key ${ importConfig . apiKey } .`
192+ : `The content has been imported to the stack ${ importConfig . apiKey } successfully!` ;
190193 log . success ( successMessage , importConfig . context ) ;
191194 }
192195
193- log . success ( `The log has been stored at '${ getLogPath ( ) } '` , importConfig . context )
196+ log . success ( `The log has been stored at '${ getLogPath ( ) } '` , importConfig . context ) ;
194197 log . info ( `The backup content has been stored at '${ backupDir } '` , importConfig . context ) ;
195198 } catch ( error ) {
196199 handleAndLogError ( error ) ;
197- log . info ( `The log has been stored at '${ getLogPath ( ) } '` )
198- log . info ( `The backup content has been stored at '${ backupDir } '` ) ;
200+ log . info ( `The log has been stored at '${ getLogPath ( ) } '` ) ;
201+ if ( backupDir ) {
202+ log . info ( `The backup content has been stored at '${ backupDir } '` ) ;
203+ } else {
204+ log . info ( 'No backup directory was created due to early termination' ) ;
205+ }
199206 }
200207 }
201208
0 commit comments