Skip to content

Commit

Permalink
refactor(main): remove unnecessary forEach (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
6km authored May 30, 2024
1 parent 2bb1e29 commit 997f096
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ const config = {
ref: 'main',
}

const templateDirs = [
'templates/aws-lambda',
'templates/bun',
'templates/cloudflare-pages',
'templates/cloudflare-workers',
'templates/deno',
'templates/fastly',
'templates/lambda-edge',
'templates/netlify',
'templates/nextjs',
'templates/nodejs',
'templates/vercel',
'templates/x-basic',
const templates = [
'aws-lambda',
'bun',
'cloudflare-pages',
'cloudflare-workers',
'deno',
'fastly',
'lambda-edge',
'netlify',
'nextjs',
'nodejs',
'vercel',
'x-basic',
]

function mkdirp(dir: string) {
Expand All @@ -54,18 +54,6 @@ async function main() {

const { install, pm, template: templateArg } = args

const templates: Record<string, { name: string }> = {}

templateDirs.forEach((dir) => {
const template = dir.replace(`${directoryName}/`, '')
if (!templates[template]) {
templates[template] = {
name: template,
}
}
})
const templateNames = [...Object.values(templates)] as { name: string }[]

let target = ''
let projectName = ''
if (args._[0]) {
Expand All @@ -92,17 +80,18 @@ async function main() {
(await select({
loop: true,
message: 'Which template do you want to use?',
choices: templateNames.map((template: { name: string }) => ({
title: template.name,
value: template.name,
choices: templates.map((template) => ({
title: template,
value: template,
})),
default: 0,
}))

if (!templateName) {
throw new Error('No template selected')
}

if (!templateNames.find((t) => t.name === templateName)) {
if (!templates.includes(templateName)) {
throw new Error(`Invalid template selected: ${templateName}`)
}

Expand Down

0 comments on commit 997f096

Please sign in to comment.