@@ -3,7 +3,7 @@ import { green, blue, dim } from 'https://deno.land/
[email protected] /fmt/colors.ts'
3
3
import { ensureDir } from 'https://deno.land/[email protected] /fs/ensure_dir.ts'
4
4
import { join } from 'https://deno.land/[email protected] /path/mod.ts'
5
5
import { gunzip } from 'https://deno.land/x/[email protected] /mod.ts'
6
- import { ensureTextFile } from '../shared/fs.ts'
6
+ import { ensureTextFile , existsDir } from '../shared/fs.ts'
7
7
import util from '../shared/util.ts'
8
8
import { defaultReactVersion } from '../shared/constants.ts'
9
9
import { VERSION } from '../version.ts'
@@ -28,8 +28,10 @@ export default async function (nameArg?: string) {
28
28
return
29
29
}
30
30
31
- if ( ! isFolderEmpty ( cwd , name ) ) {
32
- Deno . exit ( 1 )
31
+ if ( ! await isFolderEmpty ( cwd , name ) ) {
32
+ if ( ! await confirm ( 'Continue?' ) ) {
33
+ Deno . exit ( 1 )
34
+ }
33
35
}
34
36
35
37
const template = 'hello-world' // todo: add template select ui
@@ -129,7 +131,7 @@ async function confirm(question: string = 'are you sure?') {
129
131
return a . charAt ( 0 ) . toLowerCase ( ) === 'y'
130
132
}
131
133
132
- function isFolderEmpty ( root : string , name : string ) : boolean {
134
+ async function isFolderEmpty ( root : string , name : string ) : Promise < boolean > {
133
135
const validFiles = [
134
136
'.DS_Store' ,
135
137
'.git' ,
@@ -149,13 +151,15 @@ function isFolderEmpty(root: string, name: string): boolean {
149
151
150
152
const conflicts = [ ]
151
153
152
- for ( const { name : file , isDirectory } of Deno . readDirSync ( root ) ) {
153
- // Support IntelliJ IDEA-based editors
154
- if ( validFiles . includes ( file ) || / \. i m l $ / . test ( file ) ) {
155
- if ( isDirectory ) {
156
- conflicts . push ( blue ( file ) + '/' )
157
- } else {
158
- conflicts . push ( file )
154
+ if ( await existsDir ( join ( root , name ) ) ) {
155
+ for await ( const { name : file , isDirectory } of Deno . readDir ( join ( root , name ) ) ) {
156
+ // Support IntelliJ IDEA-based editors
157
+ if ( validFiles . includes ( file ) || / \. i m l $ / . test ( file ) ) {
158
+ if ( isDirectory ) {
159
+ conflicts . push ( blue ( file ) + '/' )
160
+ } else {
161
+ conflicts . push ( file )
162
+ }
159
163
}
160
164
}
161
165
}
@@ -166,8 +170,7 @@ function isFolderEmpty(root: string, name: string): boolean {
166
170
`The directory ${ green ( name ) } contains files that could conflict:` ,
167
171
'' ,
168
172
...conflicts ,
169
- '' ,
170
- 'Either try using a new directory name, or remove the files listed above.'
173
+ ''
171
174
] . join ( '\n' )
172
175
)
173
176
return false
0 commit comments