Skip to content

Commit f5b7931

Browse files
committed
feature: added chatgpt support
1 parent e81253e commit f5b7931

File tree

3 files changed

+57
-18
lines changed

3 files changed

+57
-18
lines changed

bin/index.ts

Lines changed: 18 additions & 16 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 = await (<string>(<unknown>util.confirmation()))
16+
if (editedSam === "create predefined 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

@@ -57,8 +60,7 @@ async function run(argv: Array<string>): Promise<void> {
5760
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

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: 19 additions & 2 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([
@@ -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 (): Promise<string> {
122138
const r = await inquirer.prompt([
123139
{
124140
type: "rawlist",
125141
name: "choice",
126142
message: `Hey, what do you want ?`,
127143
choices: [
128-
"create new SAM project",
144+
"create predefined SAM project",
145+
"create custom SAM project",
129146
"add components to existing SAM",
130147
"add modules to existing SAM",
131148
],

0 commit comments

Comments
 (0)