@@ -32,17 +32,18 @@ export default defineCommand({
3232 async run ( ctx ) {
3333 const cwd = resolve ( ctx . args . cwd || '.' )
3434
35- const template = ctx . args . template
35+ const templateName = ctx . args . template
36+ const template = templates [ templateName ]
3637 const ext = extname ( ctx . args . name )
3738 const name
3839 = ext === '.vue' || ext === '.ts'
3940 ? ctx . args . name . replace ( ext , '' )
4041 : ctx . args . name
4142
4243 // Validate template name
43- if ( ! templates [ template ] ) {
44+ if ( ! template ) {
4445 consola . error (
45- `Template ${ template } is not supported. Possible values: ${ Object . keys (
46+ `Template ${ templateName } is not supported. Possible values: ${ Object . keys (
4647 templates ,
4748 ) . join ( ', ' ) } `,
4849 )
@@ -60,7 +61,7 @@ export default defineCommand({
6061 const config = await kit . loadNuxtConfig ( { cwd } )
6162
6263 // Resolve template
63- const res = templates [ template ] ( { name, args : ctx . args } )
64+ const res = template ( { name, args : ctx . args } )
6465
6566 // Resolve full path to generated file
6667 const path = resolve ( config . srcDir , res . path )
@@ -77,14 +78,14 @@ export default defineCommand({
7778 const parentDir = dirname ( path )
7879 if ( ! existsSync ( parentDir ) ) {
7980 consola . info ( 'Creating directory' , parentDir )
80- if ( template === 'page' ) {
81+ if ( templateName === 'page' ) {
8182 consola . info ( 'This enables vue-router functionality!' )
8283 }
8384 await fsp . mkdir ( parentDir , { recursive : true } )
8485 }
8586
8687 // Write file
8788 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 } ` )
8990 } ,
9091} )
0 commit comments