From 4d6d4e2dc6bce001cf39f065e108105eb87d6d27 Mon Sep 17 00:00:00 2001 From: Mohammed Date: Wed, 29 May 2024 21:41:01 +0300 Subject: [PATCH] refactor(main): remove unnecessary forEach --- 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}`) }