Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(cli): creating project in current directory
closes #896
  • Loading branch information
kazupon committed Mar 2, 2018
commit 1e68a7e1d9d24f85a1e6a03d1f7ad34b4ac11795
50 changes: 33 additions & 17 deletions packages/@vue/cli/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}

Expand Down