@collectui/cli 0.2.42 → 0.2.43
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/commands/apply.mjs +10 -3
- package/src/commands/init.mjs +4 -6
- package/src/commands/migrate.mjs +14 -3
- package/src/commands/setup.mjs +7 -1
- package/src/scaffold.mjs +27 -0
package/package.json
CHANGED
package/src/commands/apply.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
applyPmToCommand,
|
|
5
|
+
DEFAULT_APPLY_COMMAND,
|
|
6
|
+
runShadcnCommand,
|
|
7
|
+
} from "../scaffold.mjs";
|
|
4
8
|
import { displayPath } from "../changes.mjs";
|
|
5
9
|
import { usageError } from "../errors.mjs";
|
|
6
|
-
import { runSetup } from "./setup.mjs";
|
|
10
|
+
import { runSetup, VALID_PM } from "./setup.mjs";
|
|
7
11
|
import { collectShadcnFlags, requireToken } from "./common.mjs";
|
|
8
12
|
import { fetchAccount } from "../dash.mjs";
|
|
9
13
|
|
|
@@ -24,7 +28,10 @@ export async function applyCmd(flags, rest, reporter) {
|
|
|
24
28
|
// 显式 flags 追加命令尾覆盖
|
|
25
29
|
const token = requireToken(flags, reporter);
|
|
26
30
|
const me = await fetchAccount(token, { reporter });
|
|
27
|
-
|
|
31
|
+
let custom = (me?.cliApplyCommand ?? "").trim() || DEFAULT_APPLY_COMMAND;
|
|
32
|
+
if (!me?.cliApplyCommand && me?.packageManager && VALID_PM.has(me.packageManager)) {
|
|
33
|
+
custom = applyPmToCommand(custom, me.packageManager);
|
|
34
|
+
}
|
|
28
35
|
const overrides = collectShadcnFlags(flags, { sub: "apply", minimal: true });
|
|
29
36
|
const command = overrides.length ? `${custom} ${overrides.join(" ")}` : custom;
|
|
30
37
|
reporter.step(1, 3, `Apply via shadcn (${displayPath(target)})`);
|
package/src/commands/init.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, rmSync, statSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { displayPath } from "../changes.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { warnShellInside } from "./migrate.mjs";
|
|
6
6
|
import { runSetup } from "./setup.mjs";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -22,11 +22,9 @@ export async function initCmd(flags, rest, reporter) {
|
|
|
22
22
|
String(flags.name ?? "collectui-app").replace(/[\\/]+/g, "-")
|
|
23
23
|
);
|
|
24
24
|
if (existsSync(target) && statSync(target).isDirectory()) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
}
|
|
25
|
+
// CLI 自身先挪到 home(保自己不崩);init new 删完立即重建同路径,
|
|
26
|
+
// 用户 shell 停的原目录恢复有效——无需任何 cd
|
|
27
|
+
warnShellInside(target, reporter);
|
|
30
28
|
rmSync(target, { recursive: true, force: true });
|
|
31
29
|
reporter.info(`Removed previous project at ${displayPath(target)} — starting fresh.`);
|
|
32
30
|
}
|
package/src/commands/migrate.mjs
CHANGED
|
@@ -56,6 +56,7 @@ export async function migrateCmd(flags, rest, reporter) {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
const wasShellInside = shellInside(source);
|
|
59
60
|
warnShellInside(source, reporter);
|
|
60
61
|
mkdirSync(resolve(dest, ".."), { recursive: true });
|
|
61
62
|
let moved;
|
|
@@ -74,7 +75,7 @@ export async function migrateCmd(flags, rest, reporter) {
|
|
|
74
75
|
}
|
|
75
76
|
reporter.result({ from: source, to: dest, mode: moved });
|
|
76
77
|
reporter.outro(
|
|
77
|
-
`Migrated (${moved}) → ${displayPath(dest)} — configs (.env.local, MCP files) moved with it; open the project from the new path
|
|
78
|
+
`Migrated (${moved}) → ${displayPath(dest)} — configs (.env.local, MCP files) moved with it; open the project from the new path${shellInside(dest) === false && wasShellInside ? ` (run: cd ${displayPath(dest)})` : "."}`
|
|
78
79
|
);
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -131,10 +132,17 @@ export function shellInside(path) {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
function warnShellInside(path, reporter) {
|
|
135
|
+
export function warnShellInside(path, reporter) {
|
|
135
136
|
if (shellInside(path)) {
|
|
137
|
+
// CLI 自身先挪到 home(子进程改不了用户 shell 的 cwd,但能保自己不崩——
|
|
138
|
+
// 目录一删,后续任何 process.cwd() 都会 ENOENT;2026-12-07 用户实锤)
|
|
139
|
+
try {
|
|
140
|
+
process.chdir(homedir());
|
|
141
|
+
} catch {
|
|
142
|
+
// chdir 失败极罕见,继续
|
|
143
|
+
}
|
|
136
144
|
reporter.warn(
|
|
137
|
-
`Your terminal is
|
|
145
|
+
`Your terminal is inside ${displayPath(path)} — the CLI moved itself to a safe directory. After this command: ${SHELL_CD_HINT}`
|
|
138
146
|
);
|
|
139
147
|
}
|
|
140
148
|
}
|
|
@@ -184,6 +192,9 @@ function dirSize(dir) {
|
|
|
184
192
|
return total;
|
|
185
193
|
}
|
|
186
194
|
|
|
195
|
+
/** clean/migrate 后给 shell 卡位用户的一行指引(带反引号便于复制) */
|
|
196
|
+
const SHELL_CD_HINT = "`cd ~` (your shell's directory was removed)";
|
|
197
|
+
|
|
187
198
|
const MIGRATE_HELP = `Usage: cui migrate <dest> [src]
|
|
188
199
|
|
|
189
200
|
Move a throwaway temp project to a permanent location:
|
package/src/commands/setup.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { fetchAccount } from "../dash.mjs";
|
|
|
11
11
|
import { planMcpConfig, describeEntries } from "../mcp.mjs";
|
|
12
12
|
import { detectPackageManager, planProjectConfig } from "../project.mjs";
|
|
13
13
|
import {
|
|
14
|
+
applyPmToCommand,
|
|
14
15
|
DEFAULT_INIT_COMMAND,
|
|
15
16
|
planManifest,
|
|
16
17
|
planScaffold,
|
|
@@ -195,7 +196,12 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
195
196
|
|
|
196
197
|
if (mode === "init" && !hasComponents) {
|
|
197
198
|
if (officialScaffold) {
|
|
198
|
-
|
|
199
|
+
let custom = (me?.cliInitCommand ?? "").trim() || DEFAULT_INIT_COMMAND;
|
|
200
|
+
// 未自定义时,pm 偏好(package-manager)驱动默认命令前缀——切换 pm
|
|
201
|
+
// 所有相关命令跟着变(dash 侧对自定义命令已同步改写存盘)
|
|
202
|
+
if (!me?.cliInitCommand && me?.packageManager && VALID_PM.has(me.packageManager)) {
|
|
203
|
+
custom = applyPmToCommand(custom, me.packageManager);
|
|
204
|
+
}
|
|
199
205
|
// 显式 flags(--preset/--base/--pointer…)追加命令尾,commander 后值
|
|
200
206
|
// 覆盖前值——不显式就纯用账户/默认命令
|
|
201
207
|
const overrides = collectShadcnFlags(flags, { minimal: true });
|
package/src/scaffold.mjs
CHANGED
|
@@ -13,6 +13,33 @@ export const SHADCN_TEMPLATES = new Set([
|
|
|
13
13
|
"astro",
|
|
14
14
|
]);
|
|
15
15
|
|
|
16
|
+
/** 包管理器 → 一次性执行官方 CLI 的前缀形态 */
|
|
17
|
+
const DLX_PREFIX = {
|
|
18
|
+
pnpm: ["pnpm", "dlx"],
|
|
19
|
+
npm: ["npx", "-y"],
|
|
20
|
+
yarn: ["yarn", "dlx"],
|
|
21
|
+
bun: ["bunx"],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** 把命令串的执行器前缀换成目标 pm(pnpm dlx shadcn… → npx -y shadcn…)。
|
|
25
|
+
* pm 偏好切换后所有相关命令跟着变(2026-12-07 用户定案):CLI 侧对
|
|
26
|
+
* 「未自定义的默认命令」执行前替换——dash 侧切换时已把自定义命令改写存盘。 */
|
|
27
|
+
export function applyPmToCommand(command, pm) {
|
|
28
|
+
const prefix = DLX_PREFIX[pm];
|
|
29
|
+
if (!prefix) return command;
|
|
30
|
+
const parts = String(command).trim().split(/\s+/);
|
|
31
|
+
// 剥掉现有执行器前缀(已知四种形态),保留其余(命令体)
|
|
32
|
+
let i = 0;
|
|
33
|
+
if (parts[0] === "pnpm" && parts[1] === "dlx") i = 2;
|
|
34
|
+
else if (parts[0] === "npx" && parts[1] === "-y") i = 2;
|
|
35
|
+
else if ((parts[0] === "yarn" || parts[0] === "pnpm") && parts[1] === "dlx") i = 2;
|
|
36
|
+
else if (parts[0] === "yarn" && parts[1] === "dlx") i = 2;
|
|
37
|
+
else if (parts[0] === "npx") i = 1;
|
|
38
|
+
else if (parts[0] === "bunx") i = 1;
|
|
39
|
+
else if (parts[0] === "pnpm" || parts[0] === "yarn" || parts[0] === "npm" || parts[0] === "bun") i = 1;
|
|
40
|
+
return [...prefix, ...parts.slice(i)].join(" ");
|
|
41
|
+
}
|
|
42
|
+
|
|
16
43
|
/**
|
|
17
44
|
* 官方 shadcn init 作脚手架引擎(2026-12-06 用户需求:Next.js / preset /
|
|
18
45
|
* monorepo 等自定义):cui 前置直接执行官方 CLI(进度直通、components.json
|