Skip to content

Commit 7dbc956

Browse files
committed
fix: added proper naming convention
1 parent b0d32fc commit 7dbc956

File tree

11 files changed

+290
-280
lines changed

11 files changed

+290
-280
lines changed

bin/index.ts

Lines changed: 17 additions & 268 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
import * as rover from "@rover-tools/engine/dist/bin/index"
22
const rover_helpers = rover.helpers
3-
const rover_generateSAM = rover.generateSAM
4-
const rover_addComponent = rover.addComponents
5-
const rover_addModules = rover.addModules
6-
import * as fs from "fs"
7-
import * as cliConfig from "../src/cliConfig"
8-
import * as util from "../src/util"
9-
const deployment = rover.deployment
10-
import * as buildConfig from "../src/buildConfig"
11-
import { createModules, roverADD, listProfiles } from "../src/helper"
123
import {
13-
IroverInput,
14-
IroveraddComponentInput,
15-
IroveraddModule,
16-
TnestedComponentsObject,
17-
IroverDeploymentConfig,
18-
IroverDeploymentObject,
19-
} from "../src/rover.types"
20-
import * as child from "child_process"
21-
const exec = child.execSync
4+
createSAMCLI,
5+
addComponentCLI,
6+
addModuleCLI,
7+
} from "../src/roverCLI/roverGenerateCLI"
8+
import { deployCLI } from "../src/roverCLI/roverDeployCLI"
9+
10+
import * as cliConfig from "../src/configs/cliConfig"
11+
import * as util from "../src/utilities/cliUtil"
2212
const test = {
2313
app_name: "dgbcom",
2414
language: "node",
@@ -27,279 +17,38 @@ const test = {
2717
}
2818
import { version } from "../package.json"
2919

30-
async function run(argv: Array<string>) {
20+
async function run(argv: Array<string>): Promise<void> {
3121
try {
3222
if (rover_helpers.npmrootTest()) {
33-
const commandError = `rover ${argv.join(
34-
" "
35-
)} -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`
23+
const commandErrors = cliConfig.commandError(argv)
3624
if (argv.length === 1) {
3725
if (argv.length === 1 && argv[0] === "init") {
3826
const editedSam = await util.confirmation()
3927
if (editedSam === "create new SAM project") {
40-
const app_name: Record<string, string> = await util.inputString(
41-
"app_name",
42-
"",
43-
false,
44-
"App Name:"
45-
)
46-
await rover_helpers.checkFile(app_name["app_name"], "no")
47-
const language = await util.languageChoice()
48-
49-
const template: IroverInput = await createModules(
50-
app_name,
51-
language,
52-
""
53-
)
54-
await rover_generateSAM.generateSAM(
55-
<IroverInput>{ template }["template"]
56-
)
28+
await createSAMCLI()
5729
} else if (editedSam === "add components to existing SAM") {
58-
const app_name = await util.inputString(
59-
"app_name",
60-
"",
61-
false,
62-
"App Name"
63-
)
64-
let template: IroveraddComponentInput
65-
await rover_helpers.checkFile(app_name["app_name"], "yes")
66-
const language = await util.languageChoice()
67-
const file_name = await exec(
68-
`ls ${app_name["app_name"]}/*.yaml `
69-
).toString()
70-
const CompStacks = await rover_helpers.checkNested(file_name)
71-
const nestedComponents: TnestedComponentsObject = <
72-
TnestedComponentsObject
73-
>{}
74-
const choice = Object.keys(CompStacks["compStacks"])
75-
let choiceLength = 0
76-
let i = 0
77-
do {
78-
const nested = CompStacks["checkNested"]
79-
choiceLength = choice.length
80-
if (nested) {
81-
const chooseStack = await util.inputType(
82-
"Select the module to which you want to add the components ",
83-
choice
84-
)
85-
const selectedchoice = choice.filter((ele) =>
86-
Object.values(chooseStack).includes(ele)
87-
)
88-
const componentChoice = cliConfig.customizable.components
89-
const components = await util.multichoice(
90-
"components",
91-
componentChoice,
92-
""
93-
)
94-
const path = CompStacks["compStacks"][selectedchoice[0]]
95-
nestedComponents[selectedchoice[0]] = {
96-
...components,
97-
path: path,
98-
}
99-
100-
template = {
101-
...app_name,
102-
language,
103-
nested,
104-
file_name,
105-
nestedComponents,
106-
}
107-
} else {
108-
const choice = cliConfig.customizable.components
109-
choiceLength = 0
110-
const Compnents = <Array<string>>(
111-
await util.multichoice("components", choice, "")
112-
)
113-
template = { ...app_name, language }
114-
if (customStacks !== null)
115-
template = {
116-
...template,
117-
file_name,
118-
...Compnents,
119-
}
120-
}
121-
122-
moreStack = await util.moreStack(
123-
"Do you want to add one more components to modules ?"
124-
)
125-
console.log(moreStack)
126-
i = i + 1
127-
} while (moreStack !== "No" && choiceLength === 0)
128-
console.log(JSON.stringify(template))
129-
await rover_addComponent.addComponents(
130-
<IroveraddComponentInput>template
131-
)
30+
await addComponentCLI()
13231
} else if (editedSam === "add modules to existing SAM") {
133-
const res = await roverADD()
134-
let template: IroveraddModule = <IroveraddModule>{}
135-
const app_name = res["appname"]
136-
const language = res["language"]
137-
const file_name = res["filename"]
138-
const addToExisting = await util.multichoice(
139-
"addToExisting",
140-
["Yes", "No"],
141-
"Do you want to Add a module to existing Module :"
142-
)
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-
}
194-
template["file_name"] = file_name
195-
await rover_addModules.addModules(<IroveraddModule>template)
32+
await addModuleCLI()
19633
}
19734
} else if (argv[0] === "deploy") {
198-
let r = await util.inputType("choice", "pipeline", "Deploy through:")
199-
r = r["choice"]
200-
if (r === "repository and pipeline") {
201-
console.log("Work in progress...")
202-
} else if (r === "generate pipeline") {
203-
await rover_helpers.samValidate("")
204-
const lang: string = await rover_helpers.langValue()
205-
const pipeline = await util.samBuild(lang)
206-
const template = { repoConfig: pipeline }
207-
const repoconfig = await Promise.resolve(
208-
util.jsonCreation(
209-
<Record<string, IroverDeploymentObject>>template
210-
)
211-
)
212-
if (repoconfig !== undefined) {
213-
await deployment.setupRepo(JSON.parse(repoconfig)["repoConfig"])
214-
rover_helpers.generateRoverConfig(
215-
"",
216-
JSON.parse(repoconfig)["repoConfig"],
217-
"rover_generate_pipeline"
218-
)
219-
}
220-
} else {
221-
await rover_helpers.samValidate("")
222-
if (fs.existsSync("samconfig.toml")) {
223-
exec("rm -rf samconfig.toml")
224-
}
225-
const profiles = await listProfiles()
226-
const filenamearray = exec("pwd").toString().split("/")
227-
const file_name = filenamearray[filenamearray.length - 1].replace(
228-
"\n",
229-
""
230-
)
231-
let stack_name = await util.inputString(
232-
"stack_name",
233-
"",
234-
true,
235-
"Stack Name(optional) :"
236-
)
237-
let bucketName = await util.inputString(
238-
"name",
239-
"",
240-
true,
241-
"Bucket Name(optional) :"
242-
)
243-
const samConfigchoices = <Record<string, Array<string>>>(
244-
buildConfig.samConfig.choices
245-
)
246-
const choice = samConfigchoices.deploymentregion
247-
const profile = (await util.inputType("AWS profile", profiles))[
248-
"AWS profile"
249-
]
250-
251-
const deploymentregion = await util.inputType(
252-
"Deployment region",
253-
choice
254-
)
255-
if (bucketName["name"] == "") {
256-
bucketName = " --resolve-s3 "
257-
} else {
258-
bucketName = ` --s3-bucket ${bucketName["name"]}`
259-
}
260-
if (stack_name["stack_name"] == "") {
261-
stack_name = `${file_name} roverTest`
262-
} else {
263-
stack_name = stack_name["stack_name"]
264-
}
265-
const region = deploymentregion["Deployment region"]
266-
267-
exec(
268-
`sh ${rover_helpers.npmroot}/@rover-tools/cli/cli-main/exec.sh ${file_name} ${stack_name} ${region} ${bucketName} ${profile} `
269-
)
270-
271-
const configdata: IroverDeploymentConfig = <
272-
IroverDeploymentConfig
273-
>{}
274-
configdata["bucket"] = bucketName
275-
configdata["stack_name"] = stack_name
276-
configdata["region"] = region
277-
configdata["profile"] = profile
278-
rover_helpers.generateRoverConfig(
279-
"",
280-
configdata,
281-
"rover_deploy_cli"
282-
)
283-
}
35+
await deployCLI()
28436
} else if (argv[0] === "-v" || argv[0] === "--version") {
28537
// show current package version in the console
28638
console.log(version)
28739
} else {
288-
console.log(commandError)
40+
console.log(commandErrors)
28941
}
29042
} else {
291-
console.log(commandError)
43+
console.log(commandErrors)
29244
}
29345
} else {
29446
console.log(
29547
"Note: install @rover-tools/cli globally (install @rover-tools/cli -g)"
29648
)
29749
}
29850
} catch (error) {
299-
console.log("Error: ", error)
51+
console.log("Error: ", (error as Error).message)
30052
}
30153
}
302-
let moreStack
303-
let customStacks: Record<string, Array<string>>
304-
30554
run(process.argv.slice(2))

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@iarna/toml": "^2.2.5",
1616
"@rover-tools/engine": "file:../rover-engine",
1717
"@types/inquirer": "^8.2.1",
18+
"dotenv": "^16.0.3",
1819
"eslint-config-prettier": "^8.5.0",
1920
"esm": "^3.2.25",
2021
"inquirer": "^8.2.4",
@@ -34,10 +35,10 @@
3435
"start": "tsc bin/init.ts && tsc bin/index.ts && npm install -g . ",
3536
"build": "tsc && npm run format:write && npm run lint:fix",
3637
"watch": "tsc --watch",
37-
"localtest": "npm install rover-engine && npm run build && npm install rover-cli -g ",
38+
"localtest": "npm install $(grep rover_engine .env | cut -d '=' -f2 | tr -d '\"' ) && npm run build && npm install $(grep rover_cli .env | cut -d '=' -f2 | tr -d '\"') -g ",
3839
"prepack": "npm run clean && npm run build ",
3940
"format:check": "prettier --check .",
40-
"format:write": "prettier --write .",
41+
"format:write": "prettier --write src/* bin/*",
4142
"lint:check": "eslint . ",
4243
"lint:fix": "eslint --fix ."
4344
},
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { Iroverdescription } from "./rover.types"
1+
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-
5+
export const commandError = (argv: Array<string>) => {
6+
return `rover ${argv.join(
7+
" "
8+
)} -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`
9+
}
610
export const LanguageSupport = {
711
node: {
812
version: "nodejs14.x",

0 commit comments

Comments
 (0)