@collectui/cli 0.2.36 → 0.2.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/setup.mjs +42 -4
package/package.json
CHANGED
package/src/commands/setup.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { protectGit } from "../git-privacy.mjs";
|
|
2
|
-
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { existsSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { basename, join, resolve } from "node:path";
|
|
5
5
|
import { ChangeSet, displayPath } from "../changes.mjs";
|
|
@@ -101,8 +101,44 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
if (mode === "init" && hasComponents) {
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
// 已有项目:问是新增还是替换(2026-12-06 用户定案,默认新增)——
|
|
105
|
+
// headless/--yes 无交互,默认新增(续配);JSON 输出不受影响
|
|
106
|
+
let choice = "add";
|
|
107
|
+
if (!reporter.headless && !reporter.yes) {
|
|
108
|
+
choice =
|
|
109
|
+
(await reporter.select(
|
|
110
|
+
`${displayPath(target)} already has a project — add to it or start over?`,
|
|
111
|
+
[
|
|
112
|
+
{
|
|
113
|
+
value: "add",
|
|
114
|
+
label: "Add to it — merge registries / keys / MCP, keep files",
|
|
115
|
+
},
|
|
116
|
+
{ value: "replace", label: "Start over — delete and re-scaffold" },
|
|
117
|
+
]
|
|
118
|
+
)) ?? "add";
|
|
119
|
+
}
|
|
120
|
+
if (choice === "replace") {
|
|
121
|
+
// 显式目录删除需二次确认(默认拒);OS 临时目录直接删(语义即重开)
|
|
122
|
+
const isTmp = target.startsWith(tmpdir());
|
|
123
|
+
if (
|
|
124
|
+
!isTmp &&
|
|
125
|
+
!(await reporter.confirm(
|
|
126
|
+
`Delete ${displayPath(target)} entirely? This cannot be undone.`,
|
|
127
|
+
{ defaultValue: false }
|
|
128
|
+
))
|
|
129
|
+
) {
|
|
130
|
+
reporter.info("Aborted — nothing deleted.");
|
|
131
|
+
return { target, mode, libraries: [], aborted: true };
|
|
132
|
+
}
|
|
133
|
+
rmSync(target, { recursive: true, force: true });
|
|
134
|
+
reporter.info(`Removed ${displayPath(target)} — starting over.`);
|
|
135
|
+
hasComponents = false;
|
|
136
|
+
} else {
|
|
137
|
+
reporter.info(
|
|
138
|
+
`${displayPath(target)} already has components.json — adding to it (configure mode, no scaffold).`
|
|
139
|
+
);
|
|
140
|
+
mode = "configure";
|
|
141
|
+
}
|
|
106
142
|
}
|
|
107
143
|
if (mode === "init" && !hasComponents && nonEmpty && !flags.force) {
|
|
108
144
|
throw new CliError(`Target directory is not empty: ${displayPath(target)}`, {
|
|
@@ -251,7 +287,9 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
251
287
|
mcpClients: clients,
|
|
252
288
|
mcpServers: mcpEntries.map((e) => e.serverName),
|
|
253
289
|
next: [
|
|
254
|
-
|
|
290
|
+
// 不在目标目录才提示 cd(在项目里跑就不必;configure 远处项目同样给——
|
|
291
|
+
// 2026-12-06 用户定案)
|
|
292
|
+
process.cwd() !== target ? `cd ${cs.show(target)}` : null,
|
|
255
293
|
// 只有 CLI 没自动装、且项目里确实没有 node_modules 才提示安装
|
|
256
294
|
// (configure 到已装过依赖的老项目不该再出现这行——2026-12-06 实报)
|
|
257
295
|
install || existsSync(join(target, "node_modules"))
|