From 997f0963f088a642e058e51a1a178e24f40a4cb9 Mon Sep 17 00:00:00 2001 From: Mohammed Taha <62352949+6km@users.noreply.github.com> Date: Thu, 30 May 2024 05:55:20 +0300 Subject: [PATCH] refactor(main): remove unnecessary forEach (#44) --- src/index.ts | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4f2b557..1976029 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) { @@ -54,18 +54,6 @@ async function main() { const { install, pm, template: templateArg } = args - const templates: Record = {} - - 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]) { @@ -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}`) }