@collectui/cli 0.2.41 → 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 -0
- package/src/commands/migrate.mjs +34 -1
- 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,6 +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 { warnShellInside } from "./migrate.mjs";
|
|
5
6
|
import { runSetup } from "./setup.mjs";
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -21,6 +22,9 @@ export async function initCmd(flags, rest, reporter) {
|
|
|
21
22
|
String(flags.name ?? "collectui-app").replace(/[\\/]+/g, "-")
|
|
22
23
|
);
|
|
23
24
|
if (existsSync(target) && statSync(target).isDirectory()) {
|
|
25
|
+
// CLI 自身先挪到 home(保自己不崩);init new 删完立即重建同路径,
|
|
26
|
+
// 用户 shell 停的原目录恢复有效——无需任何 cd
|
|
27
|
+
warnShellInside(target, reporter);
|
|
24
28
|
rmSync(target, { recursive: true, force: true });
|
|
25
29
|
reporter.info(`Removed previous project at ${displayPath(target)} — starting fresh.`);
|
|
26
30
|
}
|
package/src/commands/migrate.mjs
CHANGED
|
@@ -56,6 +56,8 @@ export async function migrateCmd(flags, rest, reporter) {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
const wasShellInside = shellInside(source);
|
|
60
|
+
warnShellInside(source, reporter);
|
|
59
61
|
mkdirSync(resolve(dest, ".."), { recursive: true });
|
|
60
62
|
let moved;
|
|
61
63
|
try {
|
|
@@ -73,7 +75,7 @@ export async function migrateCmd(flags, rest, reporter) {
|
|
|
73
75
|
}
|
|
74
76
|
reporter.result({ from: source, to: dest, mode: moved });
|
|
75
77
|
reporter.outro(
|
|
76
|
-
`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)})` : "."}`
|
|
77
79
|
);
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -111,12 +113,40 @@ export async function cleanCmd(flags, rest, reporter) {
|
|
|
111
113
|
return;
|
|
112
114
|
}
|
|
113
115
|
for (const t of targets) {
|
|
116
|
+
warnShellInside(t, reporter);
|
|
114
117
|
rmSync(t, { recursive: true, force: true });
|
|
115
118
|
reporter.success(`Deleted ${displayPath(t)}`);
|
|
116
119
|
}
|
|
117
120
|
reporter.outro(`Cleaned ${targets.length} director${targets.length === 1 ? "y" : "ies"}.`);
|
|
118
121
|
}
|
|
119
122
|
|
|
123
|
+
|
|
124
|
+
/** shell 的 cwd 是否在将被删除/移走的目录内(删除后下一条命令会 uv_cwd 崩,
|
|
125
|
+
* 2026-12-07 用户实锤:npx 直接 ENOENT)——删除前提示先 cd 出去 */
|
|
126
|
+
export function shellInside(path) {
|
|
127
|
+
try {
|
|
128
|
+
const cwd = process.cwd();
|
|
129
|
+
return cwd === path || cwd.startsWith(path + "/");
|
|
130
|
+
} catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function warnShellInside(path, reporter) {
|
|
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
|
+
}
|
|
144
|
+
reporter.warn(
|
|
145
|
+
`Your terminal is inside ${displayPath(path)} — the CLI moved itself to a safe directory. After this command: ${SHELL_CD_HINT}`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
120
150
|
/** tmpdir 下带 .collectui/project.json 标志的目录清单(名字升序) */
|
|
121
151
|
function cuiTmpProjects() {
|
|
122
152
|
const out = [];
|
|
@@ -162,6 +192,9 @@ function dirSize(dir) {
|
|
|
162
192
|
return total;
|
|
163
193
|
}
|
|
164
194
|
|
|
195
|
+
/** clean/migrate 后给 shell 卡位用户的一行指引(带反引号便于复制) */
|
|
196
|
+
const SHELL_CD_HINT = "`cd ~` (your shell's directory was removed)";
|
|
197
|
+
|
|
165
198
|
const MIGRATE_HELP = `Usage: cui migrate <dest> [src]
|
|
166
199
|
|
|
167
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
|