fix(core,cli): harden install engine and argument parsing
- Reject unknown flags with exit 2 and never write on --dry-run, even in a TTY - Treat files already matching the new content as up to date after an interrupted update - Remove unmodified orphan files from older versions, keep and report modified ones and shared paths - Degrade malformed manifests instead of blocking installs; readIfExists only maps ENOENT/ENOTDIR to null - Block downgrades from older CLIs (semver), honor uninstall --scope, dedupe targets, fix next-step output and table width - Deeper package verification, LF normalization for .mjs, MIT LICENSE
This commit is contained in:
parent
97f2c241e4
commit
eecd3f03ff
29 changed files with 867 additions and 124 deletions
|
|
@ -12,7 +12,7 @@ import {
|
|||
} from "@designpaca/core";
|
||||
import { getSkill } from "../skill.ts";
|
||||
import { runInstall, printNextSteps, printOutcomes } from "../commands/install.ts";
|
||||
import { accent, bold, dim } from "../ui.ts";
|
||||
import { accent, bad, bold, dim, warn } from "../ui.ts";
|
||||
|
||||
/** 선택한 범위를 어댑터가 지원하지 않으면 지원 가능한 범위로 낮춘다 */
|
||||
function effectiveScope(target: TargetId, wanted: Scope): Scope {
|
||||
|
|
@ -20,7 +20,15 @@ function effectiveScope(target: TargetId, wanted: Scope): Scope {
|
|||
return a.scopes.includes(wanted) ? wanted : (a.scopes[0] as Scope);
|
||||
}
|
||||
|
||||
export async function onboard(): Promise<number> {
|
||||
export interface OnboardOptions {
|
||||
/** 쓰지 않고 계획만 보여 준다 — 터미널에서도 실제 설치로 빠지지 않는다 */
|
||||
dryRun?: boolean;
|
||||
force?: boolean;
|
||||
/** 명령줄에서 직접 지정한 범위. 있으면 범위 질문을 건너뛴다 */
|
||||
scope?: Scope;
|
||||
}
|
||||
|
||||
export async function onboard(opts: OnboardOptions = {}): Promise<number> {
|
||||
const skill = await getSkill();
|
||||
|
||||
console.clear();
|
||||
|
|
@ -53,23 +61,26 @@ export async function onboard(): Promise<number> {
|
|||
});
|
||||
if (p.isCancel(targets)) return cancel();
|
||||
|
||||
const wanted = await p.select<Scope>({
|
||||
message: "어느 범위에 설치할까요?",
|
||||
options: [
|
||||
{
|
||||
value: "user",
|
||||
label: "전역 (권장)",
|
||||
hint: "홈 디렉터리에 두어 모든 프로젝트에서 쓸 수 있습니다",
|
||||
},
|
||||
{
|
||||
value: "project",
|
||||
label: "이 프로젝트만",
|
||||
hint: `${tildify(process.cwd())} · 팀과 함께 쓰려면 이쪽이 좋습니다`,
|
||||
},
|
||||
],
|
||||
initialValue: "user",
|
||||
});
|
||||
if (p.isCancel(wanted)) return cancel();
|
||||
const picked = opts.scope
|
||||
? opts.scope
|
||||
: await p.select<Scope>({
|
||||
message: "어느 범위에 설치할까요?",
|
||||
options: [
|
||||
{
|
||||
value: "user",
|
||||
label: "전역 (권장)",
|
||||
hint: "홈 디렉터리에 두어 모든 프로젝트에서 쓸 수 있습니다",
|
||||
},
|
||||
{
|
||||
value: "project",
|
||||
label: "이 프로젝트만",
|
||||
hint: `${tildify(process.cwd())} · 팀과 함께 쓰려면 이쪽이 좋습니다`,
|
||||
},
|
||||
],
|
||||
initialValue: "user",
|
||||
});
|
||||
if (p.isCancel(picked)) return cancel();
|
||||
const wanted: Scope = picked;
|
||||
|
||||
// 범위가 낮춰진 타깃이 있으면 미리 알린다 — 설치 후에 "왜 여기 깔렸지"가 되지 않게
|
||||
const downgraded = targets.filter((t) => effectiveScope(t, wanted) !== wanted);
|
||||
|
|
@ -112,6 +123,19 @@ export async function onboard(): Promise<number> {
|
|||
"이렇게 설치됩니다",
|
||||
);
|
||||
|
||||
if (opts.dryRun) {
|
||||
// 계획만 보여 주고 끝낸다 — 확인 질문도, 도구 제안도 하지 않는다
|
||||
const planned = [];
|
||||
for (const t of targets) {
|
||||
planned.push(
|
||||
...(await runInstall({ targets: [t], scope: effectiveScope(t, wanted), force: opts.force, dryRun: true })),
|
||||
);
|
||||
}
|
||||
printOutcomes(planned, true);
|
||||
p.outro(dim("--dry-run: 아무것도 쓰지 않았습니다"));
|
||||
return planned.some((o) => o.blocked) ? 1 : 0;
|
||||
}
|
||||
|
||||
const go = await p.confirm({ message: "이대로 진행할까요?", initialValue: true });
|
||||
if (p.isCancel(go) || !go) return cancel();
|
||||
|
||||
|
|
@ -122,7 +146,7 @@ export async function onboard(): Promise<number> {
|
|||
for (const t of targets) {
|
||||
const scope = effectiveScope(t, wanted);
|
||||
s.message(`${getAdapter(t).label} 에 설치하고 있습니다`);
|
||||
outcomes.push(...(await runInstall({ targets: [t], scope })));
|
||||
outcomes.push(...(await runInstall({ targets: [t], scope, force: opts.force })));
|
||||
}
|
||||
s.stop("설치가 끝났습니다");
|
||||
} catch (err) {
|
||||
|
|
@ -133,10 +157,21 @@ export async function onboard(): Promise<number> {
|
|||
|
||||
printOutcomes(outcomes);
|
||||
|
||||
// 막힌 대상에는 "다음 단계"도 "준비됐습니다"도 말하지 않는다
|
||||
const installed = outcomes.filter((o) => !o.blocked).map((o) => o.target);
|
||||
if (installed.length === 0) {
|
||||
p.outro(bad("설치하지 못했습니다 — 위 메시지를 확인해 주세요"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
await offerTools();
|
||||
|
||||
printNextSteps(targets);
|
||||
printNextSteps(installed);
|
||||
|
||||
if (installed.length < outcomes.length) {
|
||||
p.outro(warn("일부 대상은 설치하지 못했습니다 — 위 메시지를 확인해 주세요"));
|
||||
return 1;
|
||||
}
|
||||
p.outro(`${accent("designpaca")} 준비됐습니다 — 만들고 싶은 것을 말씀해 주세요`);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue