@collectui/cli 0.2.27 → 0.2.28
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/README.md +1 -1
- package/package.json +1 -1
- package/src/args.mjs +4 -0
- package/src/changes.mjs +3 -0
- package/src/cli.mjs +19 -3
- package/src/commands/apply.mjs +38 -0
- package/src/commands/common.mjs +22 -0
- package/src/commands/prefs.mjs +115 -0
- package/src/commands/setup.mjs +36 -6
- package/src/scaffold.mjs +85 -41
- package/src/skill/SKILL.md +1 -2
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ collectui configure . --libs all --dry-run
|
|
|
73
73
|
- 库没有专属 MCP → 写官方 shadcn 通用 MCP(读 `components.json` 里所有 registry)
|
|
74
74
|
- 默认写 **`collectui`** MCP(Bearer PAT),Agent 可直接调用 Dash 工具
|
|
75
75
|
- 默认写 `claude`(`.mcp.json`)、`cursor`(`.cursor/mcp.json`)、`vscode`(`.vscode/mcp.json`);`--clients codex` 写 `~/.codex/config.toml`
|
|
76
|
-
4. **`.collectui/project.json
|
|
76
|
+
4. **`.collectui/project.json`**:机器可读的配置记录(不含密钥)
|
|
77
77
|
|
|
78
78
|
### 合并规则(不覆盖你的自定义配置)
|
|
79
79
|
|
package/package.json
CHANGED
package/src/args.mjs
CHANGED
package/src/changes.mjs
CHANGED
|
@@ -462,6 +462,9 @@ function colorizer() {
|
|
|
462
462
|
};
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
+
/** 外部命令执行直至退出码(官方 shadcn init 前置执行等场景复用)。 */
|
|
466
|
+
export { exec };
|
|
467
|
+
|
|
465
468
|
function exec(command, args, { cwd, env, quiet = false }) {
|
|
466
469
|
return new Promise((resolve, reject) => {
|
|
467
470
|
const isJson = process.env.COLLECTUI_JSON === "1";
|
package/src/cli.mjs
CHANGED
|
@@ -26,6 +26,8 @@ import { doctorCmd } from "./commands/doctor.mjs";
|
|
|
26
26
|
import { mcpCmd } from "./commands/mcp.mjs";
|
|
27
27
|
import { skillCmd } from "./commands/skill.mjs";
|
|
28
28
|
import { updateCmd } from "./commands/update.mjs";
|
|
29
|
+
import { applyCmd } from "./commands/apply.mjs";
|
|
30
|
+
import { prefsCmd } from "./commands/prefs.mjs";
|
|
29
31
|
|
|
30
32
|
const HELP = `collectui ${CLI_VERSION} — one CLI for every shadcn library on CollectUI Dash
|
|
31
33
|
|
|
@@ -38,8 +40,10 @@ Commands:
|
|
|
38
40
|
whoami, me Who you are + your libraries (ownership, CLI/MCP key status)
|
|
39
41
|
init [dir] Scaffold a fresh shadcn project and configure libraries (no dir: OS temp dir)
|
|
40
42
|
configure [dir] Configure an existing shadcn project
|
|
43
|
+
apply [dir] Apply an official shadcn preset to an existing project, then configure
|
|
41
44
|
add <lib> <comp...> Install components with the library's channel
|
|
42
45
|
mcp <sub> Manage MCP servers for your agents: show / init config
|
|
46
|
+
prefs <sub> Account preferences: ls / get / set (pm, pinned-agents)
|
|
43
47
|
skill [dir] Install the agent skill (.claude/skills/collectui)
|
|
44
48
|
doctor Verify login, registries, env and MCP config
|
|
45
49
|
update Update the CLI now (--check only checks)
|
|
@@ -58,12 +62,19 @@ Global options:
|
|
|
58
62
|
--no-dash-mcp Do not add the CollectUI MCP (collectui) server
|
|
59
63
|
--force Replace custom registry/MCP entries (deliberate)
|
|
60
64
|
--libs <list> Comma list or "all" (default: all owned)
|
|
61
|
-
--clients <list> claude,cursor,vscode,codex or all (default: claude,cursor,vscode)
|
|
65
|
+
--clients <list> claude,cursor,vscode,codex or all (default: your Dash-pinned agents, else claude,cursor,vscode)
|
|
62
66
|
--cwd <dir> Project directory (default: current directory)
|
|
63
67
|
--tmp Force the OS temp dir as target (init defaults there anyway)
|
|
64
68
|
--name <name> Project/package name
|
|
65
|
-
--template <t> vite (default)
|
|
66
|
-
|
|
69
|
+
--template <t> vite (default) | none | next | start | react-router | laravel | astro
|
|
70
|
+
(non-vite templates and --preset scaffold via the official shadcn CLI)
|
|
71
|
+
--preset <id> Official shadcn preset (init scaffold / apply to existing project)
|
|
72
|
+
--base <b> Official init: base | radix | aria | ui-sdk
|
|
73
|
+
--monorepo Official init: scaffold a monorepo project
|
|
74
|
+
--pointer Official init/apply: pointer cursor for buttons
|
|
75
|
+
--rtl / --no-css-variables Official init/apply passthrough
|
|
76
|
+
--shadcn-args "<a>" Escape hatch: extra args passed to the official shadcn CLI
|
|
77
|
+
--pm <pm> npm | pnpm | yarn | bun (default: account pref, else pnpm)
|
|
67
78
|
--scope <@scope> add: force a registry scope
|
|
68
79
|
--no-auto-configure add: refuse to write missing registry scopes
|
|
69
80
|
--print add: print the command without running it
|
|
@@ -78,6 +89,9 @@ Examples:
|
|
|
78
89
|
cui init --libs reui,arc --yes --no-install # fresh verify project under the OS temp dir
|
|
79
90
|
cui init /tmp/my-app --libs all --yes --no-install
|
|
80
91
|
cui configure . --libs all --dry-run
|
|
92
|
+
cui init --template next --preset b1VlIttI --monorepo --pointer # official scaffold
|
|
93
|
+
cui apply --preset b1VlIttI # apply preset to the existing project here
|
|
94
|
+
cui prefs set pm pnpm # account-wide package manager preference
|
|
81
95
|
cui add reui data-grid
|
|
82
96
|
cui mcp show --json
|
|
83
97
|
COLLECTUI_TOKEN=dpat_... cui whoami --json
|
|
@@ -98,6 +112,8 @@ const COMMANDS = {
|
|
|
98
112
|
init: { run: initCmd, aliases: ["new"] },
|
|
99
113
|
configure: { run: configureCmd, aliases: ["config", "setup"] },
|
|
100
114
|
add: { run: addCmd, aliases: ["install"] },
|
|
115
|
+
apply: { run: applyCmd, aliases: ["preset"] },
|
|
116
|
+
prefs: { run: prefsCmd, aliases: ["pref"] },
|
|
101
117
|
mcp: { run: mcpCmd, aliases: [] },
|
|
102
118
|
skill: { run: skillCmd, aliases: ["install-skill"] },
|
|
103
119
|
doctor: { run: doctorCmd, aliases: ["check"] },
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { runShadcnApply } from "../scaffold.mjs";
|
|
4
|
+
import { displayPath } from "../changes.mjs";
|
|
5
|
+
import { usageError } from "../errors.mjs";
|
|
6
|
+
import { VALID_PM, runSetup } from "./setup.mjs";
|
|
7
|
+
import { collectShadcnFlags, requireToken } from "./common.mjs";
|
|
8
|
+
import { fetchAccount } from "../dash.mjs";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* cui apply [--preset <id>] [cwd] —— 官方 shadcn apply 前置 + cui configure 叠加
|
|
12
|
+
* (2026-12-06 用户需求:既有项目也要能吃官方 preset,如
|
|
13
|
+
* pnpm dlx shadcn@latest apply --preset b1VlIttI)。
|
|
14
|
+
* 不给 --preset 时等价于纯 configure(registries/env/MCP),保持可用。
|
|
15
|
+
*/
|
|
16
|
+
export async function applyCmd(flags, rest, reporter) {
|
|
17
|
+
const target = resolve(flags.cwd || rest[0] || process.cwd());
|
|
18
|
+
if (!existsSync(join(target, "components.json"))) {
|
|
19
|
+
throw usageError(`${target} has no components.json.`, {
|
|
20
|
+
hint: "`cui apply` works on an existing shadcn project; use `cui init` to create one.",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const passthrough = collectShadcnFlags(flags, { sub: "apply" });
|
|
24
|
+
if (flags.preset || flags["shadcn-args"]) {
|
|
25
|
+
const token = requireToken(flags, reporter);
|
|
26
|
+
const me = await fetchAccount(token, { reporter });
|
|
27
|
+
const pm = flags.pm
|
|
28
|
+
? String(flags.pm)
|
|
29
|
+
: me?.packageManager && VALID_PM.has(me.packageManager)
|
|
30
|
+
? me.packageManager
|
|
31
|
+
: "pnpm";
|
|
32
|
+
reporter.step(1, 3, `Apply preset via shadcn (${displayPath(target)})`);
|
|
33
|
+
await runShadcnApply({ target, passthrough, pm, reporter });
|
|
34
|
+
}
|
|
35
|
+
// 官方 apply 落盘后的 components.json / 主题与 cui 的 registry 配置正交:
|
|
36
|
+
// 直接走 configure 全链(registries / env / MCP),复用一切默认与守卫
|
|
37
|
+
return runSetup({ mode: "configure", rest: [target], reporter, flags });
|
|
38
|
+
}
|
package/src/commands/common.mjs
CHANGED
|
@@ -228,3 +228,25 @@ export async function chooseClients(flags, me, reporter, { interactive = true }
|
|
|
228
228
|
}
|
|
229
229
|
return clients;
|
|
230
230
|
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* shadcn 官方 CLI 透传参数收集(init 模板路径 / apply 共用):显式映射
|
|
234
|
+
* 常用 flags(--preset/--base/--monorepo/--pointer/--rtl/--no-css-variables),
|
|
235
|
+
* --shadcn-args "…" 作逃生舱透传任意官方参数(--only theme 等)。
|
|
236
|
+
*/
|
|
237
|
+
export function collectShadcnFlags(flags, { sub = "init" } = {}) {
|
|
238
|
+
const out = [];
|
|
239
|
+
if (flags.preset) out.push("--preset", String(flags.preset));
|
|
240
|
+
if (sub === "init") {
|
|
241
|
+
if (flags.base) out.push("--base", String(flags.base));
|
|
242
|
+
if (flags.monorepo) out.push("--monorepo");
|
|
243
|
+
else out.push("--no-monorepo"); // 跳过官方的 monorepo 交互确认
|
|
244
|
+
}
|
|
245
|
+
if (flags.pointer) out.push("--pointer");
|
|
246
|
+
if (flags.rtl) out.push("--rtl");
|
|
247
|
+
if (flags["no-css-variables"]) out.push("--no-css-variables");
|
|
248
|
+
if (flags["shadcn-args"]) {
|
|
249
|
+
out.push(...String(flags["shadcn-args"]).split(/\s+/).filter(Boolean));
|
|
250
|
+
}
|
|
251
|
+
return out;
|
|
252
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { dashUrl } from "../config.mjs";
|
|
2
|
+
import { usageError } from "../errors.mjs";
|
|
3
|
+
import { jsonRequest } from "../http.mjs";
|
|
4
|
+
import { fetchAccount } from "../dash.mjs";
|
|
5
|
+
import { requireToken } from "./common.mjs";
|
|
6
|
+
import { VALID_PM } from "./setup.mjs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* cui prefs —— 账户偏好(存 Dash 的 $users.displayPrefs,dash 设置面板与
|
|
10
|
+
* Agent(本命令)双向可改,2026-12-06 用户需求「偏好 Agent 能改、dash 也能改」)。
|
|
11
|
+
*
|
|
12
|
+
* cui prefs ls 列出当前偏好
|
|
13
|
+
* cui prefs get pm 看单项
|
|
14
|
+
* cui prefs set pm pnpm 改单项(Agent 改偏好即此)
|
|
15
|
+
*
|
|
16
|
+
* 键面(与服务端白名单同源):
|
|
17
|
+
* pm 包管理器:npm | pnpm | yarn | bun(init/apply 的默认)
|
|
18
|
+
* pinned-agents Copy to Agent 固定集(一般由 dash 站点卡维护)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** CLI 键名 ↔ 服务端 displayPrefs 键 */
|
|
22
|
+
const KEY_MAP = {
|
|
23
|
+
pm: "package-manager",
|
|
24
|
+
"pinned-agents": "copy-agent-pinned",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const PM_VALUES = [...VALID_PM];
|
|
28
|
+
|
|
29
|
+
export async function prefsCmd(flags, rest, reporter) {
|
|
30
|
+
const sub = rest[0] ?? "ls";
|
|
31
|
+
if (sub === "help" || flags.help) {
|
|
32
|
+
reporter.info(PREFS_HELP);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (sub === "ls" || sub === "list" || sub === "get") {
|
|
36
|
+
const token = requireToken(flags, reporter);
|
|
37
|
+
const me = await fetchAccount(token, { reporter });
|
|
38
|
+
const prefs = {
|
|
39
|
+
pm: normalizePm(me?.packageManager) ?? "(unset — defaults to pnpm)",
|
|
40
|
+
"pinned-agents": me?.pinnedAgents?.length
|
|
41
|
+
? me.pinnedAgents.join(",")
|
|
42
|
+
: "(unset — defaults to claude,cursor,vscode)",
|
|
43
|
+
};
|
|
44
|
+
if (sub === "get") {
|
|
45
|
+
const key = rest[1];
|
|
46
|
+
if (!KEY_MAP[key]) throw usageError(unknownKeyMessage(key));
|
|
47
|
+
reporter.result({ [key]: prefs[key] });
|
|
48
|
+
if (!reporter.json) reporter.note(key, String(prefs[key]));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
reporter.result({ prefs });
|
|
52
|
+
if (!reporter.json) {
|
|
53
|
+
reporter.note(
|
|
54
|
+
"Account preferences",
|
|
55
|
+
Object.entries(prefs)
|
|
56
|
+
.map(([k, v]) => `${k} = ${v}`)
|
|
57
|
+
.join("\n")
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (sub === "set") {
|
|
63
|
+
const key = rest[1];
|
|
64
|
+
let value = rest[2];
|
|
65
|
+
if (!key || !KEY_MAP[key] || value === undefined) {
|
|
66
|
+
throw usageError(unknownKeyMessage(key));
|
|
67
|
+
}
|
|
68
|
+
if (key === "pm") {
|
|
69
|
+
value = String(value).toLowerCase();
|
|
70
|
+
if (!PM_VALUES.includes(value)) {
|
|
71
|
+
throw usageError(`pm must be one of: ${PM_VALUES.join(", ")}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (key === "pinned-agents") {
|
|
75
|
+
value = String(value)
|
|
76
|
+
.split(/[,\s]+/)
|
|
77
|
+
.map((s) => s.trim())
|
|
78
|
+
.filter(Boolean)
|
|
79
|
+
.join(",");
|
|
80
|
+
}
|
|
81
|
+
const token = requireToken(flags, reporter);
|
|
82
|
+
await jsonRequest(`${dashUrl()}/api/account/prefs`, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: {
|
|
85
|
+
Authorization: `Bearer ${token}`,
|
|
86
|
+
"Content-Type": "application/json",
|
|
87
|
+
},
|
|
88
|
+
body: JSON.stringify({ key: KEY_MAP[key], value }),
|
|
89
|
+
label: "Save preference",
|
|
90
|
+
});
|
|
91
|
+
reporter.result({ key, value });
|
|
92
|
+
if (!reporter.json) reporter.success(`Saved: ${key} = ${value}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
throw usageError(`Unknown prefs subcommand "${sub}".`, { hint: PREFS_HELP });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function normalizePm(v) {
|
|
99
|
+
return v && VALID_PM.has(v) ? v : null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function unknownKeyMessage(key) {
|
|
103
|
+
return `Unknown preference "${key ?? ""}". Keys: ${Object.keys(KEY_MAP).join(", ")}.`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const PREFS_HELP = `Usage: cui prefs <ls|get|set> [key] [value]
|
|
107
|
+
|
|
108
|
+
Account-wide preferences (stored in Dash, shared across machines):
|
|
109
|
+
|
|
110
|
+
pm Package manager for init/apply: ${PM_VALUES.join(" | ")} (default pnpm)
|
|
111
|
+
pinned-agents Copy to Agent pin set (usually managed on Dash site cards)
|
|
112
|
+
|
|
113
|
+
Examples:
|
|
114
|
+
cui prefs ls
|
|
115
|
+
cui prefs set pm pnpm`;
|
package/src/commands/setup.mjs
CHANGED
|
@@ -10,13 +10,16 @@ import { login, saveSession } from "../login.mjs";
|
|
|
10
10
|
import { fetchAccount } from "../dash.mjs";
|
|
11
11
|
import { planMcpConfig, describeEntries } from "../mcp.mjs";
|
|
12
12
|
import { detectPackageManager, planProjectConfig } from "../project.mjs";
|
|
13
|
-
import { planManifest, planScaffold } from "../scaffold.mjs";
|
|
14
|
-
import { chooseClients, detectClientApp, selectLibs } from "./common.mjs";
|
|
13
|
+
import { planManifest, planScaffold, runShadcnScaffold, SHADCN_TEMPLATES } from "../scaffold.mjs";
|
|
14
|
+
import { chooseClients, collectShadcnFlags, detectClientApp, selectLibs } from "./common.mjs";
|
|
15
15
|
|
|
16
16
|
// client 集/选项面已迁 common.mjs(mcp 命令与 setup 共用决策链);
|
|
17
17
|
// 此处 re-export 兼容既有 import
|
|
18
18
|
export { resolveClients, CLIENT_OPTIONS, ALL_CLIENTS } from "./common.mjs";
|
|
19
19
|
|
|
20
|
+
/** 账户偏好可配的包管理器集合(cui config set pm <v> 校验用同款) */
|
|
21
|
+
export const VALID_PM = new Set(["npm", "pnpm", "yarn", "bun"]);
|
|
22
|
+
|
|
20
23
|
export function resolveTarget({ flags, rest, mode }) {
|
|
21
24
|
const explicit = flags.cwd || rest[0];
|
|
22
25
|
if (explicit) return resolve(String(explicit));
|
|
@@ -83,7 +86,7 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
83
86
|
const { libs, units } = await selectLibs({ flags, me, reporter });
|
|
84
87
|
|
|
85
88
|
const target = resolveTarget({ flags, rest, mode });
|
|
86
|
-
|
|
89
|
+
let hasComponents = existsSync(join(target, "components.json"));
|
|
87
90
|
const nonEmpty = isNonEmptyDir(target);
|
|
88
91
|
const template = flags.template ? String(flags.template) : "vite";
|
|
89
92
|
|
|
@@ -107,10 +110,24 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
107
110
|
});
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
// 包管理器决策链(2026-12-06 用户定案:默认 pnpm,账户偏好可改):
|
|
114
|
+
// --pm > dash 账户偏好(cui config set pm / dash 设置面板写入)> 项目锁文件
|
|
115
|
+
// 探测 > pnpm 兜底。零配置开箱即用 = pnpm。
|
|
116
|
+
const pm = flags.pm
|
|
117
|
+
? String(flags.pm)
|
|
118
|
+
: (me?.packageManager && VALID_PM.has(me.packageManager)
|
|
119
|
+
? me.packageManager
|
|
120
|
+
: detectPackageManager(hasComponents ? target : process.cwd()) ?? "pnpm");
|
|
121
|
+
// 官方 shadcn 引擎判定:显式官方模板(next/start/react-router/laravel/astro)
|
|
122
|
+
// 或给了 --preset → 前置跑官方 init(自带依赖安装与 components.json),
|
|
123
|
+
// cui 只叠加 configure;否则走自家 vite 模板(离线可先落盘)。
|
|
124
|
+
const officialScaffold =
|
|
125
|
+
SHADCN_TEMPLATES.has(template) || Boolean(flags.preset);
|
|
126
|
+
const effTemplate = officialScaffold && template === "vite" ? "next" : template;
|
|
111
127
|
const install =
|
|
112
128
|
mode === "init" &&
|
|
113
129
|
!hasComponents &&
|
|
130
|
+
!officialScaffold && // 官方 init 自带依赖安装
|
|
114
131
|
flags.install !== false &&
|
|
115
132
|
!flags["no-install"];
|
|
116
133
|
const clients = await chooseClients(flags, me, reporter);
|
|
@@ -124,8 +141,21 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
124
141
|
});
|
|
125
142
|
|
|
126
143
|
if (mode === "init" && !hasComponents) {
|
|
127
|
-
|
|
128
|
-
|
|
144
|
+
if (officialScaffold) {
|
|
145
|
+
reporter.step(1, 5, `Scaffold via shadcn init (${effTemplate}) in ${displayPath(target)}`);
|
|
146
|
+
await runShadcnScaffold({
|
|
147
|
+
target,
|
|
148
|
+
name: projectName,
|
|
149
|
+
template: effTemplate,
|
|
150
|
+
passthrough: collectShadcnFlags(flags),
|
|
151
|
+
pm,
|
|
152
|
+
reporter,
|
|
153
|
+
});
|
|
154
|
+
hasComponents = existsSync(join(target, "components.json"));
|
|
155
|
+
} else {
|
|
156
|
+
reporter.step(1, 5, `Scaffold ${template} project in ${displayPath(target)}`);
|
|
157
|
+
planScaffold(cs, { target, name: projectName, template, pm, install });
|
|
158
|
+
}
|
|
129
159
|
} else {
|
|
130
160
|
reporter.step(1, 5, `Use existing project ${displayPath(target)}`);
|
|
131
161
|
}
|
package/src/scaffold.mjs
CHANGED
|
@@ -1,5 +1,87 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
1
2
|
import { join } from "node:path";
|
|
3
|
+
import { exec } from "./changes.mjs";
|
|
2
4
|
import { resolveLibKeys } from "./catalog.mjs";
|
|
5
|
+
import { CliError } from "./errors.mjs";
|
|
6
|
+
|
|
7
|
+
/** shadcn 官方 init 支持的模板(官方脚手架引擎;vite 走自家模板,none 只配置) */
|
|
8
|
+
export const SHADCN_TEMPLATES = new Set([
|
|
9
|
+
"next",
|
|
10
|
+
"start",
|
|
11
|
+
"react-router",
|
|
12
|
+
"laravel",
|
|
13
|
+
"astro",
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 官方 shadcn init 作脚手架引擎(2026-12-06 用户需求:Next.js / preset /
|
|
18
|
+
* monorepo 等自定义):cui 前置直接执行官方 CLI(进度直通、components.json
|
|
19
|
+
* 落盘),随后 configure 链叠加 registries / env / MCP——顺序天然正确。
|
|
20
|
+
* pm 走官方 dlx 形态(pnpm dlx shadcn@latest …)由调用方拼好 command。
|
|
21
|
+
*/
|
|
22
|
+
export async function runShadcnScaffold({ target, name, template, passthrough = [], pm = "pnpm", reporter }) {
|
|
23
|
+
mkdirSync(target, { recursive: true, mode: 0o755 });
|
|
24
|
+
const args = [
|
|
25
|
+
"shadcn@latest",
|
|
26
|
+
"init",
|
|
27
|
+
"-y",
|
|
28
|
+
"-t",
|
|
29
|
+
template,
|
|
30
|
+
...(name ? ["-n", name] : []),
|
|
31
|
+
"-c",
|
|
32
|
+
target,
|
|
33
|
+
...passthrough,
|
|
34
|
+
];
|
|
35
|
+
// 包管理器 → 官方 CLI 一次性执行形态(npm/pnpm/yarn/bun)
|
|
36
|
+
const dlx = {
|
|
37
|
+
npm: ["npx", ["-y"]],
|
|
38
|
+
pnpm: ["pnpm", ["dlx"]],
|
|
39
|
+
yarn: ["yarn", ["dlx"]],
|
|
40
|
+
bun: ["bunx", []],
|
|
41
|
+
}[pm] ?? ["pnpm", ["dlx"]];
|
|
42
|
+
const [command, prefix] = dlx;
|
|
43
|
+
const release = reporter?.activity
|
|
44
|
+
? reporter.activity(`shadcn init (${template})`)
|
|
45
|
+
: undefined;
|
|
46
|
+
const code = await exec(
|
|
47
|
+
command,
|
|
48
|
+
[...prefix, ...args],
|
|
49
|
+
{ cwd: target, quiet: Boolean(reporter?.json) }
|
|
50
|
+
);
|
|
51
|
+
release?.();
|
|
52
|
+
if (code !== 0) {
|
|
53
|
+
throw new CliError(
|
|
54
|
+
`shadcn init failed (exit ${code}): ${command} ${[...prefix, ...args].join(" ")}`,
|
|
55
|
+
{
|
|
56
|
+
hint: "The target directory keeps whatever the official CLI already wrote; fix the issue and re-run.",
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 官方 shadcn apply:把 preset 应用到既有项目(2026-12-06 用户需求)。 */
|
|
63
|
+
export async function runShadcnApply({ target, passthrough = [], pm = "pnpm", reporter }) {
|
|
64
|
+
const dlx = {
|
|
65
|
+
npm: ["npx", ["-y"]],
|
|
66
|
+
pnpm: ["pnpm", ["dlx"]],
|
|
67
|
+
yarn: ["yarn", ["dlx"]],
|
|
68
|
+
bun: ["bunx", []],
|
|
69
|
+
}[pm] ?? ["pnpm", ["dlx"]];
|
|
70
|
+
const [command, prefix] = dlx;
|
|
71
|
+
const args = ["shadcn@latest", "apply", "-y", "-c", target, ...passthrough];
|
|
72
|
+
const release = reporter?.activity ? reporter.activity("shadcn apply (preset)") : undefined;
|
|
73
|
+
const code = await exec(command, [...prefix, ...args], {
|
|
74
|
+
cwd: target,
|
|
75
|
+
quiet: Boolean(reporter?.json),
|
|
76
|
+
});
|
|
77
|
+
release?.();
|
|
78
|
+
if (code !== 0) {
|
|
79
|
+
throw new CliError(
|
|
80
|
+
`shadcn apply failed (exit ${code}): ${command} ${[...prefix, ...args].join(" ")}`,
|
|
81
|
+
{ hint: "Fix the issue and re-run — apply is idempotent per preset." }
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
3
85
|
|
|
4
86
|
/** 最小 Vite + React + TS + Tailwind v4 + shadcn 兼容脚手架(无网络也能先落盘)。 */
|
|
5
87
|
export function planScaffold(cs, { target, name, template = "vite", pm = "npm", install = false }) {
|
|
@@ -116,48 +198,10 @@ export function planManifest(cs, {
|
|
|
116
198
|
summary: "write .collectui/project.json (machine-readable setup record)",
|
|
117
199
|
});
|
|
118
200
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (cs.read(envDocPath) !== envDoc) {
|
|
122
|
-
cs.write(envDocPath, envDoc, {
|
|
123
|
-
summary: "write .collectui/environment.md (agent-readable setup)",
|
|
124
|
-
});
|
|
125
|
-
}
|
|
201
|
+
// environment.md 已退役(2026-12-06 用户定案「冗余」):project.json 本身
|
|
202
|
+
// 就是 Agent 可读的机器面,不再双写一份人话文档;存量文件不主动删。
|
|
126
203
|
}
|
|
127
204
|
|
|
128
|
-
function environmentDoc(manifest) {
|
|
129
|
-
const libs = manifest.libraries
|
|
130
|
-
.map(
|
|
131
|
-
(l) =>
|
|
132
|
-
`- ${l.name} (\`${l.site}\`)\n` +
|
|
133
|
-
` - registries: ${l.registries.length ? l.registries.map((s) => `\`${s}\``).join(", ") : "—"}\n` +
|
|
134
|
-
` - CLI key: ${l.cliKeyBound ? "bound" : "missing"}; MCP key: ${l.mcpKeyBound ? "bound" : "missing"}\n` +
|
|
135
|
-
` - MCP server: ${l.mcpServer ?? "—"}`
|
|
136
|
-
)
|
|
137
|
-
.join("\n");
|
|
138
|
-
return `# CollectUI environment
|
|
139
|
-
|
|
140
|
-
Generated by \`collectui\` ${manifest.version} on ${manifest.generatedAt}.
|
|
141
|
-
|
|
142
|
-
## Libraries configured
|
|
143
|
-
|
|
144
|
-
${libs || "- (none)"}
|
|
145
|
-
|
|
146
|
-
## MCP clients
|
|
147
|
-
|
|
148
|
-
${manifest.mcpClients.map((c) => `- ${c}`).join("\n") || "- (none)"}
|
|
149
|
-
|
|
150
|
-
## Commands
|
|
151
|
-
|
|
152
|
-
- Configure another library: \`cui configure . --libs <site>\`
|
|
153
|
-
- Install a component: \`cui add <site> <component>\`
|
|
154
|
-
- Re-check setup: \`cui doctor\`
|
|
155
|
-
- Dash account: \`cui whoami\`
|
|
156
|
-
|
|
157
|
-
Secrets live in \`.env.local\` and the MCP config files (both are gitignored by
|
|
158
|
-
the scaffold). Never commit them.
|
|
159
|
-
`;
|
|
160
|
-
}
|
|
161
205
|
|
|
162
206
|
function safeName(name) {
|
|
163
207
|
return String(name || "collectui-app")
|
|
@@ -447,7 +491,7 @@ cui add <site> <component>
|
|
|
447
491
|
cui configure . --libs <site>
|
|
448
492
|
\`\`\`
|
|
449
493
|
|
|
450
|
-
See \`.collectui/
|
|
494
|
+
See \`.collectui/project.json\` for the machine-readable setup record.
|
|
451
495
|
`;
|
|
452
496
|
|
|
453
497
|
function escapeHtml(value) {
|
package/src/skill/SKILL.md
CHANGED
|
@@ -51,8 +51,7 @@ This writes/merges:
|
|
|
51
51
|
`~/.codex/config.toml`) → library MCP servers + `collectui`. Client set:
|
|
52
52
|
the user's Dash-pinned agents when available, else claude/cursor/vscode;
|
|
53
53
|
override with `--clients`.
|
|
54
|
-
- `.collectui/project.json`
|
|
55
|
-
setup record.
|
|
54
|
+
- `.collectui/project.json` → machine-readable setup record (no secrets).
|
|
56
55
|
|
|
57
56
|
### Scaffold under /tmp
|
|
58
57
|
|