@@ -15,29 +15,29 @@ import {
1515} from "../rover.types"
1616import * as child from "child_process"
1717const exec = child . execSync
18- let moreStack
18+ let moreStacks
1919let customStacks : Record < string , Array < string > >
2020
2121export async function createSAMCLI ( ) : Promise < void > {
22- const app_name : Record < string , string > = await util . inputString (
23- "app_name " ,
22+ const appName : Record < string , string > = await util . inputString (
23+ "appName " ,
2424 "" ,
2525 false ,
2626 "App Name:"
2727 )
28- await roverHelpers . checkFile ( app_name [ "app_name "] , "no" )
28+ await roverHelpers . checkFile ( appName [ "appName "] , "no" )
2929 const language = await util . languageChoice ( )
3030
31- const template : IroverInput = await createModules ( app_name , language )
31+ const template : IroverInput = await createModules ( appName , language )
3232 await rover_generateSAM . generateSAM ( { template } [ "template" ] )
3333}
3434export async function addComponentCLI ( ) {
35- const app_name = await util . inputString ( "app_name " , "" , false , "App Name" )
35+ const appName = await util . inputString ( "appName " , "" , false , "App Name" )
3636 let template : IroveraddComponentInput
37- await roverHelpers . checkFile ( app_name [ "app_name "] , "yes" )
37+ await roverHelpers . checkFile ( appName [ "appName "] , "yes" )
3838 const language = await util . languageChoice ( )
39- const file_name = await exec ( `ls ${ app_name [ "app_name "] } /*.yaml ` ) . toString ( )
40- const CompStacks = await roverHelpers . checkNested ( file_name )
39+ const fileName = await exec ( `ls ${ appName [ "appName "] } /*.yaml ` ) . toString ( )
40+ const CompStacks = await roverHelpers . checkNested ( fileName )
4141 const nestedComponents : TnestedComponentsObject = < TnestedComponentsObject > { }
4242 const choice = Object . keys ( CompStacks [ "compStacks" ] )
4343 let i = 0
@@ -64,45 +64,45 @@ export async function addComponentCLI() {
6464 }
6565
6666 template = {
67- ...app_name ,
67+ ...appName ,
6868 language,
6969 nested,
70- file_name ,
70+ fileName ,
7171 nestedComponents,
7272 }
7373 } else {
7474 const choice = cliConfig . customizable . components
7575 const Compnents = < Array < string > > (
7676 await util . multichoice ( "components" , choice , "" )
7777 )
78- template = { ...app_name , language }
78+ template = { ...appName , language }
7979 if ( customStacks !== null )
8080 template = {
8181 ...template ,
82- file_name ,
82+ fileName ,
8383 ...Compnents ,
8484 }
8585 }
86- moreStack = await util . moreStack (
86+ moreStacks = await util . choicesYorN (
8787 "Do you want to add one more components to modules ?"
8888 )
8989 i = i + 1
90- } while ( moreStack !== "No" )
90+ } while ( moreStacks !== "No" )
9191 await rover_addComponent . addComponents ( template )
9292}
93- export async function addModuleCLI ( ) : Promise < void > {
93+ export async function addModuleCLIs ( ) : Promise < void > {
9494 const res = await roverADD ( )
9595 let template : IroveraddModule = < IroveraddModule > { }
96- const app_name = res [ "appname " ]
96+ const appName = res [ "appName " ]
9797 const language = res [ "language" ]
98- const file_name = res [ "filename" ]
98+ const fileName = res [ "filename" ]
9999 const addToExisting = await util . multichoice (
100100 "addToExisting" ,
101101 [ "Yes" , "No" ] ,
102102 "Do you want to Add a module to existing Module :"
103103 )
104104 if ( addToExisting . addToExisting [ 0 ] == "Yes" ) {
105- const CompStacks = await roverHelpers . checkNested ( file_name )
105+ const CompStacks = await roverHelpers . checkNested ( fileName )
106106 const choice = Object . keys ( CompStacks [ "compStacks" ] )
107107 let i = 0
108108 do {
@@ -116,11 +116,11 @@ export async function addModuleCLI(): Promise<void> {
116116 Object . values ( chooseStack ) . includes ( ele )
117117 )
118118 // const samResources = roverHelpers.listSAMResources(
119- // file_name ,
119+ // fileName ,
120120 // selectedChoice[0]
121121 // )
122122 const moduletemplate = < IroveraddModule > (
123- await createModules ( app_name , language )
123+ await createModules ( appName , language )
124124 )
125125 Object . keys ( moduletemplate . stackDetails ) . forEach ( ( ele ) => {
126126 moduletemplate . stackDetails [ ele ] . stackName = selectedChoice [ 0 ]
@@ -138,23 +138,90 @@ export async function addModuleCLI(): Promise<void> {
138138 const Compnents = < Array < string > > (
139139 await util . multichoice ( "components" , choice , "" )
140140 )
141- template = { ...app_name , language }
141+ template = { ...appName , language }
142142 if ( customStacks !== null )
143143 template = {
144144 ...template ,
145145 ...Compnents ,
146146 }
147147 }
148- moreStack = await util . moreStack (
148+ moreStacks = await util . choicesYorN (
149149 "Do you want to add one more modules to another stack ?"
150150 )
151151 i = i + 1
152- } while ( moreStack !== "No" )
153- template [ "file_name" ] = file_name
152+ } while ( moreStacks !== "No" )
153+ template [ "fileName" ] = fileName
154+ await rover_addModulesToexisting . addModulesToExistingStack ( template )
155+ } else {
156+ template = < IroveraddModule > await createModules ( appName , language )
157+ template [ "fileName" ] = fileName
158+ await rover_addModules . addModules ( template )
159+ }
160+ }
161+ export async function addModuleCLI ( ) : Promise < void > {
162+ const res = await roverADD ( )
163+ let template : IroveraddModule = < IroveraddModule > { }
164+ const appName = res [ "appName" ]
165+ const language = res [ "language" ]
166+ const fileName = res [ "filename" ]
167+ const addToExisting = await util . choicesYorN (
168+ "Do you want to Add a module to existing Module :"
169+ )
170+ if ( addToExisting == "Yes" ) {
171+ const CompStacks = await roverHelpers . checkNested ( fileName )
172+ const choice = Object . keys ( CompStacks [ "compStacks" ] )
173+ do {
174+ const nested = CompStacks [ "checkNested" ]
175+ if ( nested ) {
176+ template = await addModuleToStack ( choice , appName , language , template )
177+ } else {
178+ const components = < Array < string > > (
179+ await util . multichoice (
180+ "components" ,
181+ cliConfig . customizable . components ,
182+ ""
183+ )
184+ )
185+ template = { ...appName , language, ...components }
186+ }
187+ moreStacks = await util . choicesYorN (
188+ "Do you want to add one more modules to another stack ?"
189+ )
190+ } while ( moreStacks !== "No" )
191+ template [ "fileName" ] = fileName
154192 await rover_addModulesToexisting . addModulesToExistingStack ( template )
155193 } else {
156- template = < IroveraddModule > await createModules ( app_name , language )
157- template [ "file_name " ] = file_name
194+ template = < IroveraddModule > await createModules ( appName , language )
195+ template [ "fileName " ] = fileName
158196 await rover_addModules . addModules ( template )
159197 }
160198}
199+
200+ async function addModuleToStack (
201+ choice : string [ ] ,
202+ appName : Record < string , string > ,
203+ language : string ,
204+ template : IroveraddModule
205+ ) {
206+ const chooseStack = await util . inputType (
207+ "Select the stack to which you want to add the module " ,
208+ choice
209+ )
210+ const selectedChoice = choice . filter ( ( ele ) =>
211+ Object . values ( chooseStack ) . includes ( ele )
212+ )
213+ // const samResources = roverHelpers.listSAMResources(fileName, selectedChoice[0])
214+ const moduleTemplate = < IroveraddModule > await createModules ( appName , language )
215+ Object . keys ( moduleTemplate . stackDetails ) . forEach ( ( ele ) => {
216+ moduleTemplate . stackDetails [ ele ] . stackName = selectedChoice [ 0 ]
217+ } )
218+ if ( Object . keys ( template ) . length == 0 ) {
219+ template = moduleTemplate
220+ } else {
221+ template . stackDetails = {
222+ ...template . stackDetails ,
223+ ...moduleTemplate . stackDetails ,
224+ }
225+ }
226+ return template
227+ }
0 commit comments