Skip to content

Commit 7c4dde6

Browse files
committed
fix : Separate the helper functions
1 parent e3e761a commit 7c4dde6

File tree

2 files changed

+135
-119
lines changed

2 files changed

+135
-119
lines changed

bin/index.ts

Lines changed: 8 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ import * as cliConfig from "../src/cliConfig"
88
import * as util from "../src/util"
99
const deployment = rover.deployment
1010
import * as buildConfig from "../src/buildConfig"
11-
11+
import { createModules, roverADD, listProfiles } from "../src/helper"
1212
import {
1313
IroverInput,
1414
IroveraddComponentInput,
1515
IroveraddModule,
16-
TroverCLIStackParams,
17-
TroverCLIcurd,
18-
IroverCLIparamModule,
19-
IstackDetails,
20-
IstackDetailsObject,
21-
IroverCLIcurdObject,
2216
TnestedComponentsObject,
2317
IroverDeploymentConfig,
2418
IroverDeploymentObject,
@@ -27,120 +21,9 @@ import * as child from "child_process"
2721
const exec = child.execSync
2822

2923
import { version } from "../package.json"
30-
async function roverADD() {
31-
const app_name = await util.inputString("app_name", "", false, "App Name")
32-
await rover_helpers.samValidate(app_name["app_name"])
33-
await rover_helpers.checkFile(app_name["app_name"], "yes")
34-
const language = await util.languageChoice()
35-
const file_name = await exec(`ls ${app_name["app_name"]}/*.yaml `).toString()
36-
const CompStacks = await rover_helpers.checkNested(file_name)
37-
return {
38-
appname: app_name,
39-
language: language,
40-
filename: file_name,
41-
compstack: CompStacks,
42-
}
43-
}
44-
async function CRUDObject(stackName: string, AppType: string) {
45-
const crud: TroverCLIcurd = {}
46-
let StackParams: TroverCLIStackParams = {}
47-
let paramModule: IroverCLIparamModule = <IroverCLIparamModule>{}
48-
const obj: TroverCLIStackParams = {}
49-
let tempObj = {}
5024

51-
do {
52-
paramModule = <IroverCLIparamModule>(<unknown>await util.params(AppType))
53-
paramModule["res"]["resourcetype"] = "lambda"
54-
paramModule["res"]["methods"].push("options")
55-
crud[paramModule.name] = paramModule.res
56-
57-
obj[stackName] = crud
58-
tempObj = { ...tempObj, crud }
59-
moreStack = await util.moreStack("Do you want to add another API ?")
60-
} while (moreStack !== "No")
61-
StackParams = { ...obj }
62-
return StackParams
63-
}
64-
async function CustomObject(i: number) {
65-
const customStacks: Record<string, Array<string>> = {}
66-
const choice = cliConfig.customizable.components
67-
const customstack_name = await util.inputString(
68-
`customStackName${i}`,
69-
"",
70-
false,
71-
`Stack ${i} Name: `
72-
)
73-
const CustomStacks = await util.multichoice("app_type", choice)
74-
customStacks[customstack_name[`customStackName${i}`]] = CustomStacks.app_type
75-
return customStacks
76-
}
77-
async function createModules(
78-
app_name: Record<string, string>,
79-
language: string
80-
) {
81-
const stack_names: Record<string, string> = {}
82-
let customStacks: Record<string, Array<string>> = {}
83-
const basecrud = {}
84-
let StackParams: TroverCLIStackParams = {}
85-
let moreStack: string
86-
const stackDetails: IstackDetails = {}
87-
const stackname: Record<string, string> = {}
88-
let i = 1
89-
const obj: TroverCLIStackParams = {}
90-
do {
91-
const AppType: string = <string>await util.appType("Module Type :")
92-
if (AppType !== "CustomizableModule") {
93-
stackname[`stackName${i}`] = `${AppType} ${rover_helpers.makeid(5)}`
94-
const stack_name = stackname
95-
const stackName: string = stack_name[`stackName${i}`]
96-
if (AppType === "CRUDModule") {
97-
StackParams = {
98-
...StackParams,
99-
...(await CRUDObject(stackName, AppType)),
100-
}
101-
} else {
102-
obj[stackName] = <Record<string, IroverCLIcurdObject>>basecrud
103-
StackParams = { ...obj, ...StackParams }
104-
}
105-
stack_names[stack_name[`stackName${i}`]] = AppType
106-
} else {
107-
customStacks = { ...customStacks, ...(await CustomObject(i)) }
108-
}
109-
moreStack = await util.moreStack("Do you want to add one more modules ? ")
110-
i++
111-
} while (moreStack !== "No")
112-
if (stack_names !== null) {
113-
Object.keys(stack_names).forEach((element) => {
114-
stackDetails[element] = <IstackDetailsObject>{}
115-
stackDetails[element]["type"] = stack_names[element]
116-
stackDetails[element]["params"] = StackParams[element]
117-
stackDetails[element]["componentlist"] = []
118-
})
119-
}
120-
if (customStacks !== null) {
121-
Object.keys(customStacks).forEach((element) => {
122-
stackDetails[element] = <IstackDetailsObject>{}
123-
stackDetails[element]["type"] = "Custom"
124-
stackDetails[element]["params"] = {}
125-
stackDetails[element]["componentlist"] = customStacks[element]
126-
})
127-
}
128-
const template: IroverInput = {
129-
app_name: app_name["app_name"],
130-
language,
131-
stack_details: stackDetails,
132-
}
133-
return template
134-
}
135-
async function listProfiles() {
136-
const profiles = exec("aws configure list-profiles").toString().split("\n")
137-
if (profiles[profiles.length - 1] == "")
138-
profiles.splice(profiles.length - 1, 1)
139-
return profiles
140-
}
14125
async function run(argv: Array<string>) {
14226
try {
143-
//rover_generateSAM.generateSAM(testinput)
14427
if (rover_helpers.npmrootTest()) {
14528
const commandError = `rover ${argv.join(
14629
" "
@@ -245,7 +128,13 @@ async function run(argv: Array<string>) {
245128
const app_name = res["appname"]
246129
const language = res["language"]
247130
const file_name = res["filename"]
248-
131+
const addToExisting = await util.inputString(
132+
"addToExisting",
133+
"",
134+
false,
135+
"Add to Existing Module: "
136+
)
137+
console.log(addToExisting)
249138
const template = <IroveraddModule>(
250139
await createModules(app_name, language)
251140
)

src/helper.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import * as rover from "@rover-tools/engine/dist/bin/index"
2+
import {
3+
IroverInput,
4+
TroverCLIStackParams,
5+
TroverCLIcurd,
6+
IroverCLIparamModule,
7+
IstackDetails,
8+
IstackDetailsObject,
9+
IroverCLIcurdObject,
10+
} from "../src/rover.types"
11+
import * as child from "child_process"
12+
import * as cliConfig from "../src/cliConfig"
13+
const exec = child.execSync
14+
const rover_helpers = rover.helpers
15+
import * as util from "../src/util"
16+
let moreStack
17+
export async function roverADD() {
18+
const app_name = await util.inputString("app_name", "", false, "App Name:")
19+
await rover_helpers.samValidate(app_name["app_name"])
20+
await rover_helpers.checkFile(app_name["app_name"], "yes")
21+
const language = await util.languageChoice()
22+
const file_name = await exec(`ls ${app_name["app_name"]}/*.yaml `).toString()
23+
const CompStacks = await rover_helpers.checkNested(file_name)
24+
return {
25+
appname: app_name,
26+
language: language,
27+
filename: file_name,
28+
compstack: CompStacks,
29+
}
30+
}
31+
async function CRUDObject(stackName: string, AppType: string) {
32+
const crud: TroverCLIcurd = {}
33+
let StackParams: TroverCLIStackParams = {}
34+
let paramModule: IroverCLIparamModule = <IroverCLIparamModule>{}
35+
const obj: TroverCLIStackParams = {}
36+
let tempObj = {}
37+
38+
do {
39+
paramModule = <IroverCLIparamModule>(<unknown>await util.params(AppType))
40+
paramModule["res"]["resourcetype"] = "lambda"
41+
paramModule["res"]["methods"].push("options")
42+
crud[paramModule.name] = paramModule.res
43+
44+
obj[stackName] = crud
45+
tempObj = { ...tempObj, crud }
46+
moreStack = await util.moreStack("Do you want to add another API ?")
47+
} while (moreStack !== "No")
48+
StackParams = { ...obj }
49+
return StackParams
50+
}
51+
async function CustomObject(i: number) {
52+
const customStacks: Record<string, Array<string>> = {}
53+
const choice = cliConfig.customizable.components
54+
const customstack_name = await util.inputString(
55+
`customStackName${i}`,
56+
"",
57+
false,
58+
`Stack ${i} Name: `
59+
)
60+
const CustomStacks = await util.multichoice("app_type", choice)
61+
customStacks[customstack_name[`customStackName${i}`]] = CustomStacks.app_type
62+
return customStacks
63+
}
64+
export async function createModules(
65+
app_name: Record<string, string>,
66+
language: string
67+
) {
68+
const stack_names: Record<string, string> = {}
69+
let customStacks: Record<string, Array<string>> = {}
70+
const basecrud = {}
71+
let StackParams: TroverCLIStackParams = {}
72+
let moreStack: string
73+
const stackDetails: IstackDetails = {}
74+
const stackname: Record<string, string> = {}
75+
let i = 1
76+
const obj: TroverCLIStackParams = {}
77+
do {
78+
const AppType: string = <string>await util.appType("Module Type :")
79+
if (AppType !== "CustomizableModule") {
80+
stackname[`stackName${i}`] = `${AppType} ${rover_helpers.makeid(5)}`
81+
const stack_name = stackname
82+
const stackName: string = stack_name[`stackName${i}`]
83+
if (AppType === "CRUDModule") {
84+
StackParams = {
85+
...StackParams,
86+
...(await CRUDObject(stackName, AppType)),
87+
}
88+
} else {
89+
obj[stackName] = <Record<string, IroverCLIcurdObject>>basecrud
90+
StackParams = { ...obj, ...StackParams }
91+
}
92+
stack_names[stack_name[`stackName${i}`]] = AppType
93+
} else {
94+
customStacks = { ...customStacks, ...(await CustomObject(i)) }
95+
}
96+
moreStack = await util.moreStack("Do you want to add one more modules ? ")
97+
i++
98+
} while (moreStack !== "No")
99+
if (stack_names !== null) {
100+
Object.keys(stack_names).forEach((element) => {
101+
stackDetails[element] = <IstackDetailsObject>{}
102+
stackDetails[element]["type"] = stack_names[element]
103+
stackDetails[element]["params"] = StackParams[element]
104+
stackDetails[element]["componentlist"] = []
105+
})
106+
}
107+
if (customStacks !== null) {
108+
Object.keys(customStacks).forEach((element) => {
109+
stackDetails[element] = <IstackDetailsObject>{}
110+
stackDetails[element]["type"] = "Custom"
111+
stackDetails[element]["params"] = {}
112+
stackDetails[element]["componentlist"] = customStacks[element]
113+
})
114+
}
115+
const template: IroverInput = {
116+
app_name: app_name["app_name"],
117+
language,
118+
stack_details: stackDetails,
119+
}
120+
return template
121+
}
122+
export async function listProfiles() {
123+
const profiles = exec("aws configure list-profiles").toString().split("\n")
124+
if (profiles[profiles.length - 1] == "")
125+
profiles.splice(profiles.length - 1, 1)
126+
return profiles
127+
}

0 commit comments

Comments
 (0)