File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,20 @@ function toValidPackageName(projectName) {
27
27
. replace ( / [ ^ a - z 0 - 9 - ~ ] + / g, '-' )
28
28
}
29
29
30
- function canSafelyOverwrite ( dir ) {
31
- return ! fs . existsSync ( dir ) || fs . readdirSync ( dir ) . length === 0
30
+ function canSkipEmptying ( dir : string ) {
31
+ if ( ! fs . existsSync ( dir ) ) {
32
+ return true
33
+ }
34
+
35
+ const files = fs . readdirSync ( dir )
36
+ if ( files . length === 0 ) {
37
+ return true
38
+ }
39
+ if ( files . length === 1 && files [ 0 ] === '.git' ) {
40
+ return true
41
+ }
42
+
43
+ return false
32
44
}
33
45
34
46
function emptyDir ( dir ) {
@@ -125,7 +137,7 @@ async function init() {
125
137
} ,
126
138
{
127
139
name : 'shouldOverwrite' ,
128
- type : ( ) => ( canSafelyOverwrite ( targetDir ) || forceOverwrite ? null : 'confirm' ) ,
140
+ type : ( ) => ( canSkipEmptying ( targetDir ) || forceOverwrite ? null : 'confirm' ) ,
129
141
message : ( ) => {
130
142
const dirForPrompt =
131
143
targetDir === '.' ? 'Current directory' : `Target directory "${ targetDir } "`
You can’t perform that action at this time.
0 commit comments