#!/usr/bin/env node // scripts/ci/clean-deep.mjs // 빌드 산출물, 캐시, 임시 브라우저 프로필을 일괄 제거한다 (.env, node_modules, 추적 정본 제외). import { existsSync, lstatSync, readdirSync, rmdirSync, rmSync, unlinkSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..') const dryRun = process.argv.includes('--dry-run') const RELATIVE_TARGETS = [ 'out', 'dist', 'sidecar-dist', 'test-results', 'apps/desktop/out', 'apps/desktop/dist', 'apps/desktop/build/sidecar-build', 'apps/desktop/build/sidecar.spec', 'apps/web/.next', 'apps/admin/.next', 'apps/api-server/bin', 'apps/api-server/obj', 'apps/api-server.Tests/bin', 'apps/api-server.Tests/obj', 'apps/mobile-rn/android/build', 'apps/mobile-rn/android/app/build', 'apps/mobile-rn/.maestro-output', 'site/dist', ] const ROOT_PREFIX_PATTERNS = ['.chrome-', '.playwright-'] const DANGLING_SYMLINK_TARGETS = ['apps/mobile-rn/node_modules/d3ro-voice-monorepo'] const removed = [] for (const rel of DANGLING_SYMLINK_TARGETS) { const full = join(root, rel) try { const stat = lstatSync(full) if (stat.isSymbolicLink()) { if (!dryRun) { try { rmdirSync(full) } catch { unlinkSync(full) } } removed.push(rel) } } catch { // 존재하지 않으면 무시 } } for (const rel of RELATIVE_TARGETS) { const full = join(root, rel) if (existsSync(full)) { if (!dryRun) { rmSync(full, { recursive: true, force: true }) } removed.push(rel) } } for (const entry of readdirSync(root, { withFileTypes: true })) { if (ROOT_PREFIX_PATTERNS.some((prefix) => entry.name.startsWith(prefix))) { const full = join(root, entry.name) if (!dryRun) { rmSync(full, { recursive: true, force: true }) } removed.push(entry.name) } } process.stdout.write( `${JSON.stringify({ ok: true, dryRun, removedCount: removed.length, removed })}\n`, )