104d18c607
* Completely rewrite Create Next App * Sort imports * Show what package manager is being used * Fix project name suggestion * Update tests for new implementation * Use normal prepublish command for on-install * Upgrade Node version * Switch to 8.16 * Disable v8 cache * Swap out update check package and fix CLI boot
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import chalk from 'chalk'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
export function isFolderEmpty(root: string, name: string) {
|
|
const validFiles = [
|
|
'.DS_Store',
|
|
'.git',
|
|
'.gitattributes',
|
|
'.gitignore',
|
|
'.gitlab-ci.yml',
|
|
'.hg',
|
|
'.hgcheck',
|
|
'.hgignore',
|
|
'.idea',
|
|
'.npmignore',
|
|
'.travis.yml',
|
|
'LICENSE',
|
|
'Thumbs.db',
|
|
'docs',
|
|
'mkdocs.yml',
|
|
'npm-debug.log',
|
|
'yarn-debug.log',
|
|
'yarn-error.log',
|
|
]
|
|
|
|
const conflicts = fs
|
|
.readdirSync(root)
|
|
.filter(file => !validFiles.includes(file))
|
|
// Support IntelliJ IDEA-based editors
|
|
.filter(file => !/\.iml$/.test(file))
|
|
|
|
if (conflicts.length > 0) {
|
|
console.log(
|
|
`The directory ${chalk.green(name)} contains files that could conflict:`
|
|
)
|
|
console.log()
|
|
for (const file of conflicts) {
|
|
try {
|
|
const stats = fs.lstatSync(path.join(root, file))
|
|
if (stats.isDirectory()) {
|
|
console.log(` ${chalk.blue(file)}/`)
|
|
} else {
|
|
console.log(` ${file}`)
|
|
}
|
|
} catch {
|
|
console.log(` ${file}`)
|
|
}
|
|
}
|
|
console.log()
|
|
console.log(
|
|
'Either try using a new directory name, or remove the files listed above.'
|
|
)
|
|
console.log()
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|