mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(nuxi): validate template argument (#1409)
This commit is contained in:
parent
9e3dfad172
commit
bd010313db
@ -13,6 +13,19 @@ const knownTemplates = {
|
|||||||
bridge: 'nuxt/starter#bridge'
|
bridge: 'nuxt/starter#bridge'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolveTemplate = (template) => {
|
||||||
|
if (template in knownTemplates) {
|
||||||
|
return knownTemplates[template]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof template === 'string' && template.includes('/')) {
|
||||||
|
return template
|
||||||
|
}
|
||||||
|
|
||||||
|
consola.error(`Invalid template name: \`${template}\``)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
meta: {
|
meta: {
|
||||||
name: 'init',
|
name: 'init',
|
||||||
@ -21,8 +34,7 @@ export default defineNuxtCommand({
|
|||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
// Clone template
|
// Clone template
|
||||||
const t = args.template || args.t
|
const src = resolveTemplate(args.template || args.t)
|
||||||
const src = knownTemplates[t] || t || 'nuxt/starter#v3'
|
|
||||||
const dstDir = resolve(process.cwd(), args._[0] || 'nuxt-app')
|
const dstDir = resolve(process.cwd(), args._[0] || 'nuxt-app')
|
||||||
const tiged = createTiged(src, { cache: false /* TODO: buggy */, verbose: (args.verbose || args.v) })
|
const tiged = createTiged(src, { cache: false /* TODO: buggy */, verbose: (args.verbose || args.v) })
|
||||||
if (existsSync(dstDir) && readdirSync(dstDir).length) {
|
if (existsSync(dstDir) && readdirSync(dstDir).length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user