From 1e68a7e1d9d24f85a1e6a03d1f7ad34b4ac11795 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 2 Mar 2018 11:05:43 +0900 Subject: [PATCH] fix(cli): creating project in current directory closes #896 --- packages/@vue/cli/lib/create.js | 50 ++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/@vue/cli/lib/create.js b/packages/@vue/cli/lib/create.js index cc75f5dc0e..9485b64d31 100644 --- a/packages/@vue/cli/lib/create.js +++ b/packages/@vue/cli/lib/create.js @@ -8,28 +8,44 @@ const clearConsole = require('./util/clearConsole') const { error, stopSpinner } = require('@vue/cli-shared-utils') async function create (projectName, options) { - const targetDir = path.resolve(process.cwd(), projectName) + const inCurrent = projectName === '.' + const name = inCurrent ? path.relative('../', process.cwd()) : projectName + const targetDir = path.resolve(projectName || '.') + if (fs.existsSync(targetDir)) { if (options.force) { rimraf.sync(targetDir) } else { await clearConsole() - const { action } = await inquirer.prompt([ - { - name: 'action', - type: 'list', - message: `Target directory ${chalk.cyan(targetDir)} already exists. Pick an action:`, - choices: [ - { name: 'Overwrite', value: 'overwrite' }, - { name: 'Merge', value: 'merge' }, - { name: 'Cancel', value: false } - ] + if (inCurrent) { + const { ok } = await inquirer.prompt([ + { + name: 'ok', + type: 'confirm', + message: `Generate project in current directory ${chalk.cyan(targetDir)} ?` + } + ]) + if (!ok) { + return + } + } else { + const { action } = await inquirer.prompt([ + { + name: 'action', + type: 'list', + message: `Target directory ${chalk.cyan(targetDir)} already exists. Pick an action:`, + choices: [ + { name: 'Overwrite', value: 'overwrite' }, + { name: 'Merge', value: 'merge' }, + { name: 'Cancel', value: false } + ] + } + ]) + if (!action) { + return + } else if (action === 'overwrite') { + rimraf.sync(targetDir) } - ]) - if (!action) { - return - } else if (action === 'overwrite') { - rimraf.sync(targetDir) } } } @@ -46,7 +62,7 @@ async function create (projectName, options) { 'e2e' ].map(file => require(`./promptModules/${file}`)) - const creator = new Creator(projectName, targetDir, promptModules) + const creator = new Creator(name, targetDir, promptModules) await creator.create(options) }