Skip to content

Commit 85d1108

Browse files
committed
fix: bug fix as per sonar cloud
1 parent 9280f4b commit 85d1108

File tree

8 files changed

+29
-45
lines changed

8 files changed

+29
-45
lines changed

bin/index.ts

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,34 @@ import { deployCLI } from "../src/roverCLI/roverDeployCLI"
99

1010
import * as cliConfig from "../src/configs/cliConfig"
1111
import * as util from "../src/utilities/cliUtil"
12-
const test = {
13-
app_name: "dgbcom",
14-
language: "node",
15-
file_name: "dgbcom/template.yaml\n",
16-
components: ["S3 Lambda", "CRUD API", "S3 Bucket", "Lambda", "DynamoDB"],
17-
}
12+
1813
import { version } from "../package.json"
1914

2015
async function run(argv: Array<string>): Promise<void> {
2116
try {
2217
if (rover_helpers.npmrootTest()) {
23-
const commandErrors = cliConfig.commandError(argv)
24-
if (argv.length === 1) {
25-
if (argv.length === 1 && argv[0] === "init") {
26-
const editedSam = await util.confirmation()
27-
if (editedSam === "create new SAM project") {
28-
await createSAMCLI()
29-
} else if (editedSam === "add components to existing SAM") {
30-
await addComponentCLI()
31-
} else if (editedSam === "add modules to existing SAM") {
32-
await addModuleCLI()
33-
}
34-
} else if (argv[0] === "deploy") {
35-
await deployCLI()
36-
} else if (argv[0] === "-v" || argv[0] === "--version") {
37-
// show current package version in the console
38-
console.log(version)
39-
} else {
40-
console.log(commandErrors)
41-
}
42-
} else {
43-
console.log(commandErrors)
18+
throw new Error(cliConfig.globalError)
19+
}
20+
const commandErrors = cliConfig.commandError(argv)
21+
if (argv.length !== 1) {
22+
throw new Error(commandErrors)
23+
}
24+
if (argv[0] === "init") {
25+
const editedSam = await util.confirmation()
26+
if (editedSam === "create new SAM project") {
27+
await createSAMCLI()
28+
} else if (editedSam === "add components to existing SAM") {
29+
await addComponentCLI()
30+
} else if (editedSam === "add modules to existing SAM") {
31+
await addModuleCLI()
4432
}
33+
} else if (argv[0] === "deploy") {
34+
await deployCLI()
35+
} else if (argv[0] === "-v" || argv[0] === "--version") {
36+
// show current package version in the console
37+
console.log(version)
4538
} else {
46-
console.log(
47-
"Note: install @rover-tools/cli globally (install @rover-tools/cli -g)"
48-
)
39+
console.log(commandErrors)
4940
}
5041
} catch (error) {
5142
console.log("Error: ", (error as Error).message)
File renamed without changes.

src/configs/cliConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Iroverdescription } from "../rover.types"
22
import * as rover from "@rover-tools/engine/dist/bin/index"
33
const rovercomponents = rover.components
44
const Stack = rover.modules
5+
export const globalError =
6+
"Note: install @rover-tools/cli globally (install @rover-tools/cli -g)"
57
export const commandError = (argv: Array<string>) => {
68
return `rover ${argv.join(
79
" "

src/roverCLI/roverDeployCLI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function deployCLI() {
7070
const region = deploymentregion["Deployment region"]
7171

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

7676
const configdata: IroverDeploymentConfig = <IroverDeploymentConfig>{}

src/roverCLI/roverGenerateCLI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function createSAMCLI(): Promise<void> {
2727
await rover_helpers.checkFile(app_name["app_name"], "no")
2828
const language = await util.languageChoice()
2929

30-
const template: IroverInput = await createModules(app_name, language, "")
30+
const template: IroverInput = await createModules(app_name, language)
3131
await rover_generateSAM.generateSAM({ template }["template"])
3232
}
3333
export async function addComponentCLI() {
@@ -121,7 +121,7 @@ export async function addModuleCLI() {
121121
)
122122
console.log(samResources)
123123
const moduletemplate = <IroveraddModule>(
124-
await createModules(app_name, language, "")
124+
await createModules(app_name, language)
125125
)
126126
if (Object.keys(template).length == 0) {
127127
template = moduletemplate
@@ -155,7 +155,7 @@ export async function addModuleCLI() {
155155
i = i + 1
156156
} while (moreStack !== "No")
157157
} else {
158-
template = <IroveraddModule>await createModules(app_name, language, "")
158+
template = <IroveraddModule>await createModules(app_name, language)
159159
}
160160
template["file_name"] = file_name
161161
console.log(JSON.stringify(template))

src/scripts/localtest.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/utilities/cliUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export const samBuild = async function (lang: string) {
291291
)
292292
const framework = { framework: "sam" }
293293

294-
let result: IroverDeploymentObject = {
294+
const result: IroverDeploymentObject = {
295295
...sam,
296296
...langs,
297297
no_of_env,

src/utilities/helper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ async function CustomObject(i: number) {
6363
}
6464
export async function createModules(
6565
app_name: Record<string, string>,
66-
language: string,
67-
stackName: string
66+
language: string
6867
) {
6968
const stack_names: Record<string, string> = {}
7069
let customStacks: Record<string, Array<string>> = {}

0 commit comments

Comments
 (0)