Skip to content

Commit 1e68a7e

Browse files
committed
fix(cli): creating project in current directory
closes vuejs#896
1 parent e4ff22a commit 1e68a7e

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

Diff for: packages/@vue/cli/lib/create.js

+33-17
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,44 @@ const clearConsole = require('./util/clearConsole')
88
const { error, stopSpinner } = require('@vue/cli-shared-utils')
99

1010
async function create (projectName, options) {
11-
const targetDir = path.resolve(process.cwd(), projectName)
11+
const inCurrent = projectName === '.'
12+
const name = inCurrent ? path.relative('../', process.cwd()) : projectName
13+
const targetDir = path.resolve(projectName || '.')
14+
1215
if (fs.existsSync(targetDir)) {
1316
if (options.force) {
1417
rimraf.sync(targetDir)
1518
} else {
1619
await clearConsole()
17-
const { action } = await inquirer.prompt([
18-
{
19-
name: 'action',
20-
type: 'list',
21-
message: `Target directory ${chalk.cyan(targetDir)} already exists. Pick an action:`,
22-
choices: [
23-
{ name: 'Overwrite', value: 'overwrite' },
24-
{ name: 'Merge', value: 'merge' },
25-
{ name: 'Cancel', value: false }
26-
]
20+
if (inCurrent) {
21+
const { ok } = await inquirer.prompt([
22+
{
23+
name: 'ok',
24+
type: 'confirm',
25+
message: `Generate project in current directory ${chalk.cyan(targetDir)} ?`
26+
}
27+
])
28+
if (!ok) {
29+
return
30+
}
31+
} else {
32+
const { action } = await inquirer.prompt([
33+
{
34+
name: 'action',
35+
type: 'list',
36+
message: `Target directory ${chalk.cyan(targetDir)} already exists. Pick an action:`,
37+
choices: [
38+
{ name: 'Overwrite', value: 'overwrite' },
39+
{ name: 'Merge', value: 'merge' },
40+
{ name: 'Cancel', value: false }
41+
]
42+
}
43+
])
44+
if (!action) {
45+
return
46+
} else if (action === 'overwrite') {
47+
rimraf.sync(targetDir)
2748
}
28-
])
29-
if (!action) {
30-
return
31-
} else if (action === 'overwrite') {
32-
rimraf.sync(targetDir)
3349
}
3450
}
3551
}
@@ -46,7 +62,7 @@ async function create (projectName, options) {
4662
'e2e'
4763
].map(file => require(`./promptModules/${file}`))
4864

49-
const creator = new Creator(projectName, targetDir, promptModules)
65+
const creator = new Creator(name, targetDir, promptModules)
5066
await creator.create(options)
5167
}
5268

0 commit comments

Comments
 (0)