From 7a579ec4545ff69a2ade903c1d83502656a908fd Mon Sep 17 00:00:00 2001 From: Damian Glowala Date: Mon, 6 Jan 2025 20:57:08 +0100 Subject: [PATCH] fix: resolve type issue and move statements closer to place of usage --- src/commands/add.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/commands/add.ts b/src/commands/add.ts index c1b9acd3..25b7e505 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -37,15 +37,9 @@ export default defineCommand({ const cwd = resolve(ctx.args.cwd) const templateName = ctx.args.template - const template = templates[templateName] - const ext = extname(ctx.args.name) - const name - = ext === '.vue' || ext === '.ts' - ? ctx.args.name.replace(ext, '') - : ctx.args.name // Validate template name - if (!template) { + if (!Object.keys(templates).includes(templateName)) { logger.error( `Template ${templateName} is not supported. Possible values: ${Object.keys( templates, @@ -55,6 +49,12 @@ export default defineCommand({ } // Validate options + const ext = extname(ctx.args.name) + const name + = ext === '.vue' || ext === '.ts' + ? ctx.args.name.replace(ext, '') + : ctx.args.name + if (!name) { logger.error('name argument is missing!') process.exit(1) @@ -65,6 +65,8 @@ export default defineCommand({ const config = await kit.loadNuxtConfig({ cwd }) // Resolve template + const template = templates[templateName as keyof typeof templates] + const res = template({ name, args: ctx.args, nuxtOptions: config }) // Ensure not overriding user code