@@ -262,14 +262,19 @@ export default class BaseClass {
262262 this . log ( error , 'error' ) ;
263263 this . exit ( 1 ) ;
264264 } ) ) || [ ] ;
265- this . config . selectedStack = await ux
266- . inquire ( {
267- name : 'stack' ,
268- type : 'search-list' ,
269- choices : listOfStacks ,
270- message : 'Stack' ,
271- } )
272- . then ( ( name ) => find ( listOfStacks , { name } ) ) ;
265+
266+ if ( this . config . selectedStack ) {
267+ this . config . selectedStack = find ( listOfStacks , { api_key : this . config . selectedStack } ) ;
268+ } else {
269+ this . config . selectedStack = await ux
270+ . inquire ( {
271+ name : 'stack' ,
272+ type : 'search-list' ,
273+ choices : listOfStacks ,
274+ message : 'Stack' ,
275+ } )
276+ . then ( ( name ) => find ( listOfStacks , { name } ) ) ;
277+ }
273278 }
274279
275280 /**
@@ -299,16 +304,19 @@ export default class BaseClass {
299304 this . exit ( 1 ) ;
300305 } ) ) || [ ] ;
301306
302- this . config . deliveryToken = await ux
303- . inquire ( {
304- type : 'search-list' ,
305- name : 'deliveryToken' ,
306- choices : listOfDeliveryTokens ,
307- message : 'Delivery token' ,
308- } )
309- . then ( ( name ) => find ( listOfDeliveryTokens , { name } ) as Record < string , any > ) ;
310-
311- this . config . environment = this . config . deliveryToken . scope [ 0 ] ?. environments [ 0 ] ?. name ;
307+ if ( this . config . deliveryToken ) {
308+ this . config . deliveryToken = find ( listOfDeliveryTokens , { token : this . config . deliveryToken } ) ;
309+ } else {
310+ this . config . deliveryToken = await ux
311+ . inquire ( {
312+ type : 'search-list' ,
313+ name : 'deliveryToken' ,
314+ choices : listOfDeliveryTokens ,
315+ message : 'Delivery token' ,
316+ } )
317+ . then ( ( name ) => find ( listOfDeliveryTokens , { name } ) as Record < string , any > ) ;
318+ }
319+ this . config . environment = this . config . deliveryToken ?. scope [ 0 ] ?. environments [ 0 ] ?. name ;
312320 }
313321
314322 /**
@@ -321,38 +329,51 @@ export default class BaseClass {
321329 let addNew = true ;
322330 const envVariables = [ ] ;
323331
324- do {
325- const variable = await ux
326- . inquire ( {
327- type : 'input' ,
328- name : 'variable' ,
329- message :
330- 'Enter key and value with a colon between them, and use a comma(,) for the key-value pair. Format: <key1>:<value1>, <key2>:<value2> Ex: APP_ENV:prod, TEST_ENV:testVal' ,
331- } )
332- . then ( ( variable ) => {
333- return map ( split ( variable as string , ',' ) , ( variable ) => {
334- let [ key , value ] = split ( variable as string , ':' ) ;
335- value = ( value || '' ) . trim ( ) ;
336- key = ( key || '' ) . trim ( ) ;
337-
338- return { key, value } ;
339- } ) . filter ( ( { key } ) => key ) ;
340- } ) ;
332+ if ( ! this . config . envVariables ) {
333+ do {
334+ const variable = await ux
335+ . inquire ( {
336+ type : 'input' ,
337+ name : 'variable' ,
338+ message :
339+ 'Enter key and value with a colon between them, and use a comma(,) for the key-value pair. Format: <key1>:<value1>, <key2>:<value2> Ex: APP_ENV:prod, TEST_ENV:testVal' ,
340+ } )
341+ . then ( ( variable ) => {
342+ return map ( split ( variable as string , ',' ) , ( variable ) => {
343+ let [ key , value ] = split ( variable as string , ':' ) ;
344+ value = ( value || '' ) . trim ( ) ;
345+ key = ( key || '' ) . trim ( ) ;
346+
347+ return { key, value } ;
348+ } ) . filter ( ( { key } ) => key ) ;
349+ } ) ;
341350
342- envVariables . push ( ...variable ) ;
351+ envVariables . push ( ...variable ) ;
343352
344- if (
345- ! ( await ux . inquire ( {
346- type : 'confirm' ,
347- name : 'canImportFromStack' ,
348- message : 'Would you like to add more variables?' ,
349- } ) )
350- ) {
351- addNew = false ;
352- }
353- } while ( addNew ) ;
353+ if (
354+ ! ( await ux . inquire ( {
355+ type : 'confirm' ,
356+ name : 'canImportFromStack' ,
357+ message : 'Would you like to add more variables?' ,
358+ } ) )
359+ ) {
360+ addNew = false ;
361+ }
362+ } while ( addNew ) ;
363+
364+ this . envVariables . push ( ...envVariables ) ;
365+ } else {
366+ if ( typeof this . config . envVariables === 'string' ) {
367+ const variable = map ( split ( this . config . envVariables as string , ',' ) , ( variable ) => {
368+ let [ key , value ] = split ( variable as string , ':' ) ;
369+ value = ( value || '' ) . trim ( ) ;
370+ key = ( key || '' ) . trim ( ) ;
354371
355- this . envVariables . push ( ...envVariables ) ;
372+ return { key, value } ;
373+ } ) ;
374+ this . envVariables . push ( ...variable ) ;
375+ }
376+ }
356377 }
357378
358379 /**
@@ -492,19 +513,16 @@ export default class BaseClass {
492513 * @memberof BaseClass
493514 */
494515 async handleEnvImportFlow ( ) : Promise < void > {
495- const variablePreparationTypeOptions = [
496- 'Import variables from a stack' ,
497- 'Manually add custom variables to the list' ,
498- 'Import variables from the local env file' ,
499- ] ;
500- const variablePreparationType : Array < string > = await ux . inquire ( {
501- type : 'checkbox' ,
502- name : 'variablePreparationType' ,
503- default : this . config . framework ,
504- choices : variablePreparationTypeOptions ,
505- message : 'Import variables from a stack and/or manually add custom variables to the list' ,
506- // validate: this.inquireRequireValidation,
507- } ) ;
516+ const variablePreparationType =
517+ this . config . variableType ||
518+ ( await ux . inquire ( {
519+ type : 'checkbox' ,
520+ name : 'variablePreparationType' ,
521+ default : this . config . framework ,
522+ choices : this . config . variablePreparationTypeOptions ,
523+ message : 'Import variables from a stack and/or manually add custom variables to the list' ,
524+ // validate: this.inquireRequireValidation,
525+ } ) ) ;
508526
509527 if ( includes ( variablePreparationType , 'Import variables from a stack' ) ) {
510528 await this . importEnvFromStack ( ) ;
@@ -519,8 +537,8 @@ export default class BaseClass {
519537 if ( this . envVariables . length ) {
520538 this . printAllVariables ( ) ;
521539 } else {
522- this . log ( 'Import variables from a stack and/or manually add custom variables to the list ' , 'warn ' ) ;
523- // this.exit(1);
540+ this . log ( 'Please provide env file! ' , 'error ' ) ;
541+ this . exit ( 1 ) ;
524542 }
525543 }
526544
@@ -533,10 +551,10 @@ export default class BaseClass {
533551 async importVariableFromLocalConfig ( ) : Promise < void > {
534552 const localEnv =
535553 dotEnv . config ( {
536- path : this . config . projectBasePath ,
554+ path : ` ${ this . config . projectBasePath } /.env.local` ,
537555 } ) . parsed ||
538556 dotEnv . config ( {
539- path : ` ${ this . config . projectBasePath } /.env.local` ,
557+ path : this . config . projectBasePath ,
540558 } ) . parsed ;
541559
542560 if ( ! isEmpty ( localEnv ) ) {
0 commit comments