Skip to content

Commit 3900b6f

Browse files
committed
feature: seperate the init and add command
1 parent 4fef396 commit 3900b6f

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

bin/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ import { version } from "../package.json"
1212
import * as util from "../src/utilities/cliUtil"
1313

1414
async function handleInitCommand() {
15-
const editedSam = <string>(<unknown>await util.confirmation())
15+
const editedSam = <string>(<unknown>await util.initConfirmation())
1616
if (editedSam === "create new SAM project") {
1717
await createSAMCLI()
1818
} else if (editedSam === "create custom SAM project") {
1919
await createCustomSAMCLI()
20-
} else if (editedSam === "add components to existing SAM") {
20+
} else {
21+
console.log(editedSam)
22+
throw new Error(`Unknown option ${editedSam}`)
23+
}
24+
}
25+
async function handleAddCommand() {
26+
const editedSam = <string>(<unknown>await util.addConfirmation())
27+
if (editedSam === "add components to existing SAM") {
2128
await addComponentCLI()
2229
} else if (editedSam === "add modules to existing SAM") {
2330
await addModuleCLI()
@@ -49,6 +56,9 @@ async function run(argv: Array<string>): Promise<void> {
4956
case "init":
5057
await handleInitCommand()
5158
break
59+
case "add":
60+
await handleAddCommand()
61+
break
5262
case "deploy":
5363
await handleDeployCommand()
5464
break

scripts/exec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sam build
2-
sam deploy --no-confirm-changeset --capabilities CAPABILITY_NAMED_IAM CAPABILITY_IAM CAPABILITY_AUTO_EXPAND --stack-name $2 --region $3 --profile $5 $4
2+
sam deploy --no-confirm-changeset --capabilities CAPABILITY_NAMED_IAM CAPABILITY_IAM CAPABILITY_AUTO_EXPAND --stack-name $2 --profile $3 --region $4 $5

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 ${roverHelpers.npmroot}/@rover-tools/cli/scripts/exec.sh ${fileName} ${stack_name} ${region} ${bucketName} ${profile} `
73+
`sh ${roverHelpers.npmroot}/@rover-tools/cli/scripts/exec.sh ${fileName} ${stack_name} ${profile} ${region} ${bucketName}`
7474
)
7575

7676
const configdata: IroverDeploymentConfig = <IroverDeploymentConfig>{}

src/roverCLI/roverGenerateCLI.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as rover from "@rover-tools/engine/dist/bin/index"
22
const roverHelpers = rover.helpers
3-
const rover_addComponent = rover.addComponents
3+
//const rover_addComponent = rover.addComponents
4+
const rover_addComponent = rover.addComponent
45
const rover_addModules = rover.addModules
56
const rover_generateSAM = rover.generateSAM
67
const rover_addModulesToexisting = rover.addModulesToExisting

src/utilities/cliUtil.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,20 @@ export async function inputString(
7171
(value !== "" && value !== undefined) ||
7272
"Environment values cannot be empty"
7373
)
74-
} else {
75-
return (
76-
optional ||
77-
stringpattern.test(value) ||
78-
`${message} should have only alphanumeric values`
79-
)
8074
}
75+
// return (
76+
// optional ||
77+
// stringpattern.test(value) ||
78+
// `${typeof message} ${typeof value} ${typeof optional} ${typeof stringpattern.test(
79+
// value
80+
// )} should have only alphanumeric values `
81+
// )
82+
return (
83+
optional ||
84+
(!stringpattern.test(value)
85+
? `should have only alphanumeric values`
86+
: true)
87+
)
8188
},
8289
},
8390
])
@@ -134,15 +141,25 @@ export const inputType = async function (
134141
return takeInput
135142
}
136143

137-
export const confirmation = async function () {
144+
export const initConfirmation = async function () {
145+
const r = await inquirer.prompt([
146+
{
147+
type: "rawlist",
148+
name: "choice",
149+
message: `Hey, what do you want ?`,
150+
choices: ["create new SAM project", "create custom SAM project"],
151+
},
152+
])
153+
154+
return r.choice
155+
}
156+
export const addConfirmation = async function () {
138157
const r = await inquirer.prompt([
139158
{
140159
type: "rawlist",
141160
name: "choice",
142161
message: `Hey, what do you want ?`,
143162
choices: [
144-
"create new SAM project",
145-
"create custom SAM project",
146163
"add components to existing SAM",
147164
"add modules to existing SAM",
148165
],

0 commit comments

Comments
 (0)