chore: update dependencies and documentation, optimize build toolchain (#6060)
* chore: update packageManager version to pnpm@10.9.0 for compatibility improvements * chore: Update dependent versions and configurations to improve compatibility and stability - Update Node version to 22.1.0 - Updated pnpm version to 10.10.0 - Fixed syntax error in prettier command in lintstagedrc - Update dependent versions in pnpm-lock.yaml to ensure consistency - Update format and content in README documents to improve readability * fix: lint error
This commit is contained in:
@@ -1,31 +1,33 @@
|
||||
import { promises as fs } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { join, normalize } from 'node:path';
|
||||
|
||||
const rootDir = process.cwd();
|
||||
|
||||
/**
|
||||
* 递归查找并删除目标目录
|
||||
* @param {string} currentDir - 当前遍历的目录路径
|
||||
* @param {string[]} targets - 要删除的目标列表
|
||||
*/
|
||||
async function cleanTargetsRecursively(currentDir, targets) {
|
||||
const items = await fs.readdir(currentDir);
|
||||
|
||||
for (const item of items) {
|
||||
try {
|
||||
const itemPath = join(currentDir, item);
|
||||
const itemPath = normalize(join(currentDir, item));
|
||||
const stat = await fs.lstat(itemPath);
|
||||
|
||||
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()) {
|
||||
} else if (stat.isDirectory()) {
|
||||
// 只对目录进行递归处理
|
||||
await cleanTargetsRecursively(itemPath, targets);
|
||||
}
|
||||
} catch {
|
||||
// console.error(
|
||||
// `Error handling item ${item} in ${currentDir}: ${error.message}`,
|
||||
// );
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Error handling item ${item} in ${currentDir}: ${error.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,9 +35,9 @@ async function cleanTargetsRecursively(currentDir, targets) {
|
||||
(async function startCleanup() {
|
||||
// 要删除的目录及文件名称
|
||||
const targets = ['node_modules', 'dist', '.turbo', 'dist.zip'];
|
||||
|
||||
const deleteLockFile = process.argv.includes('--del-lock');
|
||||
const cleanupTargets = [...targets];
|
||||
|
||||
if (deleteLockFile) {
|
||||
cleanupTargets.push('pnpm-lock.yaml');
|
||||
}
|
||||
@@ -46,8 +48,9 @@ async function cleanTargetsRecursively(currentDir, targets) {
|
||||
|
||||
try {
|
||||
await cleanTargetsRecursively(rootDir, cleanupTargets);
|
||||
console.log('Cleanup process completed.');
|
||||
console.log('Cleanup process completed successfully.');
|
||||
} catch (error) {
|
||||
console.error(`Unexpected error during cleanup: ${error.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
|
Reference in New Issue
Block a user