@collectui/cli 0.2.36 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.36",
3
+ "version": "0.2.37",
4
4
  "description": "One CLI for every shadcn library on CollectUI Dash — login once, configure registries & MCP, scaffold agent-ready projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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
- reporter.info(`${displayPath(target)} already has components.json — switching to configure mode (no scaffold).`);
105
- mode = "configure";
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)}`, {