@collectui/cli 0.2.16 → 0.2.17

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.16",
4
- "description": "One CLI for every shadcn library on CollectUI Dash — login once, configure registries & MCP, scaffold agent-ready projects.",
3
+ "version": "0.2.17",
4
+ "description": "One CLI for every shadcn library on CollectUI Dash \u2014 login once, configure registries & MCP, scaffold agent-ready projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
package/src/catalog.mjs CHANGED
@@ -1,10 +1,17 @@
1
+ import { dashUrl } from "./config.mjs";
2
+ import { jsonRequest } from "./http.mjs";
3
+
1
4
  /**
2
- * CollectUI Dash 的 shadcn 库目录(内置快照)。
5
+ * CollectUI Dash 的 shadcn 库目录。
6
+ *
7
+ * 权威源是 Dash 的公开端点 GET /api/libs(与 Dash 站点卡「AI Tools / Copy to
8
+ * Agent」同源:lib/ai-tools/libs.ts + packages/config/mcp-products.ts)——新上库
9
+ * 只改 Dash 一处,CLI 不发版自动包含;停用站在 sites 表标 retired 即自动消失。
3
10
  *
4
- * 数据源与 Dash 站点卡「AI Tools / Copy to Agent」同源(lib/ai-tools/libs.ts +
5
- * packages/config/mcp-products.ts)。CLI 内置一份是为了在无网时也能「预览计划」,
6
- * 实际密钥与授权仍以 /api/me 为准。新增库 = 在 LIBS 加一项;改 registry 路径/
7
- * env 名时须同步 Dash,否则两者配置不一致。
11
+ * 本文件内置的 LIBS / MCP_PRODUCTS 只是离线与旧 Dash 的兜底快照(远端不可达
12
+ * 时目录仍可用),运行时由 activateCatalog() 用远端目录覆盖/扩充。registry
13
+ * 条目的 url 字段(完整 URL 模板)覆盖默认的 /api/r/<source>/ 拼接——独立
14
+ * 域名 registry(如 boardui.collectui.pro)用它。
8
15
  */
9
16
 
10
17
  /** MCP 产品(由 MCP_PRODUCTS 抄录,server 名/端点/stdio 包名逐一核对)。 */
@@ -302,6 +309,37 @@ export const LIBS = [
302
309
  mcp: "motion-plus",
303
310
  verify: ["@motion/hero-parallax-layers"],
304
311
  },
312
+ {
313
+ site: "aceternity",
314
+ siteName: "Aceternity",
315
+ source: "aceternity",
316
+ registries: [
317
+ {
318
+ scope: "@aceternity",
319
+ path: "{name}.json",
320
+ headers: { Authorization: "Bearer ${ACETERNITY_API_KEY}" },
321
+ },
322
+ ],
323
+ env: [{ name: "ACETERNITY_API_KEY", from: "cliKey" }],
324
+ shadcnUiMcp: true,
325
+ verify: ["@aceternity/3d-card"],
326
+ },
327
+ {
328
+ site: "boardui",
329
+ siteName: "BoardUI",
330
+ source: "boardui",
331
+ registries: [
332
+ {
333
+ scope: "@boardui",
334
+ url: "https://boardui.collectui.pro/r/{name}.json",
335
+ headers: { Authorization: "Bearer ${BOARDUI_API_KEY}" },
336
+ },
337
+ ],
338
+ env: [{ name: "BOARDUI_API_KEY", from: "cliKey" }],
339
+ shadcnUiMcp: true,
340
+ verify: ["@boardui/theme"],
341
+ freeVerify: ["@boardui/theme"],
342
+ },
305
343
  {
306
344
  site: "21st",
307
345
  siteName: "21st",
@@ -316,6 +354,79 @@ export const LIBS = [
316
354
  },
317
355
  ];
318
356
 
