chore: 补充构建缺少的开发依赖

This commit is contained in:
wangxuefeng
2025-03-11 16:41:19 +08:00
parent 6be244336e
commit 14d4519d03
5 changed files with 341 additions and 297 deletions

58
scripts/clean-dist.mjs Normal file
View File

@@ -0,0 +1,58 @@
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
const rootDir = process.cwd();
/**
* 递归查找并删除目标目录
* @param {string} currentDir - 当前遍历的目录路径
*/
async function cleanTargetsRecursively(currentDir, targets) {
// 忽略 node_modules 目录
if (currentDir.includes('node_modules')) {
return;
}
const items = await fs.readdir(currentDir);
for (const item of items) {
try {
const itemPath = join(currentDir, item);
// 忽略 node_modules 目录
if (item === 'node_modules') {
continue;
}
if (targets.includes(item)) {
// 匹配到目标目录或文件时直接删除
await fs.rm(itemPath, { force: true, recursive: true });
console.log(`Deleted: ${itemPath}`);
}
const stat = await fs.lstat(itemPath);
if (stat.isDirectory()) {
await cleanTargetsRecursively(itemPath, targets);
}
} catch {
// console.error(
// `Error handling item ${item} in ${currentDir}: ${error.message}`,
// );
}
}
}
(async function startCleanup() {
// 要删除的目录及文件名称
const targets = ['dist', '.turbo'];
const cleanupTargets = [...targets];
console.log(
`Starting cleanup of targets: ${cleanupTargets.join(', ')} from root: ${rootDir}`,
);
try {
await cleanTargetsRecursively(rootDir, cleanupTargets);
console.log('Cleanup process completed.');
} catch (error) {
console.error(`Unexpected error during cleanup: ${error.message}`);
}
})();