Skip to content

Commit ca661d0

Browse files
committed
fix: simplified the sambuild function
1 parent e0f6339 commit ca661d0

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

src/utilities/cliUtil.ts

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export const password = async function (userName: string, message = "") {
195195
return r
196196
}
197197

198-
export const samBuild = async function (lang: string) {
198+
export const samBuilds = async function (lang: string) {
199199
try {
200200
const obj = buildConfig.samConfig
201201
const choices = <Record<string, Array<string>>>buildConfig.samConfig.choices
@@ -308,6 +308,121 @@ export const samBuild = async function (lang: string) {
308308
}
309309
}
310310

311+
export const samBuild = async (lang: string) => {
312+
try {
313+
const { samConfig } = buildConfig
314+
315+
const sam = await inputCli(
316+
samConfig,
317+
<Array<Record<string, string>>>samConfig.samBuild,
318+
""
319+
)
320+
321+
const { choices } = samConfig
322+
323+
const language = { language: lang }
324+
325+
const no_of_env = await inputNumber("no_of_env", "environments")
326+
const envs = []
327+
const steps = {}
328+
const stacknames = {}
329+
const deploymentregion = <Record<string, string>>{}
330+
const deploymentparameters = {}
331+
const depBucketNames = {}
332+
333+
const branches = { branches: ["main"] }
334+
335+
for (let i = 1; i <= no_of_env; i++) {
336+
const envName = <string>(
337+
(await inputString(`env${i}`, "", false, `Environment ${i}:`))[
338+
`env${i}`
339+
]
340+
)
341+
envs.push(envName)
342+
343+
const stepsChoice = (<Record<string, Array<string>>>choices).dev
344+
const stepData = await multichoice(
345+
`Steps required for ${envName} environment`,
346+
stepsChoice,
347+
""
348+
)
349+
const step = Object.fromEntries(
350+
Object.entries(stepData).map(([key, value]) => {
351+
const name = key
352+
.replace("steps required for ", "")
353+
.replace(" environment ", "")
354+
return [name, value]
355+
})
356+
)
357+
Object.assign(steps, step)
358+
359+
const stackname = (
360+
await inputString(
361+
`${envName}`,
362+
"",
363+
true,
364+
`Stack Name (optional) --> ${envName}:`
365+
)
366+
)[envName]
367+
const deploymentbucket = (
368+
await inputString(
369+
`${envName}`,
370+
"",
371+
true,
372+
`Deployment Bucket (optional) --> ${envName}:`
373+
)
374+
)[envName]
375+
376+
const regionChoice = (<Record<string, Array<string>>>choices)
377+
.deploymentregion
378+
const deployment_region = <string>(
379+
(await inputType(`${envName}`, regionChoice, "Deployment Region"))[
380+
`${envName}`
381+
]
382+
)
383+
deploymentregion[`${envName}`] = deployment_region
384+
385+
const deployment_parameter = (
386+
await inputString(
387+
`${envName}`,
388+
"",
389+
true,
390+
`Deployment Parameter (optional) --> ${envName}:`
391+
)
392+
)[envName]
393+
394+
Object.assign(stacknames, { [envName]: stackname })
395+
Object.assign(depBucketNames, { [envName]: deploymentbucket })
396+
Object.assign(deploymentparameters, { [envName]: deployment_parameter })
397+
}
398+
399+
const deployment_choice = (<Record<string, Array<string>>>choices)
400+
.deployment
401+
const deploymentEvent = await multichoice(
402+
`Deployment Events`,
403+
deployment_choice,
404+
""
405+
)
406+
407+
return {
408+
...sam,
409+
...language,
410+
no_of_env,
411+
envs,
412+
...branches,
413+
framework: "sam",
414+
steps,
415+
stackname: { ...stacknames },
416+
deploymentbucket: { ...depBucketNames },
417+
deploymentregion,
418+
deploymentparameters,
419+
...deploymentEvent,
420+
}
421+
} catch (error) {
422+
console.log(error)
423+
}
424+
}
425+
311426
export const appType = async function (message = "") {
312427
const r = await inquirer.prompt([
313428
{

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
14+
"target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */

0 commit comments

Comments
 (0)