Skip to content

Commit 97b3b71

Browse files
Merge pull request #56 from antstackio/ROVGPT
Added ChatGPT support.
2 parents ec8b378 + 4fef396 commit 97b3b71

File tree

4 files changed

+67
-142
lines changed

4 files changed

+67
-142
lines changed

bin/index.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,38 @@ import {
44
createSAMCLI,
55
addComponentCLI,
66
addModuleCLI,
7+
createCustomSAMCLI,
78
} from "../src/roverCLI/roverGenerateCLI"
89
import { deployCLI } from "../src/roverCLI/roverDeployCLI"
910
import * as cliConfig from "../src/configs/cliConfig"
1011
import { version } from "../package.json"
1112
import * as util from "../src/utilities/cliUtil"
1213

13-
function handleInitCommand(): Promise<void> {
14-
return new Promise( (resolve) => {
15-
const editedSam = <string>(<unknown>util.confirmation())
16-
if ( editedSam === "create new SAM project") {
17-
createSAMCLI()
18-
} else if (editedSam === "add components to existing SAM") {
19-
addComponentCLI()
20-
} else if (editedSam === "add modules to existing SAM") {
21-
addModuleCLI()
22-
}
23-
resolve()
24-
})
14+
async function handleInitCommand() {
15+
const editedSam = <string>(<unknown>await util.confirmation())
16+
if (editedSam === "create new SAM project") {
17+
await createSAMCLI()
18+
} else if (editedSam === "create custom SAM project") {
19+
await createCustomSAMCLI()
20+
} else if (editedSam === "add components to existing SAM") {
21+
await addComponentCLI()
22+
} else if (editedSam === "add modules to existing SAM") {
23+
await addModuleCLI()
24+
} else {
25+
console.log(editedSam)
26+
throw new Error(`Unknown option ${editedSam}`)
27+
}
2528
}
2629

2730
async function handleDeployCommand(): Promise<void> {
2831
await deployCLI()
2932
}
3033

31-
function handleVersionCommand(): void {
34+
async function handleVersionCommand(): Promise<void> {
3235
console.log(version)
3336
}
3437

35-
function handleUnknownCommand(): void {
38+
async function handleUnknownCommand(): Promise<void> {
3639
console.log(cliConfig.commandError(process.argv.slice(2)))
3740
}
3841

@@ -51,14 +54,13 @@ async function run(argv: Array<string>): Promise<void> {
5154
break
5255
case "-v":
5356
case "--version":
54-
handleVersionCommand()
57+
await handleVersionCommand()
5558
break
5659
default:
57-
handleUnknownCommand()
60+
await handleUnknownCommand()
5861
}
5962
} catch (error) {
60-
console.log("Error: ", error as Error)
61-
//.message)
63+
console.log("Error: ", (error as Error).message)
6264
}
6365
}
6466

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"devDependencies": {
3-
"@types/node": "^12.12.7",
3+
"@types/node": "^12.20.55",
44
"@typescript-eslint/eslint-plugin": "^5.45.0",
55
"eslint": "^8.28.0",
66
"eslint-config-standard-with-typescript": "^23.0.0",
@@ -12,7 +12,6 @@
1212
"typescript": "^4.9.3"
1313
},
1414
"dependencies": {
15-
"@iarna/toml": "^2.2.5",
1615
"@rover-tools/engine": "file:../rover-engine",
1716
"@types/inquirer": "^8.2.1",
1817
"dotenv": "^16.0.3",

src/roverCLI/roverGenerateCLI.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const rover_addComponent = rover.addComponents
44
const rover_addModules = rover.addModules
55
const rover_generateSAM = rover.generateSAM
66
const rover_addModulesToexisting = rover.addModulesToExisting
7+
const rover_generateCustomSAM = rover.generateCustomSAM
78
import * as util from "../utilities/cliUtil"
89
import * as cliConfig from "../configs/cliConfig"
910
import { createModules, roverADD } from "../utilities/helper"
@@ -157,3 +158,22 @@ async function addModuleToStack(
157158
}
158159
return template
159160
}
161+
export async function createCustomSAMCLI() {
162+
const appName: Record<string, string> = await util.inputString(
163+
"appName",
164+
"",
165+
false,
166+
"App Name:"
167+
)
168+
const Description: Record<string, string> = await util.inputDescription(
169+
"description",
170+
"",
171+
false,
172+
"You want a SAM project to ?"
173+
)
174+
await roverHelpers.checkFile(appName["appName"], "no")
175+
await rover_generateCustomSAM.generateCustomSAM(
176+
appName["appName"],
177+
Description["description"]
178+
)
179+
}

src/utilities/cliUtil.ts

Lines changed: 26 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ export async function inputString(
8484

8585
return { ...takeInput }
8686
}
87+
export async function inputDescription(
88+
name: string,
89+
defaults: string,
90+
optional: boolean,
91+
message = ""
92+
) {
93+
const takeInput = await inquirer.prompt([
94+
{
95+
type: "input",
96+
name,
97+
message,
98+
},
99+
])
100+
101+
return { ...takeInput }
102+
}
87103

88104
export const languageChoice = async function () {
89105
const lang = await inquirer.prompt([
@@ -101,14 +117,14 @@ export const languageChoice = async function () {
101117
}
102118

103119
export const inputType = async function (
104-
userName: string,
120+
name: string,
105121
choices: Array<string> | string,
106122
message = ""
107123
) {
108124
const takeInput = await inquirer.prompt([
109125
{
110126
type: "rawlist",
111-
name: `${userName}`,
127+
name: `${name}`,
112128
message: message,
113129
choices:
114130
typeof choices === "string" ? cliConfig.app.choices[choices] : choices,
@@ -118,14 +134,15 @@ export const inputType = async function (
118134
return takeInput
119135
}
120136

121-
export const confirmation = async function ():Promise<string> {
137+
export const confirmation = async function () {
122138
const r = await inquirer.prompt([
123139
{
124140
type: "rawlist",
125141
name: "choice",
126142
message: `Hey, what do you want ?`,
127143
choices: [
128144
"create new SAM project",
145+
"create custom SAM project",
129146
"add components to existing SAM",
130147
"add modules to existing SAM",
131148
],
@@ -135,16 +152,16 @@ export const confirmation = async function ():Promise<string> {
135152
return r.choice
136153
}
137154

138-
export const inputNumber = async function (userName: string, message: string) {
139-
let displayname = userName
155+
export const inputNumber = async function (name: string, message: string) {
156+
let displayname = name
140157
if (message !== undefined) {
141158
displayname = message
142159
}
143160
const takeInput = await inquirer.prompt([
144161
{
145162
type: "input",
146163
message: `Please enter the required number of ${displayname} you want ?`,
147-
name: `${userName}`,
164+
name: `${name}`,
148165
validate: function (value) {
149166
const pass = !isNaN(value) && value > 0
150167
if (pass) {
@@ -155,7 +172,7 @@ export const inputNumber = async function (userName: string, message: string) {
155172
},
156173
])
157174

158-
return parseInt(takeInput[`${userName}`], 10)
175+
return parseInt(takeInput[`${name}`], 10)
159176
}
160177

161178
export const inputCli = async function (
@@ -184,130 +201,17 @@ export const inputCli = async function (
184201
}
185202
return res
186203
}
187-
export const password = async function (userName: string, message = "") {
204+
export const password = async function (name: string, message = "") {
188205
const r = await inquirer.prompt([
189206
{
190207
type: "password",
191208
message: message,
192-
name: userName,
209+
name: name,
193210
},
194211
])
195212
return r
196213
}
197214

198-
export const samBuilds = async function (lang: string) {
199-
try {
200-
const obj = buildConfig.samConfig
201-
const choices = <Record<string, Array<string>>>buildConfig.samConfig.choices
202-
const subObj = <Array<Record<string, string>>>buildConfig.samConfig.samBuild
203-
let sam: Record<string, Record<string, string>> = await inputCli(
204-
obj,
205-
subObj,
206-
""
207-
)
208-
const temp: Record<string, Record<string, string>> = {}
209-
Object.values(sam).forEach((ele) => {
210-
Object.assign(temp, ele)
211-
})
212-
sam = temp
213-
const langs = { language: lang }
214-
const no_of_env = await inputNumber("no_of_env", "environments")
215-
const envs: string[] = []
216-
let steps: Record<string, Array<string>> = {}
217-
let stacknames: Record<string, string> = {}
218-
const deploymentregion: Record<string, string> = {}
219-
let deploymentparameters: Record<string, string> = {}
220-
let depBucketNames: Record<string, string> = {}
221-
222-
const branches = { branches: ["main"] }
223-
for (let i = 1; i <= no_of_env; i++) {
224-
const env = await inputString(`env${i}`, "", false, `Envrionment ${i} :`)
225-
const envName = env[`env${i}`]
226-
envs.push(envName)
227-
228-
const stepsChoice = choices.dev
229-
let step = await multichoice(
230-
`steps required for ${envName} environment `,
231-
stepsChoice,
232-
""
233-
)
234-
const steps1: Record<string, Array<string>> = {}
235-
step = Object.keys(step).map((ele) => {
236-
let name: string = ele.replace("steps required for ", "")
237-
name = name.replace(" environment ", "")
238-
steps1[name] = step[ele]
239-
})
240-
241-
const stackname = await inputString(
242-
`${envName}`,
243-
"",
244-
true,
245-
246-
`Stack Name(optional) --> ${envName} :`
247-
)
248-
const deploymentbucket = await inputString(
249-
`${envName}`,
250-
"",
251-
true,
252-
`Deployment Bucket(optional) --> ${envName} :`
253-
)
254-
const regionChoice = choices.deploymentregion
255-
const deployment_region = await inputType(
256-
`${envName}`,
257-
regionChoice,
258-
"Deployment Region"
259-
)
260-
const deployment_parameter = await inputString(
261-
`${envName}`,
262-
"",
263-
true,
264-
`Deployment Parameter(optional) --> ${envName} :`
265-
)
266-
steps = { ...steps, ...steps1 }
267-
268-
stacknames = { ...stacknames, ...stackname }
269-
270-
depBucketNames = {
271-
...depBucketNames,
272-
...deploymentbucket,
273-
}
274-
deploymentregion[`${envName}`] = deployment_region[`${envName}`]
275-
deploymentparameters = {
276-
...deploymentparameters,
277-
...deployment_parameter,
278-
}
279-
}
280-
281-
const deployment_choice = choices.deployment
282-
const deploymentEvent = await multichoice(
283-
`deploymentevents`,
284-
deployment_choice,
285-
""
286-
)
287-
const framework = { framework: "sam" }
288-
289-
const result: IroverDeploymentObject = {
290-
...sam,
291-
...langs,
292-
no_of_env,
293-
envs,
294-
...branches,
295-
...framework,
296-
steps,
297-
stackname: { ...stacknames },
298-
deploymentbucket: {
299-
...depBucketNames,
300-
},
301-
deploymentregion,
302-
deploymentparameters,
303-
...deploymentEvent,
304-
}
305-
return result
306-
} catch (error) {
307-
console.log(error)
308-
}
309-
}
310-
311215
export const samBuild = async (lang: string) => {
312216
try {
313217
const { samConfig } = buildConfig

0 commit comments

Comments
 (0)