| 4 | import { green, blue } from 'picocolors' |
| 5 | |
| 6 | export function isFolderEmpty(root: string, name: string): boolean { |
| 7 | const validFilesOrFolders = [ |
| 8 | '.claude', |
| 9 | '.cursor', |
| 10 | '.DS_Store', |
| 11 | '.git', |
| 12 | '.gitattributes', |
| 13 | '.gitignore', |
| 14 | '.gitlab-ci.yml', |
| 15 | '.hg', |
| 16 | '.hgcheck', |
| 17 | '.hgignore', |
| 18 | '.idea', |
| 19 | '.npmignore', |
| 20 | '.travis.yml', |
| 21 | '.vscode', |
| 22 | '.zed', |
| 23 | 'LICENSE', |
| 24 | 'Thumbs.db', |
| 25 | 'docs', |
| 26 | 'mkdocs.yml', |
| 27 | 'npm-debug.log', |
| 28 | 'yarn-debug.log', |
| 29 | 'yarn-error.log', |
| 30 | 'yarnrc.yml', |
| 31 | '.yarn', |
| 32 | ] |
| 33 | |
| 34 | const conflicts = readdirSync(root).filter( |
| 35 | (fileOrFolder) => |
| 36 | !validFilesOrFolders.includes(fileOrFolder) && |
| 37 | // Support IntelliJ IDEA-based editors |
| 38 | !/\.iml$/.test(fileOrFolder) |
| 39 | ) |
| 40 | |
| 41 | if (conflicts.length > 0) { |
| 42 | console.log( |
| 43 | `The directory ${green(name)} contains files that could conflict:` |
| 44 | ) |
| 45 | console.log() |
| 46 | for (const file of conflicts) { |
| 47 | try { |
| 48 | const stats = lstatSync(join(root, file)) |
| 49 | if (stats.isDirectory()) { |
| 50 | console.log(` ${blue(file)}/`) |
| 51 | } else { |
| 52 | console.log(` ${file}`) |
| 53 | } |
| 54 | } catch { |
| 55 | console.log(` ${file}`) |
| 56 | } |
| 57 | } |
| 58 | console.log() |
| 59 | console.log( |
| 60 | 'Either try using a new directory name, or remove the files listed above.' |
| 61 | ) |
| 62 | console.log() |
| 63 | return false |