Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import process from 'node:process'
import { defineCommand } from 'citty'
import { dirname, extname, resolve } from 'pathe'

import { camelCase, kebabCase } from 'scule'
import { loadKit } from '../utils/kit'
import { logger } from '../utils/logger'
import { templates } from '../utils/templates'
import { cwdArgs, logLevelArgs } from './_shared'

const KEBAB_CASE_TEMPLATE_NAMES = Object.keys(templates).map(template => kebabCase(template))
const templateNames = Object.keys(templates)

export default defineCommand({
meta: {
Expand All @@ -27,7 +26,7 @@ export default defineCommand({
template: {
type: 'positional',
required: true,
valueHint: KEBAB_CASE_TEMPLATE_NAMES.join('|'),
valueHint: templateNames.join('|'),
description: `Template type to scaffold`,
},
name: {
Expand All @@ -42,7 +41,7 @@ export default defineCommand({
const templateName = ctx.args.template

// Validate template name
if (!Object.keys(KEBAB_CASE_TEMPLATE_NAMES).includes(templateName)) {
if (!templateNames.includes(templateName)) {
logger.error(
`Template ${templateName} is not supported. Possible values: ${Object.keys(
templates,
Expand All @@ -68,7 +67,7 @@ export default defineCommand({
const config = await kit.loadNuxtConfig({ cwd })

// Resolve template
const template = templates[camelCase(templateName) as keyof typeof templates]
const template = templates[templateName as keyof typeof templates]

const res = template({ name, args: ctx.args, nuxtOptions: config })

Expand Down
32 changes: 16 additions & 16 deletions src/utils/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ interface Template {
}

const templates = {
api,
app,
appConfig,
component,
composable,
error,
layer,
layout,
middleware,
module,
page,
plugin,
serverMiddleware,
serverPlugin,
serverRoute,
serverUtil,
'api': api,
'app': app,
'app-config': appConfig,
'component': component,
'composable': composable,
'error': error,
'layer': layer,
'layout': layout,
'middleware': middleware,
'module': module,
'page': page,
'plugin': plugin,
'server-middleware': serverMiddleware,
'server-plugin': serverPlugin,
'server-route': serverRoute,
'server-util': serverUtil,
} satisfies Record<string, Template>

// -- internal utils --
Expand Down
Loading