@@ -19,7 +19,12 @@ import {
1919} from "../src/rover.types"
2020import * as child from "child_process"
2121const exec = child . execSync
22-
22+ const test = {
23+ app_name : "dgbcom" ,
24+ language : "node" ,
25+ file_name : "dgbcom/template.yaml\n" ,
26+ components : [ "S3 Lambda" , "CRUD API" , "S3 Bucket" , "Lambda" , "DynamoDB" ] ,
27+ }
2328import { version } from "../package.json"
2429
2530async function run ( argv : Array < string > ) {
@@ -43,7 +48,8 @@ async function run(argv: Array<string>) {
4348
4449 const template : IroverInput = await createModules (
4550 app_name ,
46- language
51+ language ,
52+ ""
4753 )
4854 await rover_generateSAM . generateSAM (
4955 < IroverInput > { template } [ "template" ]
@@ -82,17 +88,15 @@ async function run(argv: Array<string>) {
8288 const componentChoice = cliConfig . customizable . components
8389 const components = await util . multichoice (
8490 "components" ,
85- componentChoice
91+ componentChoice ,
92+ ""
8693 )
8794 const path = CompStacks [ "compStacks" ] [ selectedchoice [ 0 ] ]
8895 nestedComponents [ selectedchoice [ 0 ] ] = {
8996 ...components ,
9097 path : path ,
9198 }
92- console . log (
93- "nestedComponents" ,
94- JSON . stringify ( nestedComponents )
95- )
99+
96100 template = {
97101 ...app_name ,
98102 language,
@@ -102,8 +106,9 @@ async function run(argv: Array<string>) {
102106 }
103107 } else {
104108 const choice = cliConfig . customizable . components
109+ choiceLength = 0
105110 const Compnents = < Array < string > > (
106- await util . multichoice ( "components" , choice )
111+ await util . multichoice ( "components" , choice , "" )
107112 )
108113 template = { ...app_name , language }
109114 if ( customStacks !== null )
@@ -117,27 +122,75 @@ async function run(argv: Array<string>) {
117122 moreStack = await util . moreStack (
118123 "Do you want to add one more components to modules ?"
119124 )
120-
125+ console . log ( moreStack )
121126 i = i + 1
122- } while ( moreStack !== "No" || choiceLength === 0 )
127+ } while ( moreStack !== "No" && choiceLength === 0 )
128+ console . log ( JSON . stringify ( template ) )
123129 await rover_addComponent . addComponents (
124130 < IroveraddComponentInput > template
125131 )
126132 } else if ( editedSam === "add modules to existing SAM" ) {
127133 const res = await roverADD ( )
134+ let template : IroveraddModule = < IroveraddModule > { }
128135 const app_name = res [ "appname" ]
129136 const language = res [ "language" ]
130137 const file_name = res [ "filename" ]
131- const addToExisting = await util . inputString (
138+ const addToExisting = await util . multichoice (
132139 "addToExisting" ,
133- "" ,
134- false ,
135- "Add to Existing Module: "
136- )
137- console . log ( addToExisting )
138- const template = < IroveraddModule > (
139- await createModules ( app_name , language )
140+ [ "Yes" , "No" ] ,
141+ "Do you want to Add a module to existing Module :"
140142 )
143+ if ( addToExisting . addToExisting [ 0 ] == "Yes" ) {
144+ const CompStacks = await rover_helpers . checkNested ( file_name )
145+ const choice = Object . keys ( CompStacks [ "compStacks" ] )
146+ let choiceLength = 0
147+ let i = 0
148+ do {
149+ const nested = CompStacks [ "checkNested" ]
150+ choiceLength = choice . length
151+ if ( nested ) {
152+ const chooseStack = await util . inputType (
153+ "Select the stack to which you want to add the module " ,
154+ choice
155+ )
156+ const selectedchoice = choice . filter ( ( ele ) =>
157+ Object . values ( chooseStack ) . includes ( ele )
158+ )
159+ const samResources = rover_helpers . listSAMResources (
160+ file_name ,
161+ selectedchoice [ 0 ]
162+ )
163+ template = < IroveraddModule > (
164+ await createModules ( app_name , language , "" )
165+ )
166+ Object . keys ( template . stackDetails ) . forEach ( ( ele ) => {
167+ template . stackDetails [ ele ] . stackName = selectedchoice [ 0 ]
168+ } )
169+ } else {
170+ const choice = cliConfig . customizable . components
171+ const Compnents = < Array < string > > (
172+ await util . multichoice ( "components" , choice , "" )
173+ )
174+ template = { ...app_name , language }
175+ if ( customStacks !== null )
176+ template = {
177+ ...template ,
178+ file_name,
179+ ...Compnents ,
180+ }
181+ }
182+
183+ moreStack = await util . moreStack (
184+ "Do you want to add one more modules ?"
185+ )
186+
187+ i = i + 1
188+ } while ( moreStack !== "No" || choiceLength === 0 )
189+ } else {
190+ template = < IroveraddModule > (
191+ await createModules ( app_name , language , "" )
192+ )
193+ }
141194 template [ "file_name" ] = file_name
142195 await rover_addModules . addModules ( < IroveraddModule > template )
143196 }
0 commit comments