Skip to content

Commit

Permalink
fix: resolve type issue and move statements closer to place of usage
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianGlowala committed Jan 6, 2025
1 parent 31c881a commit 7a579ec
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 7a579ec

Please sign in to comment.