@collectui/cli 0.2.6 → 0.2.8

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.6",
3
+ "version": "0.2.8",
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",
package/src/cli.mjs CHANGED
@@ -174,16 +174,29 @@ async function main() {
174
174
  await command.run(flags, rest, reporter);
175
175
  }
176
176
 
177
- main().catch((error) => {
178
- const exitCode = error instanceof CliError ? error.exitCode : 1;
179
- const message = error instanceof CliError ? error.message : error?.stack || String(error);
180
- const hint = error instanceof CliError ? error.hint : undefined;
181
- const json = process.env.COLLECTUI_JSON === "1" || process.argv.includes("--json");
182
- if (json) {
183
- process.stdout.write(`${JSON.stringify({ event: "error", message, hint: hint ?? null, exitCode })}\n`);
184
- } else {
185
- process.stderr.write(`✖ ${message}\n`);
186
- if (hint) process.stderr.write(` hint: ${hint}\n`);
187
- }
188
- process.exit(exitCode);
189
- });
177
+ /** 命令完成后 flush stdout 并退出:一次性进程不留后台尾巴(callback server 的
178
+ * keep-alive socket、undici 连接池等挂住 event loop 时进程会悬死不退)。 */
179
+ function flushAndExit(code = 0) {
180
+ process.stdout.write("", () => process.exit(code));
181
+ }
182
+
183
+ main()
184
+ .then(() => {
185
+ flushAndExit(process.exitCode ?? 0);
186
+ })
187
+ .catch((error) => {
188
+ const exitCode = error instanceof CliError ? error.exitCode : 1;
189
+ const message = error instanceof CliError ? error.message : error?.stack || String(error);
190
+ const hint = error instanceof CliError ? error.hint : undefined;
191
+ const json = process.env.COLLECTUI_JSON === "1" || process.argv.includes("--json");
192
+ if (json) {
193
+ process.stdout.write(`${JSON.stringify({ event: "error", message, hint: hint ?? null, exitCode })}\n`, () =>
194
+ process.exit(exitCode)
195
+ );
196
+ } else {
197
+ process.stderr.write(`✖ ${message}\n`, () => {
198
+ if (hint) process.stderr.write(` hint: ${hint}\n`, () => process.exit(exitCode));
199
+ else process.exit(exitCode);
200
+ });
201
+ }
202
+ });
@@ -104,7 +104,11 @@ function addViaRegistry({ flags, reporter, lib, rawComponents, root, cliKey, fil
104
104
 
105
105
  const command = ["npx", ...args].join(" ");
106
106
  if (flags.print) {
107
- reporter.result({ command, components: names, scopes, env: Object.keys(env), missingScopes: missing });
107
+ if (reporter.headless) {
108
+ reporter.result({ command, components: names, scopes, env: Object.keys(env), missingScopes: missing });
109
+ } else {
110
+ reporter.info(command);
111
+ }
108
112
  return { command };
109
113
  }
110
114
 
@@ -13,7 +13,7 @@ export async function loginCmd(flags, rest, reporter) {
13
13
  skipVerify: Boolean(flags["no-verify"]),
14
14
  pat: Boolean(flags.pat),
15
15
  });
16
- // 交互模式:只显示人要看的(账号已在 success 行里,这里补数量与下一步);
16
+ // 交互模式:账号已在 success 行里,数量并入 outro 即可,不再画框;
17
17
  // --json / headless 才给完整结构(Agent 消费 uid / 库清单 / key 数)
18
18
  if (reporter.headless) {
19
19
  reporter.result({
@@ -24,16 +24,12 @@ export async function loginCmd(flags, rest, reporter) {
24
24
  libraries: (me?.sites ?? []).map((s) => s.slug),
25
25
  keys: (me?.keys ?? []).length,
26
26
  });
27
- } else {
28
- reporter.result({
29
- libraries: (me?.sites ?? []).length,
30
- keys: (me?.keys ?? []).length,
31
- });
32
27
  }
33
28
  }
34
29
 
35
30
  export function logoutCmd(flags, rest, reporter) {
36
31
  logout({ reporter });
37
- reporter.result({ loggedOut: true });
32
+ // info 行 + outro 已把话说完,Result 框只留给 --json
33
+ if (reporter.headless) reporter.result({ loggedOut: true });
38
34
  reporter.outro("Logged out.");
39
35
  }
@@ -210,7 +210,12 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
210
210
  "collectui doctor",
211
211
  ].filter(Boolean),
