11import * as rover from "@rover-tools/engine/dist/bin/index"
2- const rover_utilities = rover . rover_utilities
3- const rover_config = rover . rover_config
2+ const rover_helpers = rover . helpers
3+ const rover_generateSAM = rover . generateSAM
4+ const rover_addComponent = rover . addComponents
5+ const rover_addModules = rover . addModules
46import * as fs from "fs"
57import * as cliConfig from "../cli-main/cliConfig"
68import * as util from "../cli-main/util"
7- const deployment = rover . rover_deployment
9+ const deployment = rover . deployment
810import * as buildConfig from "../cli-main/buildConfig"
9- import { AnyObject } from "immer/dist/internal"
11+
12+ import {
13+ IroverInput ,
14+ IroveraddComponentInput ,
15+ IroveraddModule ,
16+ TroverCLIStackParams ,
17+ TroverCLIcurd ,
18+ IroverCLIparamModule ,
19+ IstackDetails ,
20+ IstackDetailsObject ,
21+ IroverCLIcurdObject ,
22+ TnestedComponentsObject ,
23+ IroverDeploymentConfig ,
24+ IroverDeploymentObject ,
25+ } from "./rover.types"
1026import * as child from "child_process"
1127const exec = child . execSync
1228
1329import { version } from "../package.json"
14- import { AnyArray } from "immer/dist/internal"
15- const stack_resource_Name : AnyArray = [ ]
16- let template : AnyObject = { }
1730
1831async function roverADD ( ) {
1932 const app_name = await util . inputString ( "app_name" , "" , false , "App Name" )
20- await rover_utilities . samValidate ( app_name [ "app_name" ] )
21- await rover_utilities . checkFile ( app_name [ "app_name" ] , "yes" )
33+ await rover_helpers . samValidate ( app_name [ "app_name" ] )
34+ await rover_helpers . checkFile ( app_name [ "app_name" ] , "yes" )
2235 const language = await util . languageChoice ( )
2336 const file_name = await exec (
24- " ls " + app_name [ "app_name" ] + "/" + " *.yaml "
37+ ` ls " + ${ app_name [ "app_name" ] } / *.yaml `
2538 ) . toString ( )
26- const CompStacks = await rover_utilities . checkNested ( file_name )
39+ const CompStacks = await rover_helpers . checkNested ( file_name )
2740 return {
2841 appname : app_name ,
2942 language : language ,
@@ -32,14 +45,14 @@ async function roverADD() {
3245 }
3346}
3447async function CRUDObject ( stackName : string , AppType : string ) {
35- const crud : AnyObject = { }
36- let StackParams : AnyObject = { }
37- let paramModule : AnyObject = { }
38- const obj : AnyObject = { }
48+ const crud : TroverCLIcurd = { }
49+ let StackParams : TroverCLIStackParams = { }
50+ let paramModule : IroverCLIparamModule = < IroverCLIparamModule > { }
51+ const obj : TroverCLIStackParams = { }
3952 let tempObj = { }
4053
4154 do {
42- paramModule = await util . params ( AppType )
55+ paramModule = < IroverCLIparamModule > ( < unknown > await util . params ( AppType ) )
4356 paramModule [ "res" ] [ "resourcetype" ] = "lambda"
4457 paramModule [ "res" ] [ "methods" ] . push ( "options" )
4558 crud [ paramModule . name ] = paramModule . res
@@ -49,11 +62,10 @@ async function CRUDObject(stackName: string, AppType: string) {
4962 moreStack = await util . moreStack ( "Do you want to add another API ?" )
5063 } while ( moreStack !== "No" )
5164 StackParams = { ...obj }
52-
5365 return StackParams
5466}
5567async function CustomObject ( i : number ) {
56- const customStacks : AnyObject = { }
68+ const customStacks : Record < string , Array < string > > = { }
5769 const choice = cliConfig . customizable . components
5870 const customstack_name = await util . inputString (
5971 `customStackName${ i } ` ,
@@ -65,19 +77,23 @@ async function CustomObject(i: number) {
6577 customStacks [ customstack_name [ `customStackName${ i } ` ] ] = CustomStacks . app_type
6678 return customStacks
6779}
68- async function createModules ( app_name : AnyObject , language : string ) {
69- const stack_names : AnyObject = { }
70- let customStacks : AnyObject = { }
71- const basecrud : AnyObject = { }
72- let StackParams : AnyObject = { }
80+ async function createModules (
81+ app_name : Record < string , string > ,
82+ language : string
83+ ) {
84+ const stack_names : Record < string , string > = { }
85+ let customStacks : Record < string , Array < string > > = { }
86+ const basecrud = { }
87+ let StackParams : TroverCLIStackParams = { }
7388 let moreStack : string
74- const stackname : AnyObject = { }
89+ const stackDetails : IstackDetails = { }
90+ const stackname : Record < string , string > = { }
7591 let i = 1
76- const obj : AnyObject = { }
92+ const obj : TroverCLIStackParams = { }
7793 do {
78- const AppType : string = await util . appType ( "Module Type :" )
94+ const AppType : string = < string > await util . appType ( "Module Type :" )
7995 if ( AppType !== "CustomizableModule" ) {
80- stackname [ `stackName${ i } ` ] = AppType + rover_utilities . makeid ( 5 )
96+ stackname [ `stackName${ i } ` ] = AppType + rover_helpers . makeid ( 5 )
8197 const stack_name = stackname
8298 const stackName : string = stack_name [ `stackName${ i } ` ]
8399 if ( AppType === "CRUDModule" ) {
@@ -86,7 +102,7 @@ async function createModules(app_name: AnyObject, language: string) {
86102 ...( await CRUDObject ( stackName , AppType ) ) ,
87103 }
88104 } else {
89- obj [ stackName ] = basecrud
105+ obj [ stackName ] = < Record < string , IroverCLIcurdObject > > basecrud
90106 StackParams = { ...obj , ...StackParams }
91107 }
92108 stack_names [ stack_name [ `stackName${ i } ` ] ] = AppType
@@ -96,12 +112,27 @@ async function createModules(app_name: AnyObject, language: string) {
96112 moreStack = await util . moreStack ( "Do you want to add one more modules ? " )
97113 i ++
98114 } while ( moreStack !== "No" )
99-
100- template = { ...app_name , language }
101- if ( stack_names !== null )
102- template = { ...template , Stacks : stack_names , StackParams }
103- if ( customStacks !== null )
104- template = { ...template , CustomStacks : customStacks }
115+ if ( stack_names !== null ) {
116+ Object . keys ( stack_names ) . forEach ( ( element ) => {
117+ stackDetails [ element ] = < IstackDetailsObject > { }
118+ stackDetails [ element ] [ "type" ] = stack_names [ element ]
119+ stackDetails [ element ] [ "params" ] = StackParams [ element ]
120+ stackDetails [ element ] [ "componentlist" ] = [ ]
121+ } )
122+ }
123+ if ( customStacks !== null ) {
124+ Object . keys ( customStacks ) . forEach ( ( element ) => {
125+ stackDetails [ element ] = < IstackDetailsObject > { }
126+ stackDetails [ element ] [ "type" ] = "Custom"
127+ stackDetails [ element ] [ "params" ] = { }
128+ stackDetails [ element ] [ "componentlist" ] = customStacks [ element ]
129+ } )
130+ }
131+ const template : IroverInput = {
132+ app_name : app_name [ "app_name" ] ,
133+ language,
134+ stack_details : stackDetails ,
135+ }
105136 return template
106137}
107138async function listProfiles ( ) {
@@ -110,43 +141,51 @@ async function listProfiles() {
110141 profiles . splice ( profiles . length - 1 , 1 )
111142 return profiles
112143}
113- async function run ( argv : AnyObject ) {
144+ async function run ( argv : Array < string > ) {
114145 try {
115- if ( rover_utilities . npmrootTest ( ) ) {
146+ //rover_generateSAM.generateSAM(testinput)
147+ if ( rover_helpers . npmrootTest ( ) ) {
116148 const commandError = `rover ${ argv . join (
117149 " "
118150 ) } -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`
119151 if ( argv . length === 1 ) {
120152 if ( argv . length === 1 && argv [ 0 ] === "init" ) {
121153 const editedSam = await util . confirmation ( )
122154 if ( editedSam === "create new SAM project" ) {
123- const app_name : AnyObject = await util . inputString (
155+ const app_name : Record < string , string > = await util . inputString (
124156 "app_name" ,
125157 "" ,
126158 false ,
127159 "App Name:"
128160 )
129- await rover_utilities . checkFile ( app_name [ "app_name" ] , "no" )
161+ await rover_helpers . checkFile ( app_name [ "app_name" ] , "no" )
130162 const language = await util . languageChoice ( )
131163
132- template = await createModules ( app_name , language )
133-
134- await rover_utilities . generateSAM ( { template } [ "template" ] )
164+ const template : IroverInput = await createModules (
165+ app_name ,
166+ language
167+ )
168+ await rover_generateSAM . generateSAM (
169+ < IroverInput > { template } [ "template" ]
170+ )
135171 } else if ( editedSam === "add components to existing SAM" ) {
136172 const app_name = await util . inputString (
137173 "app_name" ,
138174 "" ,
139175 false ,
140176 "App Name"
141177 )
142- await rover_utilities . checkFile ( app_name [ "app_name" ] , "yes" )
178+ let template : IroveraddComponentInput
179+ await rover_helpers . checkFile ( app_name [ "app_name" ] , "yes" )
143180 const language = await util . languageChoice ( )
144181 const file_name = await exec (
145182 "ls " + app_name [ "app_name" ] + "/" + "*.yaml "
146183 ) . toString ( )
147- const CompStacks = await rover_utilities . checkNested ( file_name )
148- const nestedComponents : AnyObject = { }
149- const choice = Object . keys ( CompStacks [ "CompStacks" ] )
184+ const CompStacks = await rover_helpers . checkNested ( file_name )
185+ const nestedComponents : TnestedComponentsObject = <
186+ TnestedComponentsObject
187+ > { }
188+ const choice = Object . keys ( CompStacks [ "compStacks" ] )
150189 let choiceLength = 0
151190 let i = 0
152191 do {
@@ -165,11 +204,15 @@ async function run(argv: AnyObject) {
165204 "components" ,
166205 componentChoice
167206 )
168- const path = CompStacks [ "CompStacks " ] [ selectedchoice [ 0 ] ]
207+ const path = CompStacks [ "compStacks " ] [ selectedchoice [ 0 ] ]
169208 nestedComponents [ selectedchoice [ 0 ] ] = {
170209 ...components ,
171210 path : path ,
172211 }
212+ console . log (
213+ "nestedComponents" ,
214+ JSON . stringify ( nestedComponents )
215+ )
173216 template = {
174217 ...app_name ,
175218 language,
@@ -179,7 +222,9 @@ async function run(argv: AnyObject) {
179222 }
180223 } else {
181224 const choice = cliConfig . customizable . components
182- const Compnents = await util . multichoice ( "components" , choice )
225+ const Compnents = < Array < string > > (
226+ await util . multichoice ( "components" , choice )
227+ )
183228 template = { ...app_name , language }
184229 if ( customStacks !== null )
185230 template = {
@@ -195,41 +240,46 @@ async function run(argv: AnyObject) {
195240
196241 i = i + 1
197242 } while ( moreStack !== "No" || choiceLength === 0 )
198- await rover_utilities . addComponents ( template )
243+ await rover_addComponent . addComponents (
244+ < IroveraddComponentInput > template
245+ )
199246 } else if ( editedSam === "add modules to existing SAM" ) {
200247 const res = await roverADD ( )
201248 const app_name = res [ "appname" ]
202249 const language = res [ "language" ]
203250 const file_name = res [ "filename" ]
204251
205- template = await createModules ( app_name , language )
252+ const template = < IroveraddModule > (
253+ await createModules ( app_name , language )
254+ )
206255 template [ "file_name" ] = file_name
207- await rover_utilities . addModules ( template )
256+ await rover_addModules . addModules ( < IroveraddModule > template )
208257 }
209258 } else if ( argv [ 0 ] === "deploy" ) {
210259 let r = await util . inputType ( "choice" , "pipeline" , "Deploy through:" )
211260 r = r [ "choice" ]
212261 if ( r === "repository and pipeline" ) {
213262 console . log ( "Work in progress..." )
214263 } else if ( r === "generate pipeline" ) {
215- await rover_utilities . samValidate ( "" )
216- const lang : string = await rover_utilities . langValue ( )
264+ await rover_helpers . samValidate ( "" )
265+ const lang : string = await rover_helpers . langValue ( )
217266 const pipeline = await util . samBuild ( lang )
218- const repoConfig = { ...pipeline }
219- template = { ...template , repoConfig }
267+ const template = { repoConfig : pipeline }
220268 const repoconfig = await Promise . resolve (
221- util . jsonCreation ( template )
269+ util . jsonCreation (
270+ < Record < string , IroverDeploymentObject > > template
271+ )
222272 )
223273 if ( repoconfig !== undefined ) {
224274 await deployment . setupRepo ( JSON . parse ( repoconfig ) [ "repoConfig" ] )
225- rover_utilities . generateRoverConfig (
275+ rover_helpers . generateRoverConfig (
226276 "" ,
227277 JSON . parse ( repoconfig ) [ "repoConfig" ] ,
228278 "rover_generate_pipeline"
229279 )
230280 }
231281 } else {
232- await rover_utilities . samValidate ( "" )
282+ await rover_helpers . samValidate ( "" )
233283 if ( fs . existsSync ( "samconfig.toml" ) ) {
234284 exec ( "rm -rf samconfig.toml" )
235285 }
@@ -251,11 +301,14 @@ async function run(argv: AnyObject) {
251301 true ,
252302 "Bucket Name(optional) :"
253303 )
254- const choice = buildConfig . samConfig . choices . deploymentregion
304+ const samConfigchoices = < Record < string , Array < string > > > (
305+ buildConfig . samConfig . choices
306+ )
307+ const choice = samConfigchoices . deploymentregion
255308 const profile = ( await util . inputType ( "AWS profile" , profiles ) ) [
256309 "AWS profile"
257310 ]
258- console . log ( profile )
311+
259312 const deploymentregion = await util . inputType (
260313 "Deployment region" ,
261314 choice
@@ -272,27 +325,18 @@ async function run(argv: AnyObject) {
272325 }
273326 const region = deploymentregion [ "Deployment region" ]
274327
275- exec (
276- "sh " +
277- rover_config . npmroot +
278- "/@rover-tools/cli/cli-main/exec.sh " +
279- file_name +
280- " " +
281- stack_name +
282- " " +
283- region +
284- " " +
285- bucketName +
286- " " +
287- profile
288- )
328+ // exec(
329+ // `sh ${rover_helpers.npmroot}/@rover -tools/cli/cli-main/exec.sh ${file_name} ${stack_name} ${region} ${bucketName} ${profile} `
330+ // )
289331
290- const configdata : AnyObject = { }
332+ const configdata : IroverDeploymentConfig = <
333+ IroverDeploymentConfig
334+ > { }
291335 configdata [ "bucket" ] = bucketName
292- configdata [ "stack name " ] = stack_name
336+ configdata [ "stack_name " ] = stack_name
293337 configdata [ "region" ] = region
294338 configdata [ "profile" ] = profile
295- rover_utilities . generateRoverConfig (
339+ rover_helpers . generateRoverConfig (
296340 "" ,
297341 configdata ,
298342 "rover_deploy_cli"
@@ -316,8 +360,7 @@ async function run(argv: AnyObject) {
316360 console . log ( "Error: " , error )
317361 }
318362}
319- export const stackNames : AnyArray = stack_resource_Name
320363let moreStack
321- let customStacks : AnyObject
364+ let customStacks : Record < string , Array < string > >
322365
323366run ( process . argv . slice ( 2 ) )
0 commit comments