@@ -16,24 +16,45 @@ let stack_resource_Name: any = [];
1616let AppType ;
1717let template = { } ;
1818let config ;
19- async function run ( argv : AnyObject ) {
20- try {
21- if ( rover_utilities . npmrootTest ( ) ) {
22- const commandError = `rover ${ argv . join (
23- " "
24- ) } -is not a rover command \n rover init - creates new SAM project \n rover deploy - deploys SAM project`;
25- if ( argv . length === 1 ) {
26- if ( argv . length === 1 && argv [ 0 ] === "init" ) {
27- let editedSam = await util . confirmation ( ) ;
28- if ( editedSam === "create new SAM project" ) {
29- let app_name : object = await util . inputString (
30- "app_name" ,
31- "" ,
32- false ,
33- "App Name:"
34- ) ;
35- await rover_utilities . checkFile ( app_name [ "app_name" ] , "no" ) ;
36- let language = await util . languageChoice ( ) ;
19+ async function roverADD ( ) {
20+ let app_name = await util . inputString ( "app_name" , "" , false , "App Name" ) ;
21+ await rover_utilities . samValidate ( app_name [ "app_name" ] ) ;
22+ await rover_utilities . checkFile ( app_name [ "app_name" ] , "yes" ) ;
23+ let language = await util . languageChoice ( ) ;
24+ let file_name = await exec ( "ls " + app_name [ "app_name" ] + "/" + "*.yaml " ) . toString ( ) ;
25+ let CompStacks = await rover_utilities . checkNested ( file_name ) ;
26+ return { "appname" : app_name , "language" : language , "filename" : file_name , "compstack" :CompStacks }
27+ }
28+ async function CRUDObject ( stackName , AppType ) {
29+ let crud : AnyObject = { } ;
30+ let StackParams : AnyObject = { } ;
31+ let paramModule : AnyObject = { } ;
32+ let obj : AnyObject = { } ;
33+ let tempObj = { } ;
34+
35+ do {
36+ paramModule = await util . params ( AppType ) ;
37+ paramModule [ "res" ] [ "resourcetype" ] = "lambda" ;
38+ paramModule [ "res" ] [ "methods" ] . push ( "options" ) ;
39+ crud [ paramModule . name ] = paramModule . res ;
40+
41+ obj [ stackName ] = crud ;
42+ tempObj = { ...tempObj , crud } ;
43+ moreStack = await util . moreStack ( "Do you want to add another API ?" ) ;
44+ } while ( moreStack !== "No" ) ;
45+ StackParams = { ...obj } ;
46+
47+ return StackParams
48+ }
49+ async function CustomObject ( i ) {
50+ let customStacks : any = { } ;
51+ let choice = cliConfig . customizable . components ;
52+ let customstack_name = await util . inputString ( `customStackName${ i } ` , "" , false , `Stack ${ i } Name: ` ) ;
53+ let CustomStacks = await util . multichoice ( "app_type" , choice ) ;
54+ customStacks [ customstack_name [ `customStackName${ i } ` ] ] = CustomStacks . app_type ;
55+ return customStacks
56+ }
57+ async function createModules ( app_name , language ) {
3758 let stack_names : any = { } ;
3859 let customStacks : any = { } ;
3960 let paramModule : AnyObject = { } ;
@@ -46,95 +67,76 @@ async function run(argv: AnyObject) {
4667 do {
4768 let app_Types : any = [ ] ;
4869 let AppType : string = await util . appType ( "Module Type :" ) ;
49-
5070 if ( AppType !== "Customizable" ) {
51- stackname [ `stackName${ i } ` ] =
52- "rover" + rover_utilities . NumtoAlpabet ( i ) ;
53- let stack_name = stackname ;
54- let stackName : string = stack_name [ `stackName${ i } ` ] ;
55-
56- if ( AppType === "CRUD" ) {
57- let crud : AnyObject = { } ;
58- let tempObj = { } ;
59- do {
71+ stackname [ `stackName${ i } ` ] = "rover" + rover_utilities . makeid ( 5 ) ;
72+ let stack_name = stackname ;
73+ let stackName : string = stack_name [ `stackName${ i } ` ] ;
74+ if ( AppType === "CRUD" ) {
75+ StackParams = { ...StackParams , ... await CRUDObject ( stackName , AppType ) } ;
76+ } else {
6077 paramModule = await util . params ( AppType ) ;
61- paramModule [ "res" ] [ "resourcetype" ] = "lambda" ;
62- paramModule [ "res" ] [ "methods" ] . push ( "options" ) ;
63- crud [ paramModule . name ] = paramModule . res ;
64-
65- obj [ stackName ] = crud ;
66- tempObj = { ...tempObj , crud } ;
67- moreStack = await util . moreStack (
68- "Do you want to add another API ?"
69- ) ;
70- } while ( moreStack !== "No" ) ;
71-
72- StackParams = { ...obj } ;
73- } else {
74- paramModule = await util . params ( AppType ) ;
75- obj [ stackName ] = basecrud ;
76- StackParams = { ...obj } ;
77- }
78-
79- stack_names [ stack_name [ `stackName${ i } ` ] ] = AppType ;
78+ obj [ stackName ] = basecrud ;
79+ StackParams = { ...obj } ;
80+ }
81+ stack_names [ stack_name [ `stackName${ i } ` ] ] = AppType ;
8082 } else {
81- let choice = cliConfig . customizable . choice ;
82- let customstack_name = await util . inputString (
83- `customStackName${ i } ` ,
84- "" ,
85- false ,
86- `Stack ${ i } Name: `
87- ) ;
88- let CustomStacks = await util . multichoice ( "app_type" , choice ) ;
89- customStacks [ customstack_name [ `customStackName${ i } ` ] ] =
90- CustomStacks . app_type ;
83+ customStacks = { ...customStacks , ... await CustomObject ( i ) }
9184 }
9285 moreStack = await util . moreStack (
9386 "Do you want to add one more modules ? "
9487 ) ;
9588 i ++ ;
9689 } while ( moreStack !== "No" ) ;
97- {
90+
9891 template = { ...app_name , language } ;
9992 if ( stack_names !== null )
10093 template = { ...template , Stacks : stack_names , StackParams } ;
10194 if ( customStacks !== null )
10295 template = { ...template , CustomStacks : customStacks } ;
103- await rover_utilities . generationSAM ( { template } [ "template" ] ) ;
104- }
105- } else if ( editedSam === "add components to existing SAM" ) {
106- let app_name = await util . inputString (
96+ return template
97+
98+ }
99+ async function run ( argv : AnyObject ) {
100+ try {
101+ if ( rover_utilities . npmrootTest ( ) ) {
102+ const commandError = `rover ${ argv . join (
103+ " "
104+ ) } -is not a rover command \n rover init - creates new SAM project \n rover deploy - deploys SAM project\n rover -v or rover --version - gives installed rover version` ;
105+ if ( argv . length === 1 ) {
106+ if ( argv . length === 1 && argv [ 0 ] === "init" ) {
107+ let editedSam = await util . confirmation ( ) ;
108+ if ( editedSam === "create new SAM project" ) {
109+ let app_name : object = await util . inputString (
107110 "app_name" ,
108111 "" ,
109112 false ,
110- "App Name"
113+ "App Name: "
111114 ) ;
112- await rover_utilities . checkFile ( app_name [ "app_name" ] , "yes" ) ;
115+ await rover_utilities . checkFile ( app_name [ "app_name" ] , "no" ) ;
116+ let language = await util . languageChoice ( ) ;
117+
118+ template = await createModules ( app_name , language )
119+ await rover_utilities . generateSAM ( { template } [ "template" ] ) ;
120+
121+ } else if ( editedSam === "add components to existing SAM" ) {
113122
123+ let app_name = await util . inputString ( "app_name" , "" , false , "App Name" ) ;
124+ await rover_utilities . checkFile ( app_name [ "app_name" ] , "yes" ) ;
114125 let language = await util . languageChoice ( ) ;
115- let file_name = await exec (
116- "ls " + app_name [ "app_name" ] + "/" + "*.yaml "
117- ) . toString ( ) ;
126+ let file_name = await exec ( "ls " + app_name [ "app_name" ] + "/" + "*.yaml " ) . toString ( ) ;
118127 let CompStacks = await rover_utilities . checkNested ( file_name ) ;
119128 let nestedComponents : AnyObject = { } ;
120129 let choice = Object . keys ( CompStacks [ "CompStacks" ] ) ;
121130 let choiceLength = 0 ;
131+
122132 do {
123133 let nested = CompStacks [ "checkNested" ] ;
124134 choiceLength = choice . length ;
125135 if ( nested ) {
126- let chooseStack = await util . inputType (
127- "Select the module to which you want to add the components " ,
128- choice
129- ) ;
130- let selectedchoice = choice . filter ( ( ele ) =>
131- Object . values ( chooseStack ) . includes ( ele )
132- ) ;
133- let componentChoice = cliConfig . customizable . choice ;
134- let components = await util . multichoice (
135- "type" ,
136- componentChoice
137- ) ;
136+ let chooseStack = await util . inputType ( "Select the module to which you want to add the components " , choice ) ;
137+ let selectedchoice = choice . filter ( ( ele ) => Object . values ( chooseStack ) . includes ( ele ) ) ;
138+ let componentChoice = cliConfig . customizable . components ;
139+ let components = await util . multichoice ( "components" , componentChoice ) ;
138140 let path = CompStacks [ "CompStacks" ] [ selectedchoice [ 0 ] ] ;
139141 nestedComponents [ selectedchoice [ 0 ] ] = {
140142 ...components ,
@@ -148,7 +150,7 @@ async function run(argv: AnyObject) {
148150 nestedComponents
149151 } ;
150152 } else {
151- let choice = cliConfig . customizable . choice ;
153+ let choice = cliConfig . customizable . components ;
152154 let Compnents = await util . multichoice ( "components" , choice ) ;
153155 template = { ...app_name , language } ;
154156 if ( customStacks !== null )
@@ -158,26 +160,33 @@ async function run(argv: AnyObject) {
158160 ...Compnents
159161 } ;
160162 }
161-
163+
162164 moreStack = await util . moreStack (
163165 "Do you want to add one more components to modules ?"
164166 ) ;
165- console . log ( moreStack ) ;
167+
166168 i ++ ;
167169 } while ( moreStack !== "No" || choiceLength === 0 ) ;
168-
169170 await rover_utilities . addComponents ( template ) ;
170171 } else if ( editedSam === "add modules to existing SAM" ) {
171- console . log ( "Work in progress..." ) ;
172+ let res = await roverADD ( )
173+ let app_name = res [ "appname" ]
174+ let language = res [ "language" ]
175+ let file_name = res [ "filename" ]
176+ let CompStacks = res [ "compstack" ]
177+
178+ template = await createModules ( app_name , language )
179+ template [ "file_name" ] = file_name
180+ await rover_utilities . addModules ( template ) ;
172181 }
173182 } else if ( argv [ 0 ] === "deploy" ) {
174183 let r = await util . inputType ( "choice" , "pipeline" , "Deploy through:" ) ;
175184 r = r [ "choice" ] ;
176185 if ( r === "repository and pipeline" ) {
177186 console . log ( "Work in progress..." ) ;
178187 } else if ( r === "generate pipeline" ) {
179- await util . samValidate ( ) ;
180- let lang : string = await util . langValue ( ) ;
188+ await rover_utilities . samValidate ( undefined ) ;
189+ let lang : string = await rover_utilities . langValue ( ) ;
181190 let pipeline = await util . samBuild ( lang ) ;
182191 let repoConfig = { ...pipeline } ;
183192 template = { ...template , repoConfig } ;
@@ -186,7 +195,7 @@ async function run(argv: AnyObject) {
186195 await deployment . setupRepo ( JSON . parse ( repoconfig ) [ "repoConfig" ] ) ;
187196 }
188197 } else {
189- await util . samValidate ( ) ;
198+ await rover_utilities . samValidate ( undefined ) ;
190199 if ( fs . existsSync ( "samconfig.toml" ) ) {
191200 exec ( "rm -rf samconfig.toml" ) ;
192201 }
@@ -255,7 +264,6 @@ async function run(argv: AnyObject) {
255264 console . log ( "Error: " , error . message ) ;
256265 }
257266}
258-
259267export let stackNames : any = stack_resource_Name ;
260268let moreStack ;
261269let customStacks : AnyObject ;
0 commit comments