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 })