@collectui/cli 0.2.10 → 0.2.11

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.10",
3
+ "version": "0.2.11",
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,6 +1,7 @@
1
1
  import { CLI_VERSION } from "../version.mjs";
2
2
  import { compareVersions, fetchLatestVersion, runManualUpdate } from "../update.mjs";
3
3
  import { CliError } from "../errors.mjs";
4
+ import * as p from "@clack/prompts";
4
5
 
5
6
  /**
6
7
  * collectui update 手动立即更新(前台,看着跑)
@@ -24,13 +25,36 @@ export async function updateCmd(flags, _rest, reporter) {
24
25
  return;
25
26
  }
26
27
 
27
- reporter.step(2, 2, `Installing @collectui/cli@latest (${CLI_VERSION} → ${latest})`);
28
- const res = runManualUpdate();
28
+ // TTY 下 spinner 转着等 npm(输出捕获不插框);headless 直接 info
29
+ if (reporter.headless) {
30
+ reporter.info(`Installing @collectui/cli@latest (${CLI_VERSION} → ${latest}) via npm …`);
31
+ const res = await runManualUpdate();
32
+ if (!res || res.status !== 0) {
33
+ throw npmFail(res);
34
+ }
35
+ if (reporter.headless) reporter.result({ ...summary, updated: true });
36
+ reporter.outro(`Updated to ${latest}. Re-run commands to pick it up.`);
37
+ return;
38
+ }
39
+
40
+ const sp = p.spinner();
41
+ sp.start(`Installing @collectui/cli@latest (${CLI_VERSION} → ${latest})`);
42
+ const res = await runManualUpdate();
29
43
  if (!res || res.status !== 0) {
30
- throw new CliError(`npm install failed${res?.status ? ` (exit ${res.status})` : ""}.`, {
31
- hint: "Run `npm i -g @collectui/cli` manually to see the npm error; check global-prefix permissions (sudo/nvm).",
32
- });
44
+ sp.stop("npm install failed", 1);
45
+ throw npmFail(res);
33
46
  }
47
+ sp.stop(`Installed ${latest}`, 0);
34
48
  if (reporter.headless) reporter.result({ ...summary, updated: true });
35
49
  reporter.outro(`Updated to ${latest}. Re-run commands to pick it up.`);
36
50
  }
51
+
52
+ function npmFail(res) {
53
+ const detail = `${res?.stderr ?? ""}${res?.stdout ?? ""}`.trim().split("\n").slice(-5).join("\n");
54
+ return new CliError(
55
+ `npm install failed${res?.status ? ` (exit ${res.status})` : ""}${detail ? `:\n${detail}` : "."}`,
56
+ {
57
+ hint: "Check global-prefix permissions (sudo/nvm), or run `npm i -g @collectui/cli` directly.",
58
+ }
59
+ );
60
+ }
package/src/update.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { spawnSync } from "node:child_process";
1
+ import { spawn } from "node:child_process";
2
2
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { configDir } from "./config.mjs";
@@ -118,8 +118,25 @@ export function startBackgroundUpdate(reporter, deps = {}) {
118
118
  return { done };
119
119
  }
120
120
 
121
- /** 手动更新(`collectui update`):前台跑,人看着进度。runner 可注入(测试)。 */
121
+ /** 手动更新(`collectui update`):异步 spawn + 捕获输出(不 inherit——往 clack 的
122
+ * frame 里插行会把边框打断;捕获后失败时调用方直接展示 stderr)。
123
+ * runner 可注入(测试):返回 { status, stdout, stderr }(或其 Promise)。 */
122
124
  export function runManualUpdate({ runner } = {}) {
123
- const run = runner ?? ((args) => spawnSync("npm", args, { stdio: "inherit", shell: process.platform === "win32" }));
124
- return run(["install", "-g", `${NPM_PACKAGE}@latest`]);
125
+ if (runner) return runner(["install", "-g", `${NPM_PACKAGE}@latest`]);
126
+ return new Promise((resolve) => {
127
+ const child = spawn("npm", ["install", "-g", `${NPM_PACKAGE}@latest`], {
128
+ stdio: ["ignore", "pipe", "pipe"],
129
+ shell: process.platform === "win32",
130
+ });
131
+ let out = "";
132
+ let err = "";
133
+ child.stdout?.on("data", (d) => {
134
+ out += d;
135
+ });
136
+ child.stderr?.on("data", (d) => {
137
+ err += d;
138
+ });
139
+ child.on("close", (code) => resolve({ status: code, stdout: out, stderr: err }));
140
+ child.on("error", (e) => resolve({ status: 1, stderr: String(e) }));
141
+ });
125
142
  }