357
+ /* ── 动态目录层 ──────────────────────────────────────────────────────────
358
+ * GET /api/libs(Dash 公开端点)→ { libs, mcpProducts, shadcnMcp, retiredSlugs }。
359
+ * ensureCatalog() 在命令入口调用一次:拉远端 → activateCatalog 合并;失败降级
360
+ * 静态兜底(目录可用性优先,绝不因目录端点挂了而挡命令)。
361
+ */
362
+
363
+ /** 兜底停用名单(远端不可达时生效;远端以 sites 表 retired 字段为准)。 */
364
+ export const RETIRED_FALLBACK = ["hero", "io"];
365
+
366
+ let active = null;
367
+ let pending = null;
368
+
369
+ export function activeCatalog() {
370
+ return (
371
+ active ?? {
372
+ libs: LIBS,
373
+ mcpProducts: MCP_PRODUCTS,
374
+ retiredSlugs: RETIRED_FALLBACK,
375
+ remote: false,
376
+ }
377
+ );
378
+ }
379
+
380
+ /** 远端目录 + 静态兜底合并:远端条目按 site 覆盖/追加,静态多出的保留
381
+ * (旧 Dash 与新 CLI 并存的窗口期不丢库);retiredSlugs 取并集。 */
382
+ export function mergeCatalog(remote) {
383
+ if (!remote || !Array.isArray(remote.libs)) return activeCatalog();
384
+ const bySite = new Map(LIBS.map((lib) => [lib.site, lib]));
385
+ for (const lib of remote.libs) {
386
+ if (lib && typeof lib.site === "string") bySite.set(lib.site, lib);
387
+ }
388
+ const products = { ...MCP_PRODUCTS };
389
+ for (const p of remote.mcpProducts ?? []) {
390
+ if (p && p.id) products[p.id] = p;
391
+ }
392
+ return {
393
+ libs: [...bySite.values()],
394
+ mcpProducts: products,
395
+ retiredSlugs: [
396
+ ...new Set([...(remote.retiredSlugs ?? []), ...RETIRED_FALLBACK]),
397
+ ],
398
+ remote: true,
399
+ };
400
+ }
401
+
402
+ /** 进程内只拉一次;失败返回 null(调用方降级静态兜底,verbose 下提一句)。 */
403
+ export async function fetchCatalog({ reporter } = {}) {
404
+ if (!pending) {
405
+ pending = jsonRequest(`${dashUrl()}/api/libs`, {
406
+ label: "dash /api/libs",
407
+ timeout: 8_000,
408
+ retries: 1,
409
+ reporter,
410
+ }).catch((error) => {
411
+ reporter?.info?.(`Catalog endpoint unavailable (${error.message}); using built-in snapshot.`);
412
+ return null;
413
+ });
414
+ }
415
+ return pending;
416
+ }
417
+
418
+ /** 激活目录(ensureCatalog 内部用;导出供测试注入/还原)。 */
419
+ export function activateCatalog(catalog) {
420
+ active = catalog;
421
+ return active;
422
+ }
423
+
424
+ /** 命令入口调用:拉远端目录并激活合并结果(幂等)。 */
425
+ export async function ensureCatalog({ reporter } = {}) {
426
+ const remote = await fetchCatalog({ reporter });
427
+ return activateCatalog(mergeCatalog(remote));
428
+ }
429
+
319
430
  /**
320
431
  * 按 slug/别名找库。
321
432
  * @param {string} slug
@@ -323,7 +434,7 @@ export const LIBS = [
323
434
  */
