Skip to content

Commit b0d32fc

Browse files
committed
Fix: added types
1 parent 7c4dde6 commit b0d32fc

File tree

5 files changed

+103
-38
lines changed

5 files changed

+103
-38
lines changed

bin/index.ts

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
} from "../src/rover.types"
2020
import * as child from "child_process"
2121
const 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+
}
2328
import { version } from "../package.json"
2429

2530
async 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
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"start": "tsc bin/init.ts && tsc bin/index.ts && npm install -g . ",
3535
"build": "tsc && npm run format:write && npm run lint:fix",
3636
"watch": "tsc --watch",
37-
"localtest": "npm install /Users/dheerajbhatt/proj/rover-engine && npm run build && npm install /Users/dheerajbhatt/proj/rover-cli -g ",
37+
"localtest": "npm install rover-engine && npm run build && npm install rover-cli -g ",
3838
"prepack": "npm run clean && npm run build ",
3939
"format:check": "prettier --check .",
4040
"format:write": "prettier --write .",

src/helper.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ async function CustomObject(i: number) {
5757
false,
5858
`Stack ${i} Name: `
5959
)
60-
const CustomStacks = await util.multichoice("app_type", choice)
60+
const CustomStacks = await util.multichoice("app_type", choice, "")
6161
customStacks[customstack_name[`customStackName${i}`]] = CustomStacks.app_type
6262
return customStacks
6363
}
6464
export async function createModules(
6565
app_name: Record<string, string>,
66-
language: string
66+
language: string,
67+
stackName: string
6768
) {
6869
const stack_names: Record<string, string> = {}
6970
let customStacks: Record<string, Array<string>> = {}
@@ -77,7 +78,7 @@ export async function createModules(
7778
do {
7879
const AppType: string = <string>await util.appType("Module Type :")
7980
if (AppType !== "CustomizableModule") {
80-
stackname[`stackName${i}`] = `${AppType} ${rover_helpers.makeid(5)}`
81+
stackname[`stackName${i}`] = `${AppType}${rover_helpers.makeid(5)}`
8182
const stack_name = stackname
8283
const stackName: string = stack_name[`stackName${i}`]
8384
if (AppType === "CRUDModule") {
@@ -101,21 +102,21 @@ export async function createModules(
101102
stackDetails[element] = <IstackDetailsObject>{}
102103
stackDetails[element]["type"] = stack_names[element]
103104
stackDetails[element]["params"] = StackParams[element]
104-
stackDetails[element]["componentlist"] = []
105+
stackDetails[element]["componentList"] = []
105106
})
106107
}
107108
if (customStacks !== null) {
108109
Object.keys(customStacks).forEach((element) => {
109110
stackDetails[element] = <IstackDetailsObject>{}
110111
stackDetails[element]["type"] = "Custom"
111112
stackDetails[element]["params"] = {}
112-
stackDetails[element]["componentlist"] = customStacks[element]
113+
stackDetails[element]["componentList"] = customStacks[element]
113114
})
114115
}
115116
const template: IroverInput = {
116117
app_name: app_name["app_name"],
117118
language,
118-
stack_details: stackDetails,
119+
stackDetails: stackDetails,
119120
}
120121
return template
121122
}

src/rover.types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ interface curdObject {
88
export interface IstackDetailsObject {
99
type: string
1010
params: curdObject | object
11-
componentlist: Array<string>
11+
componentList: Array<string>
12+
stackName: string
1213
}
1314
export interface IstackDetails {
1415
[key: string]: IstackDetailsObject
1516
}
1617
export interface IroverInput {
1718
app_name: string
1819
language: string
19-
stack_details: IstackDetails
20+
stackDetails: IstackDetails
2021
}
2122

22-
export interface IroverAppData extends Omit<IroverInput, "stack_details"> {
23+
export interface IroverAppData extends Omit<IroverInput, "stackDetails"> {
2324
dependency: string
2425
extension: string
2526
StackType: Array<string>
@@ -34,13 +35,13 @@ export interface IroverConfigTagArrayValue {
3435
Value: string
3536
}
3637
export interface IroveraddComponentInputNestedType
37-
extends Omit<IroverInput, "stack_details"> {
38+
extends Omit<IroverInput, "stackDetails"> {
3839
nested: boolean
3940
file_name: string
4041
nestedComponents: nestedComponentsObject
4142
}
4243
export interface IroveraddComponentInputType
43-
extends Omit<IroverInput, "stack_details"> {
44+
extends Omit<IroverInput, "stackDetails"> {
4445
nested: boolean
4546
file_name: string
4647
components: Array<string>

src/util.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ const stringpattern = new RegExp(/^[A-Za-z]+$/g)
1414

1515
export const multichoice = async function (
1616
name: string,
17-
choice: Array<string>
17+
choice: Array<string>,
18+
message: string
1819
) {
19-
const messages = `Please select your ${name
20-
.charAt(0)
21-
.toUpperCase()} ${name.slice(1)} :`
20+
let messages = ""
21+
if (message == "") {
22+
messages = `Please select your ${name
23+
.charAt(0)
24+
.toUpperCase()} ${name.slice(1)} :`
25+
} else {
26+
messages = message
27+
}
28+
2229
const r = await inquirer.prompt([
2330
{
2431
type: "checkbox",
@@ -225,8 +232,9 @@ export const samBuild = async function (lang: string) {
225232

226233
const stepsChoice = choices.dev
227234
let step = await multichoice(
228-
`steps required for ${envName} environment `,
229-
stepsChoice
235+
`steps required for ${envName} environment `,
236+
stepsChoice,
237+
""
230238
)
231239
const steps1: Record<string, Array<string>> = {}
232240
step = Object.keys(step).map((ele) => {
@@ -278,7 +286,8 @@ export const samBuild = async function (lang: string) {
278286
const deployment_choice = choices.deployment
279287
const deploymentEvent = await multichoice(
280288
`deploymentevents`,
281-
deployment_choice
289+
deployment_choice,
290+
""
282291
)
283292
const framework = { framework: "sam" }
284293
let result: IroverDeploymentObject = <IroverDeploymentObject>{}
@@ -354,7 +363,8 @@ export const params = async function (module: string) {
354363
} else if (modulesParams[i].value === "multichoice") {
355364
const r = await multichoice(
356365
modulesParams[i].key,
357-
<Array<string>>choice.methods
366+
<Array<string>>choice.methods,
367+
""
358368
)
359369
res = { ...res, ...r }
360370
} else {

0 commit comments

Comments
 (0)