@@ -32,17 +32,18 @@ export default defineCommand({
32
32
async run ( ctx ) {
33
33
const cwd = resolve ( ctx . args . cwd || '.' )
34
34
35
- const template = ctx . args . template
35
+ const templateName = ctx . args . template
36
+ const template = templates [ templateName ]
36
37
const ext = extname ( ctx . args . name )
37
38
const name
38
39
= ext === '.vue' || ext === '.ts'
39
40
? ctx . args . name . replace ( ext , '' )
40
41
: ctx . args . name
41
42
42
43
// Validate template name
43
- if ( ! templates [ template ] ) {
44
+ if ( ! template ) {
44
45
consola . error (
45
- `Template ${ template } is not supported. Possible values: ${ Object . keys (
46
+ `Template ${ templateName } is not supported. Possible values: ${ Object . keys (
46
47
templates ,
47
48
) . join ( ', ' ) } `,
48
49
)
@@ -60,7 +61,7 @@ export default defineCommand({
60
61
const config = await kit . loadNuxtConfig ( { cwd } )
61
62
62
63
// Resolve template
63
- const res = templates [ template ] ( { name, args : ctx . args } )
64
+ const res = template ( { name, args : ctx . args } )
64
65
65
66
// Resolve full path to generated file
66
67
const path = resolve ( config . srcDir , res . path )
@@ -77,14 +78,14 @@ export default defineCommand({
77
78
const parentDir = dirname ( path )
78
79
if ( ! existsSync ( parentDir ) ) {
79
80
consola . info ( 'Creating directory' , parentDir )
80
- if ( template === 'page' ) {
81
+ if ( templateName === 'page' ) {
81
82
consola . info ( 'This enables vue-router functionality!' )
82
83
}
83
84
await fsp . mkdir ( parentDir , { recursive : true } )
84
85
}
85
86
86
87
// Write file
87
88
await fsp . writeFile ( path , res . contents . trim ( ) + '\n' )
88
- consola . info ( `🪄 Generated a new ${ template } in ${ path } ` )
89
+ consola . info ( `🪄 Generated a new ${ templateName } in ${ path } ` )
89
90
} ,
90
91
} )
0 commit comments