import { readManifest, removeInstall, tildify, type Scope, type TargetId } from "@designpaca/core"; import { dim, heading, info, ok, warn } from "../ui.ts"; export async function runUninstall(opts: { targets?: TargetId[]; /** 직접 지정했을 때만 넘긴다 — 기본값으로 걸러 내면 project 설치를 놓친다 */ scope?: Scope; force?: boolean; dryRun?: boolean; }): Promise { const manifest = await readManifest(); const targets = manifest.installs.filter( (i) => (!opts.targets || opts.targets.length === 0 || opts.targets.includes(i.target)) && (opts.scope === undefined || i.scope === opts.scope), ); if (targets.length === 0) { console.log(warn("제거할 설치 기록이 없습니다")); return 0; } console.log(heading(opts.dryRun ? "제거 계획" : "제거")); let code = 0; for (const rec of targets) { const res = await removeInstall(rec, { force: opts.force, dryRun: opts.dryRun }); const verb = opts.dryRun ? "제거할 파일" : "제거"; console.log(ok(`${rec.target} (${rec.scope}) — ${verb} ${res.removed.length}개 ${dim(tildify(rec.root))}`)); if (res.keptModified.length > 0) { const tense = opts.dryRun ? "남긴다" : "남겼다"; console.log( warn(` 직접 수정한 파일 ${res.keptModified.length}개는 ${tense} (--force 로 함께 지운다)`), ); for (const p of res.keptModified.slice(0, 5)) console.log(dim(` ${tildify(p)}`)); } if (res.sharedKept.length > 0) { console.log(info(` 다른 대상과 공유 중이라 남긴 파일 ${res.sharedKept.length}개 (그 대상을 제거할 때 함께 지워진다)`)); for (const p of res.sharedKept.slice(0, 5)) console.log(dim(` ${tildify(p)}`)); } if (res.refused.length > 0) { code = 1; console.log( warn(` 설치 기록과 맞지 않아 손대지 않은 파일 ${res.refused.length}개 (기록 밖 경로·링크·꼬인 마커)`), ); for (const p of res.refused.slice(0, 5)) console.log(dim(` ${tildify(p)}`)); } } return code; }