mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-20 06:23:47 +00:00
feat(create): reject non-empty target directories
Made-with: Cursor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user