fs、path
删除目录
// 删除目录,将传递的目录也给删除function delDir(path) { let files = []; if (fs.existsSync(path)) { files = fs.readdirSync(path); files.forEach((file, index) => { let curPath = path + "/" + file; if (fs.statSync(curPath).isDirectory()) { delDir(curPath); //递归删除文件夹 } else { fs.unlinkSync(curPath); //删除文件 } }); fs.rmdirSync(path); }}/* 清空下packages的内容,会保留packages目录存在 */const packagesPath = path.join(__dirname, "../packages");function cleanupPackages(packagesPath) { const isExistPackages = fs.existsSync(packagesPath); // 存在则清除 if (isExistPackages) { delDir(packagesPath); } fs.mkdirSync(packagesPath);}cleanupPackages(packagesPath);