@ryanuo/utils
Version:
提供多种实用工具函数,涵盖算法、浏览器操作、网络请求等多个领域
29 lines (28 loc) • 760 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mkdirp = mkdirp;
exports.rmrf = rmrf;
var _promises = require("node:fs/promises");
var _nodePath = require("node:path");
async function mkdirp(dirPath) {
try {
await (0, _promises.access)(dirPath);
} catch {
await mkdirp((0, _nodePath.dirname)(dirPath));
await (0, _promises.mkdir)(dirPath);
}
}
async function rmrf(path) {
const stats = await (0, _promises.stat)(path);
if (stats.isDirectory()) {
const files = await (0, _promises.readdir)(path);
await Promise.all(files.map(file => rmrf((0, _nodePath.join)(path, file))));
await (0, _promises.rm)(path, {
recursive: true
});
} else {
await (0, _promises.rm)(path);
}
}