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

Commit e194c49

Browse files
committed
feat(cli/helpers): Check if the directory contains files that could conflict
1 parent 2fa0322 commit e194c49

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

cli/helpers/is-folder-empty.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { green, blue } from 'https://deno.land/[email protected]/fmt/colors.ts'
2+
import { join } from "https://deno.land/std/path/mod.ts"
3+
4+
export default function (root: string, name: string): boolean {
5+
const validFiles = [
6+
'.DS_Store',
7+
'.git',
8+
'.gitattributes',
9+
'.gitignore',
10+
'.gitlab-ci.yml',
11+
'.hg',
12+
'.hgcheck',
13+
'.hgignore',
14+
'.idea',
15+
'.npmignore',
16+
'.travis.yml',
17+
'LICENSE',
18+
'Thumbs.db',
19+
'docs',
20+
'mkdocs.yml',
21+
]
22+
23+
const conflicts = []
24+
25+
for (const { name: file } of Deno.readDirSync(root)) {
26+
// Support IntelliJ IDEA-based editors
27+
if (validFiles.includes(file) || /\.iml$/.test(file)) {
28+
conflicts.push(file)
29+
}
30+
}
31+
32+
if (conflicts.length > 0) {
33+
console.log(
34+
`The directory ${green(name)} contains files that could conflict:`
35+
)
36+
console.log()
37+
38+
for (const file of conflicts) {
39+
try {
40+
const stats = Deno.lstatSync(join(root, file))
41+
if (stats.isDirectory) {
42+
console.log(` ${blue(file)}/`)
43+
} else {
44+
console.log(` ${file}`)
45+
}
46+
} catch {
47+
console.log(` ${file}`)
48+
}
49+
}
50+
51+
console.log()
52+
console.log(
53+
'Either try using a new directory name, or remove the files listed above.'
54+
)
55+
console.log()
56+
57+
return false
58+
}
59+
60+
return true
61+
62+
}

0 commit comments

Comments
 (0)