212
212
  };
213
- reporter.result(summary);
213
+ if (reporter.headless) {
214
+ reporter.result(summary);
215
+ } else {
216
+ // TTY 下不画 Result 大框;下一步行动指引是 summary 里唯一对人有用的
217
+ reporter.note("Next steps", summary.next.join("\n"));
218
+ }
214
219
  reporter.outro(
215
220
  flags["dry-run"]
216
221
  ? "Dry run complete. Re-run without --dry-run to apply."
@@ -21,6 +21,7 @@ export async function skillCmd(flags, rest, reporter) {
21
21
  });
22
22
  cs.write(target, content, { summary: "install the CollectUI agent skill" });
23
23
  await cs.apply();
24
- reporter.result({ path: target, scope: global ? "global" : "project" });
24
+ if (reporter.headless) reporter.result({ path: target, scope: global ? "global" : "project" });
25
+ else reporter.info(`Skill written to ${target}.`);
25
26
  reporter.outro("Skill installed. Claude Code picks it up automatically.");
26
27
  }
@@ -14,7 +14,7 @@ export async function updateCmd(flags, _rest, reporter) {
14
14
  throw new CliError("--off and --on are mutually exclusive.", { code: 2 });
15
15
  }
16
16
  const next = writeConfig({ autoUpdate: !flags.off });
17
- reporter.result({ autoUpdate: next.autoUpdate !== false });
17
+ if (reporter.headless) reporter.result({ autoUpdate: next.autoUpdate !== false });
18
18
  reporter.outro(next.autoUpdate !== false ? "Auto-update enabled." : "Auto-update disabled (still notifies on new versions).");
19
19
  return;
20
20
  }
@@ -25,13 +25,13 @@ export async function updateCmd(flags, _rest, reporter) {
25
25
  const summary = { current: CLI_VERSION, latest, updateAvailable: cmp > 0 };
26
26
 
27
27
  if (cmp <= 0) {
28
- reporter.result(summary);
28
+ if (reporter.headless) reporter.result(summary);
29
29
  reporter.outro(`Already on the latest version (${CLI_VERSION}).`);
30
30
  return;
31
31
  }
32
32
 
33
33
  if (flags.check) {
34
- reporter.result(summary);
34
+ if (reporter.headless) reporter.result(summary);
35
35
  reporter.outro(`Update available: ${CLI_VERSION} → ${latest} (re-run without --check to install).`);
36
36
  return;
37
37
  }
@@ -43,6 +43,6 @@ export async function updateCmd(flags, _rest, reporter) {
43
43
  hint: "Run `npm i -g @collectui/cli` manually to see the npm error; check global-prefix permissions (sudo/nvm).",
44
44
  });
45
45
  }
46
- reporter.result({ ...summary, updated: true });
46
+ if (reporter.headless) reporter.result({ ...summary, updated: true });
47
47
  reporter.outro(`Updated to ${latest}. Re-run commands to pick it up.`);
48
48
  }
package/src/login.mjs CHANGED
@@ -189,6 +189,13 @@ export function startCallbackServer({ state } = {}) {
189
189
  return listening;
190
190
  },
191
191
  close() {
192
+ // 浏览器对回调的 keep-alive 连接会挂住 event loop(server.close() 只停
193
+ // 接新连接、不断旧连接)——登录完成瞬间强断,否则进程悬死不退
194
+ try {
195
+ server.closeAllConnections?.();
196
+ } catch {
197
+ // Node <18.2 无此方法
198
+ }
192
199
  try {
193
200
  server.close();
194
201
  } catch {