Skip to content

Commit 85485c8

Browse files
committed
fix: sonar cloud bugs and compelexity
1 parent 901e8cb commit 85485c8

File tree

5 files changed

+120
-51
lines changed

5 files changed

+120
-51
lines changed

src/rover.types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface IstackDetails {
1414
[key: string]: IstackDetailsObject
1515
}
1616
export interface IroverInput {
17-
app_name: string
17+
appName: string
1818
language: string
1919
stackDetails: IstackDetails
2020
}
@@ -36,13 +36,13 @@ export interface IroverConfigTagArrayValue {
3636
export interface IroveraddComponentInputNestedType
3737
extends Omit<IroverInput, "stackDetails"> {
3838
nested: boolean
39-
file_name: string
39+
fileName: string
4040
nestedComponents: nestedComponentsObject
4141
}
4242
export interface IroveraddComponentInputType
4343
extends Omit<IroverInput, "stackDetails"> {
4444
nested: boolean
45-
file_name: string
45+
fileName: string
4646
components: Array<string>
4747
}
4848

@@ -58,7 +58,7 @@ interface IroverComponentInputObject {
5858
type nestedComponentsObject = Record<string, IroverComponentInputObject>
5959

6060
export interface IroveraddModule extends IroverInput {
61-
file_name: string
61+
fileName: string
6262
}
6363

6464
export interface IroverCLIcurdObject {
@@ -95,7 +95,7 @@ export interface Iroverdescription {
9595
value: string
9696
}
9797
export interface IroverDeploymentObject {
98-
app_name?: string
98+
appName?: string
9999
name?: string
100100
repoType: string
101101
tool: string

src/roverCLI/roverDeployCLI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function deployCLI() {
3636
}
3737
const profiles = await listProfiles()
3838
const filenamearray = exec("pwd").toString().split("/")
39-
const file_name = filenamearray[filenamearray.length - 1].replace("\n", "")
39+
const fileName = filenamearray[filenamearray.length - 1].replace("\n", "")
4040
let stack_name = await util.inputString(
4141
"stack_name",
4242
"",
@@ -63,14 +63,14 @@ export async function deployCLI() {
6363
bucketName = ` --s3-bucket ${bucketName["name"]}`
6464
}
6565
if (stack_name["stack_name"] == "") {
66-
stack_name = `${file_name} roverTest`
66+
stack_name = `${fileName} roverTest`
6767
} else {
6868
stack_name = stack_name["stack_name"]
6969
}
7070
const region = deploymentregion["Deployment region"]
7171

7272
exec(
73-
`sh ${roverHelpers.npmroot}/@rover-tools/cli/scripts/exec.sh ${file_name} ${stack_name} ${region} ${bucketName} ${profile} `
73+
`sh ${roverHelpers.npmroot}/@rover-tools/cli/scripts/exec.sh ${fileName} ${stack_name} ${region} ${bucketName} ${profile} `
7474
)
7575

7676
const configdata: IroverDeploymentConfig = <IroverDeploymentConfig>{}

src/roverCLI/roverGenerateCLI.ts

Lines changed: 94 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ import {
1515
} from "../rover.types"
1616
import * as child from "child_process"
1717
const exec = child.execSync
18-
let moreStack
18+
let moreStacks
1919
let customStacks: Record<string, Array<string>>
2020

2121
export async function createSAMCLI(): Promise<void> {
22-
const app_name: Record<string, string> = await util.inputString(
23-
"app_name",
22+
const appName: Record<string, string> = await util.inputString(
23+
"appName",
2424
"",
2525
false,
2626
"App Name:"
2727
)
28-
await roverHelpers.checkFile(app_name["app_name"], "no")
28+
await roverHelpers.checkFile(appName["appName"], "no")
2929
const language = await util.languageChoice()
3030

31-
const template: IroverInput = await createModules(app_name, language)
31+
const template: IroverInput = await createModules(appName, language)
3232
await rover_generateSAM.generateSAM({ template }["template"])
3333
}
3434
export async function addComponentCLI() {
35-
const app_name = await util.inputString("app_name", "", false, "App Name")
35+
const appName = await util.inputString("appName", "", false, "App Name")
3636
let template: IroveraddComponentInput
37-
await roverHelpers.checkFile(app_name["app_name"], "yes")
37+
await roverHelpers.checkFile(appName["appName"], "yes")
3838
const language = await util.languageChoice()
39-
const file_name = await exec(`ls ${app_name["app_name"]}/*.yaml `).toString()
40-
const CompStacks = await roverHelpers.checkNested(file_name)
39+
const fileName = await exec(`ls ${appName["appName"]}/*.yaml `).toString()
40+
const CompStacks = await roverHelpers.checkNested(fileName)
4141
const nestedComponents: TnestedComponentsObject = <TnestedComponentsObject>{}
4242
const choice = Object.keys(CompStacks["compStacks"])
4343
let i = 0
@@ -64,45 +64,45 @@ export async function addComponentCLI() {
6464
}
6565

6666
template = {
67-
...app_name,
67+
...appName,
6868
language,
6969
nested,
70-
file_name,
70+
fileName,
7171
nestedComponents,
7272
}
7373
} else {
7474
const choice = cliConfig.customizable.components
7575
const Compnents = <Array<string>>(
7676
await util.multichoice("components", choice, "")
7777
)
78-
template = { ...app_name, language }
78+
template = { ...appName, language }
7979
if (customStacks !== null)
8080
template = {
8181
...template,
82-
file_name,
82+
fileName,
8383
...Compnents,
8484
}
8585
}
86-
moreStack = await util.moreStack(
86+
moreStacks = await util.choicesYorN(
8787
"Do you want to add one more components to modules ?"
8888
)
8989
i = i + 1
90-
} while (moreStack !== "No")
90+
} while (moreStacks !== "No")
9191
await rover_addComponent.addComponents(template)
9292
}
93-
export async function addModuleCLI(): Promise<void> {
93+
export async function addModuleCLIs(): Promise<void> {
9494
const res = await roverADD()
9595
let template: IroveraddModule = <IroveraddModule>{}
96-
const app_name = res["appname"]
96+
const appName = res["appName"]
9797
const language = res["language"]
98-
const file_name = res["filename"]
98+
const fileName = res["filename"]
9999
const addToExisting = await util.multichoice(
100100
"addToExisting",
101101
["Yes", "No"],
102102
"Do you want to Add a module to existing Module :"
103103
)
104104
if (addToExisting.addToExisting[0] == "Yes") {
105-
const CompStacks = await roverHelpers.checkNested(file_name)
105+
const CompStacks = await roverHelpers.checkNested(fileName)
106106
const choice = Object.keys(CompStacks["compStacks"])
107107
let i = 0
108108
do {
@@ -116,11 +116,11 @@ export async function addModuleCLI(): Promise<void> {
116116
Object.values(chooseStack).includes(ele)
117117
)
118118
// const samResources = roverHelpers.listSAMResources(
119-
// file_name,
119+
// fileName,
120120
// selectedChoice[0]
121121
// )
122122
const moduletemplate = <IroveraddModule>(
123-
await createModules(app_name, language)
123+
await createModules(appName, language)
124124
)
125125
Object.keys(moduletemplate.stackDetails).forEach((ele) => {
126126
moduletemplate.stackDetails[ele].stackName = selectedChoice[0]
@@ -138,23 +138,90 @@ export async function addModuleCLI(): Promise<void> {
138138
const Compnents = <Array<string>>(
139139
await util.multichoice("components", choice, "")
140140
)
141-
template = { ...app_name, language }
141+
template = { ...appName, language }
142142
if (customStacks !== null)
143143
template = {
144144
...template,
145145
...Compnents,
146146
}
147147
}
148-
moreStack = await util.moreStack(
148+
moreStacks = await util.choicesYorN(
149149
"Do you want to add one more modules to another stack ?"
150150
)
151151
i = i + 1
152-
} while (moreStack !== "No")
153-
template["file_name"] = file_name
152+
} while (moreStacks !== "No")
153+
template["fileName"] = fileName
154+
await rover_addModulesToexisting.addModulesToExistingStack(template)
155+
} else {
156+
template = <IroveraddModule>await createModules(appName, language)
157+
template["fileName"] = fileName
158+
await rover_addModules.addModules(template)
159+
}
160+
}
161+
export async function addModuleCLI(): Promise<void> {
162+
const res = await roverADD()
163+
let template: IroveraddModule = <IroveraddModule>{}
164+
const appName = res["appName"]
165+
const language = res["language"]
166+
const fileName = res["filename"]
167+
const addToExisting = await util.choicesYorN(
168+
"Do you want to Add a module to existing Module :"
169+
)
170+
if (addToExisting == "Yes") {
171+
const CompStacks = await roverHelpers.checkNested(fileName)
172+
const choice = Object.keys(CompStacks["compStacks"])
173+
do {
174+
const nested = CompStacks["checkNested"]
175+
if (nested) {
176+
template = await addModuleToStack(choice, appName, language, template)
177+
} else {
178+
const components = <Array<string>>(
179+
await util.multichoice(
180+
"components",
181+
cliConfig.customizable.components,
182+
""
183+
)
184+
)
185+
template = { ...appName, language, ...components }
186+
}
187+
moreStacks = await util.choicesYorN(
188+
"Do you want to add one more modules to another stack ?"
189+
)
190+
} while (moreStacks !== "No")
191+
template["fileName"] = fileName
154192
await rover_addModulesToexisting.addModulesToExistingStack(template)
155193
} else {
156-
template = <IroveraddModule>await createModules(app_name, language)
157-
template["file_name"] = file_name
194+
template = <IroveraddModule>await createModules(appName, language)
195+
template["fileName"] = fileName
158196
await rover_addModules.addModules(template)
159197
}
160198
}
199+
200+
async function addModuleToStack(
201+
choice: string[],
202+
appName: Record<string, string>,
203+
language: string,
204+
template: IroveraddModule
205+
) {
206+
const chooseStack = await util.inputType(
207+
"Select the stack to which you want to add the module ",
208+
choice
209+
)
210+
const selectedChoice = choice.filter((ele) =>
211+
Object.values(chooseStack).includes(ele)
212+
)
213+
// const samResources = roverHelpers.listSAMResources(fileName, selectedChoice[0])
214+
const moduleTemplate = <IroveraddModule>await createModules(appName, language)
215+
Object.keys(moduleTemplate.stackDetails).forEach((ele) => {
216+
moduleTemplate.stackDetails[ele].stackName = selectedChoice[0]
217+
})
218+
if (Object.keys(template).length == 0) {
219+
template = moduleTemplate
220+
} else {
221+
template.stackDetails = {
222+
...template.stackDetails,
223+
...moduleTemplate.stackDetails,
224+
}
225+
}
226+
return template
227+
}

src/utilities/cliUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export const appType = async function (message = "") {
328328
}
329329
}
330330
}
331-
export const moreStack = async function (message: string) {
331+
export const choicesYorN = async function (message: string) {
332332
const r = await inquirer.prompt([
333333
{
334334
type: "list",

src/utilities/helper.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import * as cliConfig from "../configs/cliConfig"
1313
const exec = child.execSync
1414
const roverHelpers = rover.helpers
1515
import * as util from "./cliUtil"
16-
let moreStack
16+
let moreStacks
1717
export async function roverADD() {
18-
const app_name = await util.inputString("app_name", "", false, "App Name:")
19-
await roverHelpers.samValidate(<string>app_name["app_name"])
20-
await roverHelpers.checkFile(<string>app_name["app_name"], "yes")
18+
const appName = await util.inputString("appName", "", false, "App Name:")
19+
await roverHelpers.samValidate(appName["appName"])
20+
await roverHelpers.checkFile(appName["appName"], "yes")
2121
const language = await util.languageChoice()
22-
const file_name = await exec(`ls ${app_name["app_name"]}/*.yaml `).toString()
23-
const CompStacks = await roverHelpers.checkNested(file_name)
22+
const fileName = await exec(`ls ${appName["appName"]}/*.yaml `).toString()
23+
const CompStacks = await roverHelpers.checkNested(fileName)
2424
return {
25-
appname: app_name,
25+
appName: appName,
2626
language: language,
27-
filename: file_name,
27+
filename: fileName,
2828
compstack: CompStacks,
2929
}
3030
}
@@ -43,8 +43,8 @@ async function CRUDObject(stackName: string, AppType: string) {
4343

4444
obj[stackName] = crud
4545
tempObj = { ...tempObj, crud }
46-
moreStack = await util.moreStack("Do you want to add another API ?")
47-
} while (moreStack !== "No")
46+
moreStacks = await util.choicesYorN("Do you want to add another API ?")
47+
} while (moreStacks !== "No")
4848
StackParams = { ...obj }
4949
return StackParams
5050
}
@@ -63,14 +63,14 @@ async function CustomObject(i: number) {
6363
return customStacks
6464
}
6565
export async function createModules(
66-
app_name: Record<string, string>,
66+
appName: Record<string, string>,
6767
language: string
6868
) {
6969
const stack_names: Record<string, string> = {}
7070
let customStacks: Record<string, Array<string>> = {}
7171
const basecrud = {}
7272
let StackParams: TroverCLIStackParams = {}
73-
let moreStack: string
73+
let moreStacks: string
7474
const stackDetails: IstackDetails = {}
7575
const stackname: Record<string, string> = {}
7676
let i = 1
@@ -94,9 +94,11 @@ export async function createModules(
9494
} else {
9595
customStacks = { ...customStacks, ...(await CustomObject(i)) }
9696
}
97-
moreStack = await util.moreStack("Do you want to add one more modules ? ")
97+
moreStacks = await util.choicesYorN(
98+
"Do you want to add one more modules ? "
99+
)
98100
i++
99-
} while (moreStack !== "No")
101+
} while (moreStacks !== "No")
100102
if (stack_names !== null) {
101103
Object.keys(stack_names).forEach((element) => {
102104
stackDetails[element] = <IstackDetailsObject>{}
@@ -114,7 +116,7 @@ export async function createModules(
114116
})
115117
}
116118
const template: IroverInput = {
117-
app_name: app_name["app_name"],
119+
appName: appName["appName"],
118120
language,
119121
stackDetails: stackDetails,
120122
}

0 commit comments

Comments
 (0)