@collectui/bdui 0.2.1 → 0.2.3
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/add.js +42 -6
- package/src/auth.js +23 -1
- package/src/registry.js +12 -2
package/package.json
CHANGED
package/src/add.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { spawn } from "child_process";
|
|
4
4
|
import ora from "ora";
|
|
5
|
-
import { readSavedKey, resolveKey } from "./auth.js";
|
|
5
|
+
import { promptAndSaveKey, readSavedKey, resolveKey } from "./auth.js";
|
|
6
6
|
import c from "./color.js";
|
|
7
7
|
import { itemHints } from "./hints.js";
|
|
8
8
|
import { detectProject, installCommand } from "./project.js";
|
|
@@ -15,6 +15,15 @@ export function pkgBaseName(dep) {
|
|
|
15
15
|
return i === -1 ? dep : dep.slice(0, i);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const BDUI_SCOPE = "@boardui/";
|
|
19
|
+
|
|
20
|
+
/** registry 条目名归一:服务端为 shadcn CLI 兼容会把裸名依赖改写成 @boardui/<name>
|
|
21
|
+
* 路由 scope(boardui.collectui.pro 出口重写,2026-12-01 起),而本 CLI 的索引/条目
|
|
22
|
+
* 名恒为裸名——闭包解析与命令行入参统一先剥 scope,两种服务端形态都吃得下。 */
|
|
23
|
+
export function bareItemName(name) {
|
|
24
|
+
return name.startsWith(BDUI_SCOPE) ? name.slice(BDUI_SCOPE.length) : name;
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export async function installPackages(pm, packages, cwd) {
|
|
19
28
|
if (!packages.length) return;
|
|
20
29
|
const [command, args] = installCommand(pm, packages);
|
|
@@ -52,7 +61,10 @@ export async function cmdAdd(names, flags) {
|
|
|
52
61
|
);
|
|
53
62
|
|
|
54
63
|
const index = await fetchIndex(true);
|
|
55
|
-
|
|
64
|
+
// 入参也过一遍归一:从 shadcn 侧文档/命令抄来的 @boardui/<name> 形态直接可用
|
|
65
|
+
const wanted = (
|
|
66
|
+
flags.all ? index.items.map((i) => i.name) : names
|
|
67
|
+
).map(bareItemName);
|
|
56
68
|
|
|
57
69
|
if (!wanted.length) {
|
|
58
70
|
console.log(
|
|
@@ -62,20 +74,44 @@ export async function cmdAdd(names, flags) {
|
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
// 递归收集:name → item(公共 + pro),依赖闭包先装;pro 的 key 三级解析(flag/env/login 落盘)
|
|
65
|
-
|
|
77
|
+
let key = resolveKey(flags.key);
|
|
66
78
|
const resolved = new Map();
|
|
67
79
|
const missing = [];
|
|
68
|
-
|
|
80
|
+
let promptedForKey = false;
|
|
81
|
+
async function collect(rawName) {
|
|
82
|
+
const name = bareItemName(rawName);
|
|
69
83
|
if (resolved.has(name)) return;
|
|
70
84
|
const meta = index.items.find((i) => i.name === name);
|
|
71
85
|
if (!meta) {
|
|
72
86
|
missing.push(name);
|
|
73
87
|
return;
|
|
74
88
|
}
|
|
75
|
-
|
|
89
|
+
let item = null;
|
|
90
|
+
try {
|
|
91
|
+
item = await fetchItem(name, key);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
// Pro 条目撞上无 key:TTY 下就地补一次(输入→验证→落盘→重试),
|
|
94
|
+
// 客户冷机第一条命令即可装完,不必先知道 login 子命令(2026-12-02 客户实踩)
|
|
95
|
+
if (
|
|
96
|
+
error?.code === "PRO_KEY_MISSING" &&
|
|
97
|
+
!promptedForKey &&
|
|
98
|
+
process.stdin.isTTY
|
|
99
|
+
) {
|
|
100
|
+
promptedForKey = true;
|
|
101
|
+
const saved = await promptAndSaveKey();
|
|
102
|
+
if (saved.ok) {
|
|
103
|
+
key = saved.key;
|
|
104
|
+
item = await fetchItem(name, key);
|
|
105
|
+
} else if (saved.message) {
|
|
106
|
+
// 主动输了 key 但验证不过:给验证结论,别绕回"去 login"的长指引
|
|
107
|
+
throw new Error(saved.message);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!item) throw error;
|
|
111
|
+
}
|
|
76
112
|
resolved.set(name, item);
|
|
77
113
|
for (const dep of item.registryDependencies ?? []) {
|
|
78
|
-
if (!resolved.has(dep)) await collect(dep);
|
|
114
|
+
if (!resolved.has(bareItemName(dep))) await collect(dep);
|
|
79
115
|
}
|
|
80
116
|
}
|
|
81
117
|
for (const name of wanted) await collect(name);
|
package/src/auth.js
CHANGED
|
@@ -47,8 +47,30 @@ function saveKey(key) {
|
|
|
47
47
|
return file;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** add/skill 等命令撞上 Pro 无 key 时的就地补 key(TTY 交互):输入 → 验证 → 落盘。
|
|
51
|
+
* 返回 { ok, key? } 或 { ok:false, message }(验证失败);取消/留空返回 { ok:false }
|
|
52
|
+
* —— 调用方按"没给 key"走原有的指引报错,不打断原语义。 */
|
|
53
|
+
export async function promptAndSaveKey() {
|
|
54
|
+
const r = await prompts({
|
|
55
|
+
type: "password",
|
|
56
|
+
name: "key",
|
|
57
|
+
message: "BoardUI license key (Pro component):",
|
|
58
|
+
});
|
|
59
|
+
const key = r?.key?.trim();
|
|
60
|
+
if (!key) return { ok: false };
|
|
61
|
+
const verdict = await verifyKey(key);
|
|
62
|
+
if (!verdict.ok) return { ok: false, message: verdict.message };
|
|
63
|
+
const file = saveKey(key);
|
|
64
|
+
console.log(
|
|
65
|
+
c.green(
|
|
66
|
+
`✓ license key verified and saved to ${file} — future commands won't ask again`
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
return { ok: true, key };
|
|
70
|
+
}
|
|
71
|
+
|
|
50
72
|
// 401 = key 不存在/无效;423 = 暂停/封禁;429 = 限流;其余(5xx/网络)按"暂不可验证"处理
|
|
51
|
-
async function verifyKey(key) {
|
|
73
|
+
export async function verifyKey(key) {
|
|
52
74
|
try {
|
|
53
75
|
const res = await fetch(`${proRegistryBaseUrl()}/${PROBE_NAME}`, {
|
|
54
76
|
headers: { Authorization: `Bearer ${key}` },
|
package/src/registry.js
CHANGED
|
@@ -7,6 +7,14 @@ const BASE = "https://boardui.collectui.pro";
|
|
|
7
7
|
export const registryBaseUrl = () => `${BASE}/r`;
|
|
8
8
|
export const proRegistryBaseUrl = () => `${BASE}/api/pro/r`;
|
|
9
9
|
|
|
10
|
+
/** 报错文案里的调起前缀:客户绝大多数经 npx 调起(文档同款),照抄裸 `bdui login`
|
|
11
|
+
* 在他们机器上是 command not found(2026-12-02 客户实踩「这个也不行」)。 */
|
|
12
|
+
export function cliInvoker() {
|
|
13
|
+
return process.env.npm_lifecycle_event === "npx"
|
|
14
|
+
? "npx -y @collectui/bdui"
|
|
15
|
+
: "bdui";
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
async function fetchJson(url, headers) {
|
|
11
19
|
const response = await fetch(url, { headers });
|
|
12
20
|
if (!response.ok) {
|
|
@@ -42,9 +50,11 @@ export async function fetchItem(name, key) {
|
|
|
42
50
|
// 网络/5xx 原样抛出,否则会把上游抖动误诊成"Pro 组件需要 key",误导用户。
|
|
43
51
|
if (error?.status !== 404 && error?.status !== 401) throw error;
|
|
44
52
|
if (!key) {
|
|
45
|
-
|
|
46
|
-
`"${name}" is a BoardUI Pro component. Run
|
|
53
|
+
const err = new Error(
|
|
54
|
+
`"${name}" is a BoardUI Pro component. Run \`${cliInvoker()} login <license-key>\` once to save your key on this machine — CLI and MCP then work without passing it. For a single call instead: \`${cliInvoker()} add ${name} --key <license-key>\`, or a per-call \`key\` parameter (MCP install_components / get_component). The key is distributed by your platform or administrator.`
|
|
47
55
|
);
|
|
56
|
+
err.code = "PRO_KEY_MISSING";
|
|
57
|
+
throw err;
|
|
48
58
|
}
|
|
49
59
|
const response = await fetch(`${proRegistryBaseUrl()}/${name}`, {
|
|
50
60
|
headers: { Authorization: `Bearer ${key}` },
|