feat: Check for empty directory (#9539)

* feat: check for empty directory

* fix: correct error

Co-authored-by: space <spaceeec@yahoo.com>

---------

Co-authored-by: space <spaceeec@yahoo.com>
This commit is contained in:
Jiralite
2023-05-08 08:00:09 +01:00
committed by GitHub
parent b6162bc5b5
commit 64324a8be1

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env node
// eslint-disable-next-line n/shebang
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { URL } from 'node:url';
@@ -28,6 +28,12 @@ if (!directory) {
const root = path.resolve(directory);
const directoryName = path.basename(root);
if (existsSync(root) && readdirSync(root).length > 0) {
console.error(chalk.red(`The directory ${chalk.yellow(`"${directoryName}"`)} is not empty.`));
console.error(chalk.red(`Please specify an empty directory.`));
process.exit(1);
}
// We'll use the directory name as the project name. Check npm name validity.
const validationResult = validateProjectName(directoryName);