@@ -8,28 +8,44 @@ const clearConsole = require('./util/clearConsole')
8
8
const { error, stopSpinner } = require ( '@vue/cli-shared-utils' )
9
9
10
10
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
+
12
15
if ( fs . existsSync ( targetDir ) ) {
13
16
if ( options . force ) {
14
17
rimraf . sync ( targetDir )
15
18
} else {
16
19
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 )
27
48
}
28
- ] )
29
- if ( ! action ) {
30
- return
31
- } else if ( action === 'overwrite' ) {
32
- rimraf . sync ( targetDir )
33
49
}
34
50
}
35
51
}
@@ -46,7 +62,7 @@ async function create (projectName, options) {
46
62
'e2e'
47
63
] . map ( file => require ( `./promptModules/${ file } ` ) )
48
64
49
- const creator = new Creator ( projectName , targetDir , promptModules )
65
+ const creator = new Creator ( name , targetDir , promptModules )
50
66
await creator . create ( options )
51
67
}
52
68
0 commit comments