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

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

51 lines
1.2 KiB
JavaScript

const fs = require('fs/promises')
const path = require('path')
const { spawn } = require('child_process')
const repoRoot = process.cwd()
const nextBin = path.join(repoRoot, 'node_modules', 'next', 'dist', 'bin', 'next')
const tscBin = path.join(repoRoot, 'node_modules', 'typescript', 'bin', 'tsc')
function run(command, args) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
cwd: repoRoot,
stdio: 'inherit',
shell: false,
})
child.on('exit', (code) => {
if (code === 0) {
resolve()
return
}
reject(new Error(`${command} ${args.join(' ')} exited with code ${code}`))
})
})
}
async function ensureNextCacheLifeStub() {
const typesDir = path.join(repoRoot, '.next', 'types')
const cacheLifePath = path.join(typesDir, 'cache-life.d.ts')
await fs.mkdir(typesDir, { recursive: true })
try {
await fs.access(cacheLifePath)
} catch {
await fs.writeFile(cacheLifePath, '', 'utf8')
}
}
async function main() {
await run(process.execPath, [nextBin, 'typegen'])
await ensureNextCacheLifeStub()
await run(process.execPath, [tscBin, '--noEmit', '--incremental', 'false'])
}
main().catch((error) => {
console.error(error)
process.exitCode = 1
})