Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 51411f5

Browse files
committed
Clean up
1 parent a868aad commit 51411f5

File tree

2 files changed

+48
-63
lines changed

2 files changed

+48
-63
lines changed

commands/helpers/is-folder-empty.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

commands/init.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Untar } from 'https://deno.land/[email protected]/archive/tar.ts'
2-
import { green, dim } from 'https://deno.land/[email protected]/fmt/colors.ts'
2+
import { green, blue, dim } from 'https://deno.land/[email protected]/fmt/colors.ts'
33
import { ensureDir } from 'https://deno.land/[email protected]/fs/ensure_dir.ts'
44
import { join } from 'https://deno.land/[email protected]/path/mod.ts'
55
import { gunzip } from 'https://deno.land/x/[email protected]/mod.ts'
@@ -8,7 +8,6 @@ import util from '../shared/util.ts'
88
import { defaultReactVersion } from '../shared/constants.ts'
99
import { VERSION } from '../version.ts'
1010
import { deno_x_brotli, deno_x_flate } from '../server/compress.ts'
11-
import isFolderEmpty from './helpers/is-folder-empty.ts';
1211

1312
export const helpMessage = `
1413
Usage:
@@ -129,3 +128,50 @@ async function confirm(question: string = 'are you sure?') {
129128
while (!/^(y(es)?|no?)$/i.test(a = (await ask(question + ' ' + dim('[y/n]'))).trim())) { }
130129
return a.charAt(0).toLowerCase() === 'y'
131130
}
131+
132+
function isFolderEmpty(root: string, name: string): boolean {
133+
const validFiles = [
134+
'.DS_Store',
135+
'.git',
136+
'.gitattributes',
137+
'.gitignore',
138+
'.gitlab-ci.yml',
139+
'.hg',
140+
'.hgcheck',
141+
'.hgignore',
142+
'.idea',
143+
'.travis.yml',
144+
'LICENSE',
145+
'Thumbs.db',
146+
'docs',
147+
'mkdocs.yml',
148+
]
149+
150+
const conflicts = []
151+
152+
for (const { name: file, isDirectory } of Deno.readDirSync(root)) {
153+
// Support IntelliJ IDEA-based editors
154+
if (validFiles.includes(file) || /\.iml$/.test(file)) {
155+
if (isDirectory) {
156+
conflicts.push(blue(file) + '/')
157+
} else {
158+
conflicts.push(file)
159+
}
160+
}
161+
}
162+
163+
if (conflicts.length > 0) {
164+
console.log(
165+
[
166+
`The directory ${green(name)} contains files that could conflict:`,
167+
'',
168+
...conflicts,
169+
'',
170+
'Either try using a new directory name, or remove the files listed above.'
171+
].join('\n')
172+
)
173+
return false
174+
}
175+
176+
return true
177+
}

0 commit comments

Comments
 (0)