@@ -18,7 +18,7 @@ const PLAN_DEFINITIONS = {
1818 "Version" : "Community" ,
1919 "Description" : "FREE membership with community access to development resources" ,
2020 "Subscription" : 0
21- } ,
21+ } ,
2222 "PREMIUM" : {
2323 "Index" : 1 ,
2424 "Version" : "Enterprise" ,
@@ -36,7 +36,7 @@ const CRESET = '\x1b[0m'
3636const CDONE = '\x1b[37m'
3737const CBRIGHT = '\x1b[37m'
3838const CUNDERLINE = '\x1b[4m'
39- const COLORS = function ( name ) {
39+ const COLORS = function ( name ) {
4040 const colorCodes = [ "\x1b[31m" , "\x1b[32m" , "\x1b[33m" , "\x1b[34m" , "\x1b[35m" , "\x1b[36m" , "\x1b[31m" , "\x1b[32m" , "\x1b[33m" , "\x1b[34m" , "\x1b[35m" , "\x1b[36m" , "\x1b[31m" , "\x1b[32m" , "\x1b[33m" , "\x1b[34m" , "\x1b[35m" , "\x1b[36m" , "\x1b[31m" , "\x1b[32m" , "\x1b[33m" , "\x1b[34m" , "\x1b[35m" , "\x1b[36m" , "\x1b[31m" , "\x1b[32m" , "\x1b[33m" , "\x1b[34m" , "\x1b[35m" , "\x1b[36m" ]
4141 return colorCodes [ ( name . toUpperCase ( ) . charCodeAt ( 0 ) - 65 ) % colorCodes . length ]
4242}
@@ -142,8 +142,8 @@ const deployStack = function (options) {
142142 }
143143 Object . keys ( docYaml . Parameters ) . map ( paramName => {
144144 function getSimilarParameter ( stackParamteres , paramName ) {
145- let foundParam = stackParamteres [ Object . keys ( stackParamteres ) . find ( x => paramName == x . replace ( / \x1b \[ [ 0 - 9 ; ] * m / g, "" ) . replace ( / [ \W _ ] / g, '' ) ) ]
146- return foundParam || stackParamteres [ Object . keys ( stackParamteres ) . find ( x => paramName . indexOf ( x . split ( '.' ) [ 1 ] . replace ( / \x1b \[ [ 0 - 9 ; ] * m / g, "" ) ) >= 0 ) ]
145+ let foundParam = stackParamteres [ Object . keys ( stackParamteres ) . find ( x => paramName == x . replace ( / \x1b \[ [ 0 - 9 ; ] * m / g, "" ) . replace ( / [ \W _ ] / g, '' ) ) ]
146+ return foundParam || stackParamteres [ Object . keys ( stackParamteres ) . find ( x => paramName . indexOf ( x . split ( '.' ) [ 1 ] . replace ( / \x1b \[ [ 0 - 9 ; ] * m / g, "" ) ) >= 0 ) ]
147147 }
148148 resultParameters [ paramName ] = parameters [ paramName ] || getSimilarParameter ( stackParamteres , paramName ) || docYaml . Parameters [ paramName ] . Default
149149 if ( ! resultParameters [ paramName ] ) {
@@ -160,7 +160,7 @@ const deployStack = function (options) {
160160 function selectParameter ( param , type , resultParameters , stackParamteres ) {
161161 const options = Object . keys ( stackParamteres ) . map ( x => `${ x } = ${ stackParamteres [ x ] } ` )
162162 const index = readlineSync . keyInSelect ( options , `Select a value for ${ CPROMPT } ${ param } ${ CRESET } parameter ?` , { cancel : `${ CBRIGHT } Move to next step${ CRESET } - (Continue)` } )
163- if ( index >= 0 ) {
163+ if ( index >= 0 ) {
164164 const selectedParam = param
165165 const selectedValue = stackParamteres [ Object . keys ( stackParamteres ) [ index ] ]
166166 resultParameters [ selectedParam ] = selectedValue
@@ -175,7 +175,7 @@ const deployStack = function (options) {
175175 if ( redoParamIndex !== - 1 ) {
176176 selectParameter ( Object . keys ( resultParameters ) [ redoParamIndex ] , "String" , resultParameters , stackParamteres )
177177 }
178- } while ( redoParamIndex !== - 1 )
178+ } while ( redoParamIndex !== - 1 )
179179 }
180180
181181 function saveParameters ( resultParameters ) {
@@ -200,7 +200,7 @@ const deployStack = function (options) {
200200 finalResult . resultErrors . map ( error => {
201201 const adjustParameter = error . name
202202 simplify . consoleWithErrors ( `${ opName } -Verification` , `(${ stackFullName } ) name=${ adjustParameter } type=${ error . type } is not set.` )
203- finalResult . resultParameters [ adjustParameter ] = readlineSync . question ( `\n * Enter parameter value for ${ CPROMPT } ${ adjustParameter } ${ CRESET } :` )
203+ finalResult . resultParameters [ adjustParameter ] = readlineSync . question ( `\n * Enter parameter value for ${ CPROMPT } ${ adjustParameter } ${ CRESET } :` )
204204 } )
205205 saveParameters ( finalResult . resultParameters )
206206 createStack ( templateURL , finalResult . resultParameters , stackPluginModule )
@@ -565,6 +565,7 @@ const getDirectories = source =>
565565 fs . readdirSync ( source , { withFileTypes : true } )
566566 . filter ( dirent => dirent . isDirectory ( ) )
567567 . map ( dirent => dirent . name )
568+
568569const showTemplates = ( templateFolderName , promptDescription ) => {
569570 console . log ( promptDescription )
570571 getDirectories ( path . join ( __dirname , templateFolderName ) ) . map ( ( template , idx ) => {
@@ -653,7 +654,7 @@ var optCMD = (argv._.length > 1 ? argv._[1] : undefined)
653654var cmdArg = argv [ 'stack' ] || argv [ 'function' ] || optCMD
654655var cmdType = cmdArg ? fs . existsSync ( path . resolve ( argv . location , cmdArg , "template.yaml" ) ) ? "CF-Stack" : "Function" : undefined
655656
656- const showSubscriptionPlan = function ( userSession ) {
657+ const showSubscriptionPlan = function ( userSession ) {
657658 currentSubscription = ( userSession . getIdToken ( ) . payload [ `subscription` ] || 'Basic' )
658659 const currentVersion = PLAN_DEFINITIONS [ currentSubscription . toUpperCase ( ) ] . Version || 'Community'
659660 console . log ( `\n` , ` * ${ CPROMPT } Welcome back${ CRESET } : ${ userSession . getIdToken ( ) . payload [ `name` ] } ` )
@@ -727,7 +728,7 @@ const processCLI = function (cmdRun, session) {
727728 `BASIC - ${ PLAN_DEFINITIONS [ "BASIC" ] . Description } ` ,
728729 `PREMIUM - ${ PLAN_DEFINITIONS [ "PREMIUM" ] . Description } ` ] ,
729730 ` - You are about to change your subscription from ${ CPROMPT } ${ currentSubscription . toUpperCase ( ) } ${ CRESET } plan to: ` )
730- if ( subscriptionPlan >= 0 ) {
731+ if ( subscriptionPlan >= 0 ) {
731732 const newSubscription = Object . keys ( PLAN_DEFINITIONS ) . find ( x => PLAN_DEFINITIONS [ x ] . Index == ( subscriptionPlan ) )
732733 console . log ( `\n * You have selected to pay ${ PLAN_DEFINITIONS [ newSubscription ] . Subscription } $ for ${ newSubscription } version!` )
733734 console . log ( ` * Unfortunately, this feature is not available at the moment. \n` )
@@ -792,7 +793,7 @@ const processCLI = function (cmdRun, session) {
792793 }
793794}
794795
795- if ( [ "LOGIN" , "REGISTER" ] . indexOf ( cmdOPS ) == - 1 ) {
796+ if ( [ "INIT" , " LOGIN", "REGISTER" ] . indexOf ( cmdOPS ) == - 1 ) {
796797 getCurrentSession ( ) . then ( session => {
797798 if ( session && session . isValid ( ) ) {
798799 showSubscriptionPlan ( session )
@@ -807,17 +808,19 @@ if (["LOGIN", "REGISTER"].indexOf(cmdOPS) == -1) {
807808 console . log ( ` *` , `Register: \tsimplify-cli register` , `\n` )
808809 } )
809810} else {
810- if ( [ "INIT" ] . indexOf ( cmdOPS ) == - 1 && ! fs . existsSync ( path . resolve ( argv . config || 'config.json' ) ) ) {
811- console . log ( `\n` , `- ${ CPROMPT } This is not a valid environment${ CRESET } . You must create an environment first.` )
812- console . log ( `\n` , `*` , `Create environment: \tsimplify-cli init` , `\n` )
813- } else {
811+ if ( [ "INIT" , "LOGIN" , "REGISTER" ] . indexOf ( cmdOPS ) == - 1 && ! fs . existsSync ( path . resolve ( argv . config || 'config.json' ) ) ) {
812+ console . log ( `\n` , `- ${ CPROMPT } This is not a valid environment${ CRESET } . You must create an environment first.` )
813+ console . log ( `\n` , `*` , `Create environment: \tsimplify-cli init` , `\n` )
814+ } else if ( [ "INIT" ] . indexOf ( cmdOPS ) == - 1 ) {
814815 const configInfo = JSON . parse ( fs . readFileSync ( path . resolve ( argv . config || 'config.json' ) ) )
815816 if ( configInfo . hasOwnProperty ( 'Profile' ) && configInfo . hasOwnProperty ( 'Region' ) && configInfo . hasOwnProperty ( 'Bucket' ) ) {
816- processCLI ( cmdOPS )
817+ processCLI ( cmdOPS )
817818 } else {
818- console . log ( `\n` , `- ${ CPROMPT } This is not a valid environment${ CRESET } . The ${ argv . config || 'config.json' } is incorrect.` )
819- console . log ( `\n` , `*` , `Create environment: \tsimplify-cli init` , `\n` )
819+ console . log ( `\n` , `- ${ CPROMPT } This is not a valid environment${ CRESET } . The ${ argv . config || 'config.json' } is incorrect.` )
820+ console . log ( `\n` , `*` , `Create environment: \tsimplify-cli init` , `\n` )
820821 }
822+ } else {
823+ processCLI ( "INIT" )
821824 }
822825}
823826
0 commit comments