feat(create): reject non-empty target directories

Made-with: Cursor
This commit is contained in:
zuiidea
2026-04-14 22:32:21 +08:00
parent 6031d691ea
commit db696409d3
+17
View File
@@ -0,0 +1,17 @@
import fs from "node:fs";
import path from "node:path";
import { CliError } from "./errors.js";
export function resolveTargetRoot(cwd: string, dir: string): string {
const abs = path.resolve(cwd, dir);
if (fs.existsSync(abs)) {
const entries = fs.readdirSync(abs);
if (entries.length > 0) {
throw new CliError(
`Target directory is not empty: ${abs}`,
"INVALID_INPUT"
);
}
}
return abs;
}