@collectui/cli 0.2.35 → 0.2.37
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 +44 -7
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";
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
planManifest,
|
|
16
16
|
planScaffold,
|
|
17
17
|
runShadcnCommand,
|
|
18
|
-
SHADCN_TEMPLATES,
|
|
19
18
|
} from "../scaffold.mjs";
|
|
20
19
|
import { includeDashMcp, chooseClients, collectShadcnFlags, detectClientApp, selectLibs } from "./common.mjs";
|
|
21
20
|
|
|
@@ -102,8 +101,44 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
102
101
|
});
|
|
103
102
|
}
|
|
104
103
|
if (mode === "init" && hasComponents) {
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
}
|
|
107
142
|
}
|
|
108
143
|
if (mode === "init" && !hasComponents && nonEmpty && !flags.force) {
|
|
109
144
|
throw new CliError(`Target directory is not empty: ${displayPath(target)}`, {
|
|
@@ -253,9 +288,11 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
253
288
|
mcpServers: mcpEntries.map((e) => e.serverName),
|
|
254
289
|
next: [
|
|
255
290
|
mode === "init" && !hasComponents ? `cd ${cs.show(target)}` : null,
|
|
256
|
-
// 只有 CLI
|
|
257
|
-
//
|
|
258
|
-
install
|
|
291
|
+
// 只有 CLI 没自动装、且项目里确实没有 node_modules 才提示安装
|
|
292
|
+
// (configure 到已装过依赖的老项目不该再出现这行——2026-12-06 实报)
|
|
293
|
+
install || existsSync(join(target, "node_modules"))
|
|
294
|
+
? null
|
|
295
|
+
: `${pm} install`,
|
|
259
296
|
// 按实际选的库逐个给 add 示例——用户配了几个库就列几行
|
|
260
297
|
...units.slice(0, 3).map((u) => `cui add ${u.site} <component>`),
|
|
261
298
|
].filter(Boolean),
|