furniture-3d-system-Wu/scripts/cleanup-local-artifacts.js
WuYongJie 8d1f86756d chore(协作流程): 收口团队协作规则与主线清理机制
为新平台主链补齐团队协作模式、模块边界、任务单和提测清单。

新增本地清理脚本,移除误纳入仓库的 npm 缓存日志,并把清理后 type-check 失效的问题收回到脚本层修复。
2026-03-31 10:23:56 +08:00

79 lines
1.5 KiB
JavaScript

const fs = require('fs/promises')
const path = require('path')
const root = process.cwd()
const directories = [
'.codex-logs',
'_logs',
'.next',
'coverage',
'output',
'temp',
]
const files = [
'%OUT%',
'nul',
'dev-server.log',
'trace-deprecation-build.log',
'typecheck-latest.log',
'tsconfig.tsbuildinfo',
]
const globPatterns = [
/^\.dev-.*\.log$/,
/^\.qa-.*\.log$/,
/^\.start-.*\.log$/,
/^\.next-start-.*\.log$/,
]
async function removeTarget(relativePath, removed) {
const absolutePath = path.join(root, relativePath)
try {
await fs.rm(absolutePath, { recursive: true, force: true })
removed.push(relativePath)
} catch (error) {
console.warn(`[skip] ${relativePath}: ${error.message}`)
}
}
async function main() {
const removed = []
const entries = await fs.readdir(root, { withFileTypes: true })
for (const directory of directories) {
await removeTarget(directory, removed)
}
for (const file of files) {
await removeTarget(file, removed)
}
for (const entry of entries) {
if (!entry.isFile()) {
continue
}
if (globPatterns.some((pattern) => pattern.test(entry.name))) {
await removeTarget(entry.name, removed)
}
}
if (removed.length === 0) {
console.log('No local artifacts removed.')
return
}
console.log('Removed local artifacts:')
for (const item of removed) {
console.log(`- ${item}`)
}
}
main().catch((error) => {
console.error(error)
process.exitCode = 1
})