324
435
  export function libBySlug(slug) {
325
436
  const needle = String(slug || "").toLowerCase();
326
- for (const lib of LIBS) {
437
+ for (const lib of activeCatalog().libs) {
327
438
  if (lib.site.toLowerCase() === needle) return lib;
328
439
  if (lib.source && lib.source.toLowerCase() === needle) return lib;
329
440
  }
@@ -331,14 +442,21 @@ export function libBySlug(slug) {
331
442
  }
332
443
 
333
444
  export function allSlugs() {
334
- return LIBS.map((lib) => lib.site);
445
+ return activeCatalog().libs.map((lib) => lib.site);
446
+ }
447
+
448
+ /** 停用站集合(Dash sites 表 retired;尾部提示据此过滤)。 */
449
+ export function retiredSlugs() {
450
+ return new Set(activeCatalog().retiredSlugs);
335
451
  }
336
452
 
337
453
  /** 用户拥有的库(site 授权或已绑定任意 key)。 */
338
454
  export function ownedLibs(me) {
339
455
  const sites = new Set((me?.sites ?? []).map((s) => s.slug));
340
456
  const keySites = new Set((me?.keys ?? []).map((k) => k.site).filter(Boolean));
341
- return LIBS.filter((lib) => sites.has(lib.site) || keySites.has(lib.site));
457
+ return activeCatalog().libs.filter(
458
+ (lib) => sites.has(lib.site) || keySites.has(lib.site)
459
+ );
342
460
  }
343
461
 
344
462
  export function keyEntriesFor(me, site) {
@@ -353,6 +471,8 @@ export function resolveLibKeys(lib, me) {
353
471
  }
354
472
 
355
473
  export function registryUrl(source, registry, base) {
474
+ // 独立域名 registry(RegistrySpec.url 完整模板,如 boardui)不走 shadcn-proxy 拼接
475
+ if (registry.url) return registry.url;
356
476
  const path = registry.path ?? "{name}.json";
357
477
  return `${base.replace(/\/+$/, "")}/api/r/${source}/${path}`;
358
478
  }
@@ -371,9 +491,9 @@ export function envValue(env, cliKey) {
371
491
  return env.from === "cliKey" ? (cliKey ?? "") : (env.value ?? "");
372
492
  }
373
493
 
374
- /** MCP 产品定义;未知 id 返回 null(配置时跳过并报告)。 */
494
+ /** MCP 产品定义(动态目录优先,静态兜底);未知 id 返回 null(配置时跳过并报告)。 */
375
495
  export function mcpProduct(id) {
376
- return id ? MCP_PRODUCTS[id] ?? null : null;
496
+ return id ? activeCatalog().mcpProducts[id] ?? null : null;
377
497
  }
378
498
 
379
499
  /** 配置单元:目录里每个库就是一个单元(保留导出供调用方按库遍历)。 */
package/src/cli.mjs CHANGED
@@ -15,6 +15,7 @@ import { collectSecrets, readConfig, resolveToken } from "./config.mjs";
15
15
  import { CliError, usageError } from "./errors.mjs";
16
16
  import { createReporter } from "./report.mjs";
17
17
  import { startBackgroundUpdate } from "./update.mjs";
18
+ import { ensureCatalog } from "./catalog.mjs";
18
19
  import { showBanner } from "./banner.mjs";
19
20
  import { loginCmd, logoutCmd } from "./commands/login.mjs";
20
21
  import { whoamiCmd } from "./commands/whoami.mjs";
@@ -117,6 +118,9 @@ function findCommand(name) {
117
118
  return null;
118
119
  }
119
120
 
121
+ /** 纯本地/纯账号命令不拉动态目录(省一次网络等待)。 */
122
+ const CATALOG_SKIP = new Set(["login", "logout", "whoami", "update"]);
123
+
120
124
  function printHelp() {
121
125
  process.stdout.write(HELP);
122
126
  }
@@ -165,6 +169,9 @@ async function main() {
165
169
  if (token) reporter.addSecrets([token]);
166
170
 
167
171
  showBanner(reporter); // 开机画面:任何子命令(headless/--version/help 已在前面分流)
172
+ // 动态目录(Dash GET /api/libs):新上库自动包含、停用站自动剔除;失败降级
173
+ // 内置快照(目录可用性优先)——与更新检查互不影响
174
+ if (!CATALOG_SKIP.has(name)) await ensureCatalog({ reporter });
168
175
  // 更新检查:与命令并行即时异步查一次 npm(TTY 才查),有新版打一行提醒;
169
176
  // 手动 update 命令自身不触发(避免与前台安装并发写全局目录)
170
177
  const updateNotice =
@@ -102,7 +102,9 @@ function addViaRegistry({ flags, reporter, lib, rawComponents, root, cliKey, fil
102
102
  }
103
103
  }
104
104
 
105
- const command = ["npx", ...args].join(" ");
105
+ // npx -y:非交互环境(headless/CI)下 npx 会因「Ok to proceed?」确认挂死,
106
+ // -y 自动确认下载(2026-12-01 boardui 真机实测踩坑)
107
+ const command = ["npx", "-y", ...args].join(" ");
106
108
  if (flags.print) {
107
109
  if (reporter.headless) {
108
110
  reporter.result({ command, components: names, scopes, env: Object.keys(env), missingScopes: missing });
@@ -131,7 +133,7 @@ function addViaRegistry({ flags, reporter, lib, rawComponents, root, cliKey, fil
131
133
  summary: `auto-configure ${lib.siteName} registry scope(s): ${missing.join(", ")}`,
132
134
  });
133
135
  }
134
- cs.run("npx", args, { cwd: root, env, summary: `install ${names.join(", ")}` });
136
+ cs.run("npx", ["-y", ...args], { cwd: root, env, summary: `install ${names.join(", ")}` });
135
137
  return cs.apply();
136
138
  }
137
139
 
@@ -1,7 +1,7 @@
1
1
  import * as p from "@clack/prompts";
2
2
  import { listFlag } from "../args.mjs";
3
3
  import {
4
- LIBS,
4
+ activeCatalog,
5
5
  allSlugs,
6
6
  configUnits,
7
7
  libBySlug,
@@ -114,7 +114,7 @@ export function libLabel(lib) {
114
114
  }
115
115
 
116
116
  export function catalogSummary() {
117
- return LIBS.map((lib) => ({
117
+ return activeCatalog().libs.map((lib) => ({
118
118
  site: lib.site,
119
119
  name: lib.siteName,
120
120
  source: lib.source,
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { join, resolve } from "node:path";
3
- import { LIBS, ownedLibs, registryUrl, resolveLibKeys } from "../catalog.mjs";
3
+ import { activeCatalog, ownedLibs, registryUrl, resolveLibKeys } from "../catalog.mjs";
4
4
  import { registryUrl as registryBase, resolveToken, tokenSource } from "../config.mjs";
5
5
  import { httpRequest } from "../http.mjs";
6
6
  import { dashMcpTools, fetchMe } from "../dash.mjs";
@@ -58,7 +58,7 @@ export async function doctorCmd(flags, rest, reporter) {
58
58
  const envPath = join(root, ".env.local");
59
59
  const env = existsSync(envPath) ? parseEnvText(readFileSync(envPath, "utf8")) : {};
60
60
  const missing = [];
61
- for (const lib of LIBS) {
61
+ for (const lib of activeCatalog().libs) {
62
62
  if (!scopes.some((scope) => (lib.registries ?? []).some((r) => r.scope === scope))) continue;
63
63
  for (const spec of lib.env ?? []) {
64
64
  if (spec.from === "cliKey" && !env[spec.name]) missing.push(`${lib.site}:${spec.name}`);
@@ -1,4 +1,4 @@
1
- import { LIBS, ownedLibs, resolveLibKeys } from "../catalog.mjs";
1
+ import { activeCatalog, ownedLibs, resolveLibKeys, retiredSlugs } from "../catalog.mjs";
2
2
  import { formatTable, startSpin } from "../report.mjs";
3
3
  import { loadMe } from "./common.mjs";
4
4
 
@@ -19,16 +19,19 @@ export async function libsCmd(flags, rest, reporter) {
19
19
  }
20
20
 
21
21
  const owned = me ? new Set(ownedLibs(me).map((lib) => lib.site)) : null;
22
- // 账号里拥有但不属于 shadcn registry 体系的库(自带独立安装器,如 threeui/heroui/
23
- // aura)——本 CLI 管不到,但必须点名说明,不然用户以为少了
22
+ // 账号里拥有但不属于 shadcn registry 体系的库(自带独立安装器,如 threeui/
23
+ // heroui v3/aura)——本 CLI 管不到,但必须点名说明,不然用户以为少了。
24
+ // 停用站(Dash sites 表 retired,如 hero v2 / io)不再点名。
25
+ const LIBS = activeCatalog().libs;
24
26
  const knownSites = new Set(LIBS.map((lib) => lib.site));
27
+ const retired = retiredSlugs();
25
28
  const extraOwned = me
26
29
  ? [
27
30
  ...new Set([
28
31
  ...(me.sites ?? []).map((s) => s.slug),
29
32
  ...(me.keys ?? []).map((k) => k.site).filter(Boolean),
30
33
  ]),
31
- ].filter((slug) => !knownSites.has(slug))
34
+ ].filter((slug) => !knownSites.has(slug) && !retired.has(slug))
32
35
  : [];
33
36
  const rows = [];
34
37
 
package/src/report.mjs CHANGED
@@ -222,23 +222,36 @@ export function formatTable(rows, columns) {
222
222
  }
223
223
 
224
224
  /**
225
- * 行内覆写式 spinner:braille 帧 + `\r\x1b[K` 单次整串写入(不做整行
226
- * clear + 光标复位,那是 clack spinner 在部分终端闪烁的根源)。
227
- * 仅 TTY 用;stop(finalMessage) 清行后打印终态(省略则只清行)。
225
+ * 行内覆写式 spinner(零闪烁三原则):
226
+ * 1. 不擦行——`\x1b[K` 每帧先擦后写,擦除→空白的空窗在部分终端被渲染成
227
+ * 一帧空行,这就是「整行在闪」。改为首帧铺满整行,后续帧 `\r` 回行首
228
+ * 等长覆写(braille 帧全部单列等宽,每帧渲染串严格等长,必然盖满旧行)。
229
+ * 2. 隐藏光标——不藏的话块状光标每帧在行首/行尾来回跳,观感同闪。
230
+ * stop 恢复;进程意外退出由 exit 钩子兜底恢复,终端不会丢光标。
231
+ * 3. 单次 write 整串——不拆多次写,避免终端分批渲染出中间态。
232
+ * 仅 TTY 用;stop(finalMessage) 清行后打印终态(省略则只清行),幂等。
228
233
  */
229
- export function startSpin(message) {
230
- if (!process.stdout.isTTY) return { stop: () => {} };
234
+ export function startSpin(message, { stream = process.stdout, interval = 90 } = {}) {
235
+ if (!stream.isTTY) return { stop: () => {} };
231
236
  const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
237
+ const render = (frame) => `${frame} ${message}`;
232
238
  let i = 0;
239
+ let stopped = false;
240
+ const restoreCursor = () => stream.write("\x1b[?25h");
241
+ process.once("exit", restoreCursor);
242
+ stream.write(`\x1b[?25l${render(frames[0])}`);
233
243
  const timer = setInterval(() => {
234
- process.stdout.write(`\r\x1b[K${frames[i % frames.length]} ${message}`);
235
244
  i += 1;
236
- }, 90);
245
+ stream.write(`\r${render(frames[i % frames.length])}`);
246
+ }, interval);
237
247
  return {
238
248
  stop(finalMessage) {
249
+ if (stopped) return;
250
+ stopped = true;
239
251
  clearInterval(timer);
240
- process.stdout.write(`\r\x1b[K`);
241
- if (finalMessage != null) console.log(finalMessage);
252
+ process.removeListener("exit", restoreCursor);
253
+ stream.write(`\r\x1b[K\x1b[?25h`);
254
+ if (finalMessage != null) stream.write(`${finalMessage}\n`);
242
255
  },
243
256
  };
244
257
  }