@nuxt/cli
Version:
Nuxt CLI
29 lines (28 loc) • 679 B
JavaScript
import { join } from "pathe";
import { existsSync, promises } from "node:fs";
// src/utils/fs.ts
async function clearDir(path, exclude) {
if (!exclude) await promises.rm(path, {
recursive: true,
force: true
});
else if (existsSync(path)) {
const files = await promises.readdir(path);
await Promise.all(files.map(async (name) => {
if (!exclude.includes(name)) await promises.rm(join(path, name), {
recursive: true,
force: true
});
}));
}
await promises.mkdir(path, { recursive: true });
}
function clearBuildDir(path) {
return clearDir(path, [
"cache",
"analyze",
"nuxt.json",
"nuxt.lock"
]);
}
export { clearDir as n, clearBuildDir as t };