@@ -20,7 +20,7 @@ export default class ImportEnvironments extends BaseClass {
2020
2121 constructor ( { importConfig, stackAPIClient } : ModuleClassParams ) {
2222 super ( { importConfig, stackAPIClient } ) ;
23- this . environmentsConfig = importConfig . modules . environments ;
23+ this . environmentsConfig = importConfig . modules . environments ;
2424 this . mapperDirPath = join ( this . importConfig . backupDir , 'mapper' , 'environments' ) ;
2525 this . environmentsFolderPath = join ( this . importConfig . backupDir , this . environmentsConfig . dirName ) ;
2626 this . envUidMapperPath = join ( this . mapperDirPath , 'uid-mapping.json' ) ;
@@ -40,7 +40,10 @@ export default class ImportEnvironments extends BaseClass {
4040
4141 //Step1 check folder exists or not
4242 if ( fileHelper . fileExistsSync ( this . environmentsFolderPath ) ) {
43- this . environments = fsUtil . readFile ( join ( this . environmentsFolderPath , 'environments.json' ) , true ) as Record < string , unknown > ;
43+ this . environments = fsUtil . readFile ( join ( this . environmentsFolderPath , 'environments.json' ) , true ) as Record <
44+ string ,
45+ unknown
46+ > ;
4447 } else {
4548 log ( this . importConfig , `No such file or directory - '${ this . environmentsFolderPath } '` , 'error' ) ;
4649 return ;
@@ -79,10 +82,13 @@ export default class ImportEnvironments extends BaseClass {
7982 fsUtil . writeFile ( this . envUidMapperPath , this . envUidMapper ) ;
8083 } ;
8184
82- const onReject = ( { error, apiData } : any ) => {
85+ const onReject = async ( { error, apiData } : any ) => {
8386 const err = error ?. message ? JSON . parse ( error . message ) : error ;
84- const { name } = apiData ;
87+ const { name, uid } = apiData ;
8588 if ( err ?. errors ?. name ) {
89+ const res = await this . getEnvDetails ( name ) ;
90+ this . envUidMapper [ uid ] = res ?. uid || ' ' ;
91+ fsUtil . writeFile ( this . envUidMapperPath , this . envUidMapper ) ;
8692 log ( this . importConfig , `Environment '${ name } ' already exists` , 'info' ) ;
8793 } else {
8894 this . envFailed . push ( apiData ) ;
@@ -128,4 +134,14 @@ export default class ImportEnvironments extends BaseClass {
128134 }
129135 return apiOptions ;
130136 }
137+
138+ async getEnvDetails ( envName : string ) {
139+ return await this . stack
140+ . environment ( envName )
141+ . fetch ( )
142+ . then ( ( data : any ) => data )
143+ . catch ( ( error : any ) => {
144+ log ( this . importConfig , `Failed to fetch environment details. ${ formatError ( error ) } ` , 'error' ) ;
145+ } ) ;
146+ }
131147}
0 commit comments