@@ -3,7 +3,7 @@ import { green, blue, dim } from 'https://deno.land/
[email protected] /fmt/colors.ts'
33import { ensureDir } from 'https://deno.land/[email protected] /fs/ensure_dir.ts' 44import { join } from 'https://deno.land/[email protected] /path/mod.ts' 55import { 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'
77import util from '../shared/util.ts'
88import { defaultReactVersion } from '../shared/constants.ts'
99import { VERSION } from '../version.ts'
@@ -28,8 +28,10 @@ export default async function (nameArg?: string) {
2828 return
2929 }
3030
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+ }
3335 }
3436
3537 const template = 'hello-world' // todo: add template select ui
@@ -129,7 +131,7 @@ async function confirm(question: string = 'are you sure?') {
129131 return a . charAt ( 0 ) . toLowerCase ( ) === 'y'
130132}
131133
132- function isFolderEmpty ( root : string , name : string ) : boolean {
134+ async function isFolderEmpty ( root : string , name : string ) : Promise < boolean > {
133135 const validFiles = [
134136 '.DS_Store' ,
135137 '.git' ,
@@ -149,13 +151,15 @@ function isFolderEmpty(root: string, name: string): boolean {
149151
150152 const conflicts = [ ]
151153
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+ }
159163 }
160164 }
161165 }
@@ -166,8 +170,7 @@ function isFolderEmpty(root: string, name: string): boolean {
166170 `The directory ${ green ( name ) } contains files that could conflict:` ,
167171 '' ,
168172 ...conflicts ,
169- '' ,
170- 'Either try using a new directory name, or remove the files listed above.'
173+ ''
171174 ] . join ( '\n' )
172175 )
173176 return false
0 commit comments