@collectui/cli 0.2.30 → 0.2.32
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 +5 -0
- package/src/commands/common.mjs +6 -1
- package/src/commands/migrate.mjs +170 -0
- package/src/commands/setup.mjs +6 -0
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import { skillCmd } from "./commands/skill.mjs";
|
|
|
28
28
|
import { updateCmd } from "./commands/update.mjs";
|
|
29
29
|
import { applyCmd } from "./commands/apply.mjs";
|
|
30
30
|
import { prefsCmd } from "./commands/prefs.mjs";
|
|
31
|
+
import { cleanCmd, migrateCmd } from "./commands/migrate.mjs";
|
|
31
32
|
|
|
32
33
|
const HELP = `collectui ${CLI_VERSION} — one CLI for every shadcn library on CollectUI Dash
|
|
33
34
|
|
|
@@ -44,6 +45,8 @@ Commands:
|
|
|
44
45
|
add <lib> <comp...> Install components with the library's channel
|
|
45
46
|
mcp <sub> Manage MCP servers for your agents: show / init config
|
|
46
47
|
prefs <sub> Account preferences: ls / get / set (pm, pinned-agents)
|
|
48
|
+
migrate <dest> Move a temp project to a permanent location (configs follow)
|
|
49
|
+
clean Delete cui projects under the OS temp directory
|
|
47
50
|
skill [dir] Install the agent skill (.claude/skills/collectui)
|
|
48
51
|
doctor Verify login, registries, env and MCP config
|
|
49
52
|
update Update the CLI now (--check only checks)
|
|
@@ -114,6 +117,8 @@ const COMMANDS = {
|
|
|
114
117
|
add: { run: addCmd, aliases: ["install"] },
|
|
115
118
|
apply: { run: applyCmd, aliases: ["preset"] },
|
|
116
119
|
prefs: { run: prefsCmd, aliases: ["pref"] },
|
|
120
|
+
migrate: { run: migrateCmd, aliases: ["keep", "move"] },
|
|
121
|
+
clean: { run: cleanCmd, aliases: ["cleanup"] },
|
|
117
122
|
mcp: { run: mcpCmd, aliases: [] },
|
|
118
123
|
skill: { run: skillCmd, aliases: ["install-skill"] },
|
|
119
124
|
doctor: { run: doctorCmd, aliases: ["check"] },
|
package/src/commands/common.mjs
CHANGED
|
@@ -74,7 +74,12 @@ export async function selectLibs({ flags, me, reporter }) {
|
|
|
74
74
|
message: "Which libraries do you want to configure?",
|
|
75
75
|
options: owned.map((lib) => ({
|
|
76
76
|
value: lib.site,
|
|
77
|
-
|
|
77
|
+
// 显示名与 slug 同名(不区分大小写)只显示一个,不重复;
|
|
78
|
+
// 不同(如 React Bits/bits)才带 (slug)——slug 是 --libs 取值,有信息量
|
|
79
|
+
label:
|
|
80
|
+
lib.siteName.toLowerCase() === lib.site.toLowerCase()
|
|
81
|
+
? lib.siteName
|
|
82
|
+
: `${lib.siteName} (${lib.site})`,
|
|
78
83
|
})),
|
|
79
84
|
initialValues: preferred.length
|
|
80
85
|
? preferred
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { homedir, tmpdir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { displayPath } from "../changes.mjs";
|
|
5
|
+
import { CliError, usageError } from "../errors.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* cui migrate <dest> [src] —— 把临时目录里的 cui 项目迁移到正式位置保留
|
|
9
|
+
* (2026-12-06 用户需求:临时项目想复用就搬走,配置随目录整体走)。
|
|
10
|
+
*
|
|
11
|
+
* - 源默认 = OS 临时目录下的 cui 项目(collectui-app 或 --cwd/[src] 指定)
|
|
12
|
+
* - 目标必须不存在;跨设备 rename 失败(EXDEV)自动回退递归复制
|
|
13
|
+
* - 项目内配置(components.json / .env.local / .mcp.json / .collectui/)
|
|
14
|
+
* 全是相对文件,随目录迁移即完整;codex 全局配置(~/.codex)不随迁
|
|
15
|
+
*/
|
|
16
|
+
export async function migrateCmd(flags, rest, reporter) {
|
|
17
|
+
const destRaw = rest[0];
|
|
18
|
+
if (!destRaw) {
|
|
19
|
+
throw usageError("Where to? Pass a destination: cui migrate ~/dev/my-app", {
|
|
20
|
+
hint: MIGRATE_HELP,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const dest = destRaw.startsWith("~")
|
|
24
|
+
? join(homedir(), destRaw.slice(1))
|
|
25
|
+
: resolve(destRaw);
|
|
26
|
+
if (!isAbsolute(dest)) {
|
|
27
|
+
throw usageError(`Destination must be absolute or start with ~: ${destRaw}`);
|
|
28
|
+
}
|
|
29
|
+
const source = resolve(flags.cwd || rest[1] || join(tmpdir(), "collectui-app"));
|
|
30
|
+
|
|
31
|
+
if (!existsSync(source)) {
|
|
32
|
+
throw new CliError(`Nothing to migrate: ${displayPath(source)} does not exist.`, {
|
|
33
|
+
hint: "Run `cui init` first, or pass the source directory as the second argument.",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (!statSync(source).isDirectory()) {
|
|
37
|
+
throw new CliError(`${displayPath(source)} is not a directory.`);
|
|
38
|
+
}
|
|
39
|
+
if (existsSync(dest)) {
|
|
40
|
+
throw new CliError(`Destination already exists: ${displayPath(dest)}`, {
|
|
41
|
+
hint: "Pick a fresh path — migrate never overwrites existing content.",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!existsSync(join(source, ".collectui", "project.json"))) {
|
|
45
|
+
reporter.warn(
|
|
46
|
+
`${displayPath(source)} has no .collectui/project.json — migrating it anyway (not a cui-managed project?).`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ok = await reporter.confirm(
|
|
51
|
+
`Migrate ${displayPath(source)} → ${displayPath(dest)}?`,
|
|
52
|
+
{ defaultValue: true }
|
|
53
|
+
);
|
|
54
|
+
if (!ok) {
|
|
55
|
+
reporter.info("Aborted.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
mkdirSync(resolve(dest, ".."), { recursive: true });
|
|
60
|
+
let moved;
|
|
61
|
+
try {
|
|
62
|
+
renameSync(source, dest);
|
|
63
|
+
moved = "renamed";
|
|
64
|
+
} catch (e) {
|
|
65
|
+
if (e && (e.code === "EXDEV" || e.code === "EPERM")) {
|
|
66
|
+
// 跨设备/部分平台:递归复制后删源
|
|
67
|
+
cpSync(source, dest, { recursive: true });
|
|
68
|
+
rmSync(source, { recursive: true, force: true });
|
|
69
|
+
moved = "copied";
|
|
70
|
+
} else {
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
reporter.result({ from: source, to: dest, mode: moved });
|
|
75
|
+
reporter.outro(
|
|
76
|
+
`Migrated (${moved}) → ${displayPath(dest)} — configs (.env.local, MCP files) moved with it; open the project from the new path.`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* cui clean —— 立即删除 OS 临时目录里的 cui 项目(2026-12-06 用户需求)。
|
|
82
|
+
* 识别标志 = 目录内有 .collectui/project.json(我们脚手架写的);只删确认过的。
|
|
83
|
+
*/
|
|
84
|
+
export async function cleanCmd(flags, rest, reporter) {
|
|
85
|
+
const explicit = flags.cwd || rest[0];
|
|
86
|
+
const roots = explicit ? [resolve(explicit)] : cuiTmpProjects();
|
|
87
|
+
const targets = roots.filter((p) => existsSync(p));
|
|
88
|
+
|
|
89
|
+
if (targets.length === 0) {
|
|
90
|
+
reporter.info("No cui projects found in the OS temp directory. Nothing to clean.");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
for (const t of targets) {
|
|
94
|
+
const size = dirSize(t);
|
|
95
|
+
reporter.info(`${displayPath(t)} (${(size / 1024 / 1024).toFixed(1)} MB)`);
|
|
96
|
+
}
|
|
97
|
+
// headless(无交互)下删除必须显式 --yes——confirm 对 headless 恒 true,
|
|
98
|
+
// 破坏性操作不能吃这个默认
|
|
99
|
+
if (reporter.headless && !reporter.yes) {
|
|
100
|
+
reporter.info(
|
|
101
|
+
`Listed ${targets.length} director${targets.length === 1 ? "y" : "ies"} — re-run with --yes to delete.`
|
|
102
|
+
);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const ok = await reporter.confirm(
|
|
106
|
+
`Delete ${targets.length} director${targets.length === 1 ? "y" : "ies"} above? This cannot be undone.`,
|
|
107
|
+
{ defaultValue: false }
|
|
108
|
+
);
|
|
109
|
+
if (!ok) {
|
|
110
|
+
reporter.info("Aborted — nothing deleted.");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
for (const t of targets) {
|
|
114
|
+
rmSync(t, { recursive: true, force: true });
|
|
115
|
+
reporter.success(`Deleted ${displayPath(t)}`);
|
|
116
|
+
}
|
|
117
|
+
reporter.outro(`Cleaned ${targets.length} director${targets.length === 1 ? "y" : "ies"}.`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** tmpdir 下带 .collectui/project.json 标志的目录清单(名字升序) */
|
|
121
|
+
function cuiTmpProjects() {
|
|
122
|
+
const out = [];
|
|
123
|
+
let entries;
|
|
124
|
+
try {
|
|
125
|
+
entries = readdirSync(tmpdir());
|
|
126
|
+
} catch {
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
for (const name of entries.sort()) {
|
|
130
|
+
const p = join(tmpdir(), name);
|
|
131
|
+
try {
|
|
132
|
+
if (statSync(p).isDirectory() && existsSync(join(p, ".collectui", "project.json"))) {
|
|
133
|
+
out.push(p);
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
// 不可读的条目跳过
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function dirSize(dir) {
|
|
143
|
+
let total = 0;
|
|
144
|
+
const walk = (d) => {
|
|
145
|
+
for (const e of readdirSync(d, { withFileTypes: true })) {
|
|
146
|
+
const p = join(d, e.name);
|
|
147
|
+
if (e.isDirectory()) walk(p);
|
|
148
|
+
else {
|
|
149
|
+
try {
|
|
150
|
+
total += statSync(p).size;
|
|
151
|
+
} catch {
|
|
152
|
+
// 权限不可读的文件按 0 计
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
try {
|
|
158
|
+
walk(dir);
|
|
159
|
+
} catch {
|
|
160
|
+
// 统计失败返回 0
|
|
161
|
+
}
|
|
162
|
+
return total;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const MIGRATE_HELP = `Usage: cui migrate <dest> [src]
|
|
166
|
+
|
|
167
|
+
Move a throwaway temp project to a permanent location:
|
|
168
|
+
cui init # scaffold under the OS temp dir
|
|
169
|
+
cui migrate ~/dev/my-app # keep it — configs move with the directory
|
|
170
|
+
cui clean # delete cui projects under the OS temp dir`;
|
package/src/commands/setup.mjs
CHANGED
|
@@ -277,5 +277,11 @@ export async function runSetup({ flags, rest = [], reporter, mode }) {
|
|
|
277
277
|
reporter.outro(
|
|
278
278
|
`Done — ${libs.length} librar${libs.length === 1 ? "y" : "ies"} configured in ${cs.show(target)}.`
|
|
279
279
|
);
|
|
280
|
+
// 临时目录提示(2026-12-06 用户需求):OS 会自动清 + 迁移/删除出口
|
|
281
|
+
if (mode === "configure" && !reporter.headless && target.startsWith(tmpdir())) {
|
|
282
|
+
reporter.info(
|
|
283
|
+
`Heads-up: ${cs.show(target)} is a throwaway directory — the OS purges it automatically (macOS: ~3 days unused; Linux: on reboot). Keep the project? \`cui migrate ~/dev/${basename(target) || "my-app"}\` moves it with all configs. Done with it? \`cui clean\` deletes it now.`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
280
286
|
return summary;
|
|
281
287
|
}
|