@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collectui/cli",
3
- "version": "0.2.29",
3
+ "version": "0.2.30",
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
@@ -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 (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)
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 --yes --no-install # fresh verify project under the OS temp dir
90
- cui init /tmp/my-app --libs all --yes --no-install
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
@@ -1,9 +1,9 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join, resolve } from "node:path";
3
- import { runShadcnApply } from "../scaffold.mjs";
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 { VALID_PM, runSetup } from "./setup.mjs";
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
- 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
- }
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 });
@@ -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");
@@ -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 { planManifest, planScaffold, runShadcnScaffold, SHADCN_TEMPLATES } from "../scaffold.mjs";
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
- const officialScaffold =
125
- SHADCN_TEMPLATES.has(template) || Boolean(flags.preset);
126
- const effTemplate = officialScaffold && template === "vite" ? "next" : template;
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
- 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
- });
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 = {