rsnext/packages/create-next-app/helpers/is-folder-empty.ts
Sukka 66ffc3cd39
refactor(cna): replace chalk with picocolors, glob with fast-glob@2.2.7 (#53146)
Follows #53115

- Replace `chalk` with `picocolors`
  - Note that `chalk.hex('#007acc')` has been replaced with `picocolors.blue`
- Replace `glob` with `fast-glob@2.2.7`
  - Not only does `fast-glob` is a faster drop-in replacement of `glob` with first-party `Promise`-based API support, but also `fast-glob` is already a dependency of `cpy`:
 
  <img width="812" alt="image" src="https://github.com/vercel/next.js/assets/40715044/8efa24c4-5312-4b1c-bf8d-68255ca30b60">


Together the PR removes about `50 KiB` from the `create-next-app/dist/index.js`:

<img width="570" alt="image" src="https://github.com/vercel/next.js/assets/40715044/db2f3723-14cc-48ce-9cb2-8aa1fb1d5e95">


Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-07-26 18:16:13 +00:00

62 lines
1.4 KiB
TypeScript

/* eslint-disable import/no-extraneous-dependencies */
import { green, blue } from 'picocolors'
import fs from 'fs'
import path from 'path'
export function isFolderEmpty(root: string, name: string): boolean {
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',
'yarnrc.yml',
'.yarn',
]
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 ${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(` ${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
}