@collectui/cli 0.2.29 → 0.2.30
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/cli.mjs +11 -11
- package/src/commands/apply.mjs +12 -14
- package/src/commands/common.mjs +7 -2
- package/src/commands/setup.mjs +20 -13
- package/src/scaffold.mjs +37 -0
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -66,15 +66,15 @@ Global options:
|
|
|
66
66
|
--cwd <dir> Project directory (default: current directory)
|
|
67
67
|
--tmp Force the OS temp dir as target (init defaults there anyway)
|
|
68
68
|
--name <name> Project/package name
|
|
69
|
-
--template <t> vite
|
|
70
|
-
(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
--
|
|
74
|
-
--
|
|
75
|
-
|
|
76
|
-
--shadcn-args "<a>" Escape hatch: extra args
|
|
77
|
-
--pm <pm> npm | pnpm | yarn | bun (
|
|
69
|
+
--template <t> vite | none | next | start | react-router | laravel | astro
|
|
70
|
+
(no flags at all: your saved shadcn command, else the built-in
|
|
71
|
+
pnpm dlx shadcn@latest init --preset b1VlIttI --template next
|
|
72
|
+
--monorepo --pointer)
|
|
73
|
+
--preset <id> Override the shadcn preset (appended to the command)
|
|
74
|
+
--base <b> / --monorepo / --pointer / --rtl / --no-css-variables
|
|
75
|
+
Passed through to the official shadcn CLI
|
|
76
|
+
--shadcn-args "<a>" Escape hatch: extra args appended to the command
|
|
77
|
+
--pm <pm> npm | pnpm | yarn | bun (only for the built-in vite template)
|
|
78
78
|
--scope <@scope> add: force a registry scope
|
|
79
79
|
--no-auto-configure add: refuse to write missing registry scopes
|
|
80
80
|
--print add: print the command without running it
|
|
@@ -86,8 +86,8 @@ Global options:
|
|
|
86
86
|
Examples:
|
|
87
87
|
cui login
|
|
88
88
|
cui whoami --json
|
|
89
|
-
cui init --libs reui,arc
|
|
90
|
-
cui init
|
|
89
|
+
cui init --libs reui,arc # default shadcn command, then configure
|
|
90
|
+
cui init --template vite --no-install # built-in vite template instead
|
|
91
91
|
cui configure . --libs all --dry-run
|
|
92
92
|
cui init --template next --preset b1VlIttI --monorepo --pointer # official scaffold
|
|
93
93
|
cui apply --preset b1VlIttI # apply preset to the existing project here
|
package/src/commands/apply.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_APPLY_COMMAND, runShadcnCommand } from "../scaffold.mjs";
|
|
4
4
|
import { displayPath } from "../changes.mjs";
|
|
5
5
|
import { usageError } from "../errors.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { runSetup } from "./setup.mjs";
|
|
7
7
|
import { collectShadcnFlags, requireToken } from "./common.mjs";
|
|
8
8
|
import { fetchAccount } from "../dash.mjs";
|
|
9
9
|
|
|
@@ -20,18 +20,16 @@ export async function applyCmd(flags, rest, reporter) {
|
|
|
20
20
|
hint: "`cui apply` works on an existing shadcn project; use `cui init` to create one.",
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await runShadcnApply({ target, passthrough, pm, reporter });
|
|
34
|
-
}
|
|
23
|
+
// 默认 = 账户自定义命令 > 内置默认(2026-12-06 四版:偏好模型即两条命令);
|
|
24
|
+
// 显式 flags 追加命令尾覆盖
|
|
25
|
+
const token = requireToken(flags, reporter);
|
|
26
|
+
const me = await fetchAccount(token, { reporter });
|
|
27
|
+
const custom = (me?.cliApplyCommand ?? "").trim() || DEFAULT_APPLY_COMMAND;
|
|
28
|
+
const overrides = collectShadcnFlags(flags, { sub: "apply", minimal: true });
|
|
29
|
+
const command = overrides.length ? `${custom} ${overrides.join(" ")}` : custom;
|
|
30
|
+
reporter.step(1, 3, `Apply via shadcn (${displayPath(target)})`);
|
|
31
|
+
reporter.info(`Command: ${command}`);
|
|
32
|
+
await runShadcnCommand({ command, target, reporter });
|
|
35
33
|
// 官方 apply 落盘后的 components.json / 主题与 cui 的 registry 配置正交:
|
|
36
34
|
// 直接走 configure 全链(registries / env / MCP),复用一切默认与守卫
|
|
37
35
|
return runSetup({ mode: "configure", rest: [target], reporter, flags });
|
package/src/commands/common.mjs
CHANGED
|
@@ -241,13 +241,18 @@ export async function chooseClients(flags, me, reporter, { interactive = true }
|
|
|
241
241
|
* 常用 flags(--preset/--base/--monorepo/--pointer/--rtl/--no-css-variables),
|
|
242
242
|
* --shadcn-args "…" 作逃生舱透传任意官方参数(--only theme 等)。
|
|
243
243
|
*/
|
|
244
|
-
export function collectShadcnFlags(flags, { sub = "init" } = {}) {
|
|
244
|
+
export function collectShadcnFlags(flags, { sub = "init", minimal = false } = {}) {
|
|
245
245
|
const out = [];
|
|
246
246
|
if (flags.preset) out.push("--preset", String(flags.preset));
|
|
247
|
-
if (sub === "init") {
|
|
247
|
+
if (sub === "init" && !minimal) {
|
|
248
248
|
if (flags.base) out.push("--base", String(flags.base));
|
|
249
249
|
if (flags.monorepo) out.push("--monorepo");
|
|
250
250
|
else out.push("--no-monorepo"); // 跳过官方的 monorepo 交互确认
|
|
251
|
+
} else {
|
|
252
|
+
// minimal:只透传显式给的(命令串已含默认形,重复项靠 commander 后值覆盖)
|
|
253
|
+
if (flags.base) out.push("--base", String(flags.base));
|
|
254
|
+
if (flags.monorepo) out.push("--monorepo");
|
|
255
|
+
if (flags["no-monorepo"]) out.push("--no-monorepo");
|
|
251
256
|
}
|
|
252
257
|
if (flags.pointer) out.push("--pointer");
|
|
253
258
|
if (flags.rtl) out.push("--rtl");
|
package/src/commands/setup.mjs
CHANGED
|
@@ -10,7 +10,13 @@ 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 {
|
|
13
|
+
import {
|
|
14
|
+
DEFAULT_INIT_COMMAND,
|
|
15
|
+
planManifest,
|
|
16
|
+
planScaffold,
|
|
17
|
+
runShadcnCommand,
|
|
18
|
+
SHADCN_TEMPLATES,
|
|
19
|
+
} from "../scaffold.mjs";
|
|
14
20
|
import { includeDashMcp, chooseClients, collectShadcnFlags, detectClientApp, selectLibs } from "./common.mjs";
|
|
15
21
|
|
|
16
22
|
// client 集/选项面已迁 common.mjs(mcp 命令与 setup 共用决策链);
|
|
@@ -121,9 +127,11 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
121
127
|
// 官方 shadcn 引擎判定:显式官方模板(next/start/react-router/laravel/astro)
|
|
122
128
|
// 或给了 --preset → 前置跑官方 init(自带依赖安装与 components.json),
|
|
123
129
|
// cui 只叠加 configure;否则走自家 vite 模板(离线可先落盘)。
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
// 2026-12-06 四版:默认 = 官方命令链(账户 cli-init-command > 内置默认——
|
|
131
|
+
// 两条可随时覆盖的命令,pm 就写在命令里);--template vite 显式才走自家模板,
|
|
132
|
+
// 显式 --template next/--preset 等仍按拼参路径覆盖
|
|
133
|
+
const explicitVite = template === "vite";
|
|
134
|
+
const officialScaffold = !explicitVite; // none 已在上面被 hasComponents 分支吸收
|
|
127
135
|
const install =
|
|
128
136
|
mode === "init" &&
|
|
129
137
|
!hasComponents &&
|
|
@@ -142,15 +150,14 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
142
150
|
|
|
143
151
|
if (mode === "init" && !hasComponents) {
|
|
144
152
|
if (officialScaffold) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
153
|
+
const custom = (me?.cliInitCommand ?? "").trim() || DEFAULT_INIT_COMMAND;
|
|
154
|
+
// 显式 flags(--preset/--base/--pointer…)追加命令尾,commander 后值
|
|
155
|
+
// 覆盖前值——不显式就纯用账户/默认命令
|
|
156
|
+
const overrides = collectShadcnFlags(flags, { minimal: true });
|
|
157
|
+
const command = overrides.length ? `${custom} ${overrides.join(" ")}` : custom;
|
|
158
|
+
reporter.step(1, 5, `Scaffold via shadcn in ${displayPath(target)}`);
|
|
159
|
+
reporter.info(`Command: ${command}`);
|
|
160
|
+
await runShadcnCommand({ command, target, name: projectName, reporter });
|
|
154
161
|
hasComponents = existsSync(join(target, "components.json"));
|
|
155
162
|
} else {
|
|
156
163
|
reporter.step(1, 5, `Scaffold ${template} project in ${displayPath(target)}`);
|
package/src/scaffold.mjs
CHANGED
|
@@ -59,6 +59,43 @@ export async function runShadcnScaffold({ target, name, template, passthrough =
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/** 内置默认命令(与 dash「CLI 偏好」弹窗同源同文案;账户 cli-init-command /
|
|
63
|
+
* cli-apply-command 只存改过的值——2026-12-06 用户定案:偏好模型 = 两条
|
|
64
|
+
* 可随时覆盖的命令,包管理器选择随之退役(pm 就写在命令里)) */
|
|
65
|
+
export const DEFAULT_INIT_COMMAND =
|
|
66
|
+
"pnpm dlx shadcn@latest init --preset b1VlIttI --template next --monorepo --pointer";
|
|
67
|
+
export const DEFAULT_APPLY_COMMAND =
|
|
68
|
+
"pnpm dlx shadcn@latest apply --preset b1VlIttI";
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 执行用户自定义的 shadcn 命令串(账户偏好,whitespace tokenize):
|
|
72
|
+
* 末尾追加 -c <target>(与 -n <name>,commander 后值覆盖前值——目标目录
|
|
73
|
+
* 恒由 CLI 控制)。命令自带 pm(pnpm dlx / npx …),不再单独传 pm。
|
|
74
|
+
*/
|
|
75
|
+
export async function runShadcnCommand({ command, target, name, extraArgs = [], reporter }) {
|
|
76
|
+
const parts = String(command).trim().split(/\s+/).filter(Boolean);
|
|
77
|
+
if (parts.length === 0) {
|
|
78
|
+
throw new CliError("Empty shadcn command.", {
|
|
79
|
+
hint: "Keep the default command or set a non-empty one in Dash CLI preferences.",
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const args = [...parts.slice(1), "-c", target, ...(name ? ["-n", name] : []), ...extraArgs];
|
|
83
|
+
const release = reporter?.activity
|
|
84
|
+
? reporter.activity(`shadcn (${parts.slice(1, 3).join(" ")}…)`)
|
|
85
|
+
: undefined;
|
|
86
|
+
const code = await exec(parts[0], args, {
|
|
87
|
+
cwd: target,
|
|
88
|
+
quiet: Boolean(reporter?.json),
|
|
89
|
+
});
|
|
90
|
+
release?.();
|
|
91
|
+
if (code !== 0) {
|
|
92
|
+
throw new CliError(
|
|
93
|
+
`shadcn command failed (exit ${code}): ${parts[0]} ${args.join(" ")}`,
|
|
94
|
+
{ hint: "The target directory keeps whatever was already written; fix the issue and re-run." }
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
62
99
|
/** 官方 shadcn apply:把 preset 应用到既有项目(2026-12-06 用户需求)。 */
|
|
63
100
|
export async function runShadcnApply({ target, passthrough = [], pm = "pnpm", reporter }) {
|
|
64
101
|
const dlx = {
|