@icebreakers/monorepo 3.2.17 → 4.0.0
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/README.md +181 -52
- package/bin/mo.js +2 -0
- package/bin/rc.js +2 -0
- package/bin/repo.js +2 -0
- package/bin/repoctl.js +2 -0
- package/dist/cli.mjs +1067 -76
- package/dist/commands-MPDw9wMy.mjs +2501 -0
- package/dist/config-BGCo7USv.mjs +120 -0
- package/dist/create-flow-BEHRojMs.mjs +179 -0
- package/dist/index-BBxViYZd.d.mts +1049 -0
- package/dist/index.d.mts +383 -713
- package/dist/index.mjs +6 -2
- package/dist/rolldown-runtime-twds-ZHy.mjs +14 -0
- package/dist/tooling-DyUe-eiv.mjs +427 -0
- package/dist/tooling-entry.d.mts +2 -0
- package/dist/tooling-entry.mjs +2 -0
- package/dist/types-CRtyTy2K.mjs +213 -0
- package/dist/workspace-DS6LAL71.mjs +118 -0
- package/package.json +43 -34
- package/resources/skills/icebreakers-monorepo-cli/SKILL.md +12 -10
- package/resources/skills/icebreakers-monorepo-cli/references/commands.md +166 -21
- package/resources/skills/icebreakers-monorepo-cli/references/config.md +13 -9
- package/resources/skills/icebreakers-monorepo-cli/references/templates.md +30 -5
- package/tsconfig.base.json +23 -0
- package/dist/cli.cjs +0 -116
- package/dist/cli.d.cts +0 -1
- package/dist/index.cjs +0 -82
- package/dist/index.d.cts +0 -918
- package/dist/upgrade-CEtZ-XOF.mjs +0 -1513
- package/dist/upgrade-d3Q-0wfw.cjs +0 -1850
package/dist/cli.mjs
CHANGED
|
@@ -1,64 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as logger, g as fs, r as cliName, t as initToolingTargets, u as version } from "./types-CRtyTy2K.mjs";
|
|
2
|
+
import path from "pathe";
|
|
2
3
|
import process from "node:process";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
core: opts.core ?? false,
|
|
14
|
-
cwd
|
|
15
|
-
});
|
|
16
|
-
logger.success("upgrade @icebreakers/monorepo ok!");
|
|
17
|
-
});
|
|
18
|
-
program.command("init").description("初始化 package.json 和 README.md").action(async () => {
|
|
19
|
-
await init(cwd);
|
|
20
|
-
logger.success("init finished!");
|
|
21
|
-
});
|
|
22
|
-
program.command("sync").description("向 npmmirror 同步所有子包").action(async () => {
|
|
23
|
-
await syncNpmMirror(cwd);
|
|
24
|
-
logger.success("sync npm mirror finished!");
|
|
25
|
-
});
|
|
26
|
-
program.command("clean").description("清除选中的包").option("-y, --yes", "跳过交互直接清理(等价 autoConfirm)").option("--include-private", "包含 private 包").option("--pinned-version <version>", "覆盖写入的 @icebreakers/monorepo 版本").action(async (opts) => {
|
|
27
|
-
const overrides = {};
|
|
28
|
-
if (opts.yes) overrides.autoConfirm = true;
|
|
29
|
-
if (opts.includePrivate) overrides.includePrivate = true;
|
|
30
|
-
if (opts.pinnedVersion) overrides.pinnedVersion = opts.pinnedVersion;
|
|
31
|
-
await cleanProjects(cwd, overrides);
|
|
32
|
-
logger.success("clean projects finished!");
|
|
33
|
-
});
|
|
34
|
-
program.command("mirror").description("设置 VscodeBinaryMirror").action(async () => {
|
|
35
|
-
await setVscodeBinaryMirror(cwd);
|
|
36
|
-
logger.success("set vscode binary mirror finished!");
|
|
37
|
-
});
|
|
38
|
-
program.command("skills").description("技能工具集").command("sync").description("同步 resources/skills/icebreakers-monorepo-cli 到全局目录").option("--codex", "同步到 ~/.codex/skills").option("--claude", "同步到 ~/.claude/skills").option("--all", "同步全部目标").action(async (opts) => {
|
|
39
|
-
const selected = /* @__PURE__ */ new Set();
|
|
40
|
-
if (opts.all) for (const target of skillTargets) selected.add(target);
|
|
41
|
-
else {
|
|
42
|
-
if (opts.codex) selected.add("codex");
|
|
43
|
-
if (opts.claude) selected.add("claude");
|
|
44
|
-
}
|
|
45
|
-
const results = await syncSkills(selected.size ? {
|
|
46
|
-
cwd,
|
|
47
|
-
targets: [...selected]
|
|
48
|
-
} : { cwd });
|
|
49
|
-
if (!results.length) {
|
|
50
|
-
logger.info("未选择任何目标,已跳过同步。");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
logger.info(`[已同步的目标]:\n${results.map((item) => `- ${item.target}: ${item.dest}`).join("\n")}\n`);
|
|
54
|
-
logger.success("skills sync finished!");
|
|
55
|
-
});
|
|
56
|
-
program.command("ai").description("AI 助手工具集").command("create").alias("new").description("生成 Agentic 任务提示词模板").option("-o, --output <path>", "输出到指定文件").option("-f, --force", "允许覆盖已存在文件").option("--format <md|json>", "模板格式,默认 md").option("-d, --dir <path>", "默认输出目录(默认 agentic/prompts,下级自动创建时间文件夹),配合 --name / --tasks 使用").option("-n, --name <name>", "使用名称快速生成文件,自动添加后缀").option("-t, --tasks <file>", "从 JSON 数组批量生成模板").action(async (opts) => {
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
//#region src/cli/commands/ai.ts
|
|
8
|
+
async function handleAiPromptCreate(cwd, opts) {
|
|
9
|
+
const [{ input }, { createTimestampFolderName, defaultAgenticBaseDir, generateAgenticTemplate, generateAgenticTemplates, loadAgenticTasks }, { resolveCommandConfig }] = await Promise.all([
|
|
10
|
+
import("@icebreakers/monorepo-templates"),
|
|
11
|
+
import("./commands-MPDw9wMy.mjs").then((n) => n.t),
|
|
12
|
+
import("./config-BGCo7USv.mjs").then((n) => n.n)
|
|
13
|
+
]);
|
|
57
14
|
const aiConfig = await resolveCommandConfig("ai", cwd);
|
|
58
15
|
const format = opts.format ?? aiConfig?.format ?? "md";
|
|
59
16
|
const force = opts.force ?? aiConfig?.force ?? false;
|
|
60
17
|
const output = opts.output ?? aiConfig?.output;
|
|
61
|
-
const baseDir = opts.dir ?? aiConfig?.baseDir ??
|
|
18
|
+
const baseDir = opts.dir ?? aiConfig?.baseDir ?? defaultAgenticBaseDir;
|
|
62
19
|
const tasksFile = opts.tasks ?? aiConfig?.tasksFile;
|
|
63
20
|
const templateName = opts.name;
|
|
64
21
|
if (Boolean(tasksFile && !opts.output && !opts.name)) {
|
|
@@ -89,28 +46,1062 @@ program.command("ai").description("AI 助手工具集").command("create").alias(
|
|
|
89
46
|
if (templateName !== void 0) templateOptions.name = templateName;
|
|
90
47
|
if (folderName !== void 0) templateOptions.folderName = folderName;
|
|
91
48
|
await generateAgenticTemplate(templateOptions);
|
|
92
|
-
}
|
|
93
|
-
program
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
49
|
+
}
|
|
50
|
+
function registerAiCommands(program, cwd) {
|
|
51
|
+
program.command("ai").description("AI 助手工具集").command("prompt").alias("p").description("Prompt 模板命令").command("create").alias("new").description("生成 Agentic 任务提示词模板").option("-o, --output <path>", "输出到指定文件").option("-f, --force", "允许覆盖已存在文件").option("--format <md|json>", "模板格式,默认 md").option("-d, --dir <path>", "默认输出目录(默认 agentic/prompts,下级自动创建时间文件夹),配合 --name / --tasks 使用").option("-n, --name <name>", "使用名称快速生成文件,自动添加后缀").option("-t, --tasks <file>", "从 JSON 数组批量生成模板").action(async (opts) => {
|
|
52
|
+
await handleAiPromptCreate(cwd, opts);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/cli/commands/config.ts
|
|
57
|
+
function formatConfigInspection(inspection) {
|
|
58
|
+
const commandKeys = Object.keys(inspection.config.commands ?? {});
|
|
59
|
+
const toolingKeys = Object.keys(inspection.config.tooling ?? {});
|
|
60
|
+
return [
|
|
61
|
+
`cwd: ${inspection.cwd}`,
|
|
62
|
+
`file: ${inspection.file ?? "-"}`,
|
|
63
|
+
`commands: ${commandKeys.length > 0 ? commandKeys.join(", ") : "-"}`,
|
|
64
|
+
`tooling: ${toolingKeys.length > 0 ? toolingKeys.join(", ") : "-"}`
|
|
65
|
+
].join("\n");
|
|
66
|
+
}
|
|
67
|
+
function formatMarkdownTable$5(rows) {
|
|
68
|
+
const formatCell = (value) => String(value ?? "-").split("|").join("\\|").split("\n").join("<br>");
|
|
69
|
+
return [
|
|
70
|
+
"| Field | Value |",
|
|
71
|
+
"| --- | --- |",
|
|
72
|
+
...rows.map(([label, value]) => `| ${label} | ${formatCell(value)} |`)
|
|
73
|
+
].join("\n");
|
|
74
|
+
}
|
|
75
|
+
function formatConfigInspectionMarkdown(inspection) {
|
|
76
|
+
const commandKeys = Object.keys(inspection.config.commands ?? {});
|
|
77
|
+
const toolingKeys = Object.keys(inspection.config.tooling ?? {});
|
|
78
|
+
return [
|
|
79
|
+
"# Repo config inspection",
|
|
80
|
+
"",
|
|
81
|
+
formatMarkdownTable$5([
|
|
82
|
+
["cwd", inspection.cwd],
|
|
83
|
+
["file", inspection.file ?? "-"],
|
|
84
|
+
["commands", commandKeys.length],
|
|
85
|
+
["tooling", toolingKeys.length]
|
|
86
|
+
]),
|
|
87
|
+
"",
|
|
88
|
+
"## Commands",
|
|
89
|
+
"",
|
|
90
|
+
...commandKeys.length > 0 ? commandKeys.map((key) => `- ${key}`) : ["- -"],
|
|
91
|
+
"",
|
|
92
|
+
"## Tooling",
|
|
93
|
+
"",
|
|
94
|
+
...toolingKeys.length > 0 ? toolingKeys.map((key) => `- ${key}`) : ["- -"]
|
|
95
|
+
].join("\n");
|
|
96
|
+
}
|
|
97
|
+
function replaceAll$5(value, search, replacement) {
|
|
98
|
+
return search.length > 0 ? value.split(search).join(replacement) : value;
|
|
99
|
+
}
|
|
100
|
+
function redactConfigInspectionValue(value, replacements) {
|
|
101
|
+
if (typeof value === "string") return replacements.reduce((result, [search, replacement]) => replaceAll$5(result, search, replacement), value);
|
|
102
|
+
if (Array.isArray(value)) return value.map((item) => redactConfigInspectionValue(item, replacements));
|
|
103
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactConfigInspectionValue(item, replacements)]));
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
function redactConfigInspection(inspection) {
|
|
107
|
+
return redactConfigInspectionValue(inspection, [
|
|
108
|
+
[inspection.cwd, "<cwd>"],
|
|
109
|
+
[inspection.file ? path.dirname(inspection.file) : "", "<configDir>"],
|
|
110
|
+
[os.homedir(), "<home>"]
|
|
111
|
+
].filter(([search], index, entries) => search.length > 0 && entries.findIndex(([value]) => value === search) === index).sort(([left], [right]) => right.length - left.length));
|
|
112
|
+
}
|
|
113
|
+
async function emitConfigInspection(inspection, opts, cwd) {
|
|
114
|
+
const outputInspection = opts.redact ? redactConfigInspection(inspection) : inspection;
|
|
115
|
+
const content = opts.json ? JSON.stringify(outputInspection, null, 2) : opts.markdown ? formatConfigInspectionMarkdown(outputInspection) : formatConfigInspection(outputInspection);
|
|
116
|
+
if (!opts.out) {
|
|
117
|
+
logger.log(content);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const outFile = path.resolve(cwd, opts.out);
|
|
121
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
122
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
123
|
+
}
|
|
124
|
+
function registerConfigCommands(program, cwd) {
|
|
125
|
+
program.command("config").alias("cfg").description("配置命令").command("inspect").description("输出当前 repoctl 配置文件和已解析配置").alias("i").option("--json", "输出 JSON,方便脚本消费").option("--markdown", "输出 Markdown,方便粘贴到 issue 或 PR").option("--out <file>", "把当前输出写入文件").option("--redact", "脱敏 cwd/configDir/home 绝对路径后再输出").action(async (opts) => {
|
|
126
|
+
const { inspectMonorepoConfig } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
127
|
+
await emitConfigInspection(await inspectMonorepoConfig(cwd), opts, cwd);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/cli/commands/env/output.ts
|
|
132
|
+
function formatMarkdownTable$4(rows) {
|
|
133
|
+
const formatCell = (value) => String(value ?? "-").split("|").join("\\|").split("\n").join("<br>");
|
|
134
|
+
return [
|
|
135
|
+
"| Field | Value |",
|
|
136
|
+
"| --- | --- |",
|
|
137
|
+
...rows.map(([label, value]) => `| ${label} | ${formatCell(value)} |`)
|
|
138
|
+
].join("\n");
|
|
139
|
+
}
|
|
140
|
+
function formatEnvInfo$1(info) {
|
|
141
|
+
return [
|
|
142
|
+
`cwd: ${info.cwd}`,
|
|
143
|
+
`workspace: ${info.workspaceDir}`,
|
|
144
|
+
`packages: ${info.packageCount}`,
|
|
145
|
+
`node: ${info.nodeVersion}${info.nodeRange ? ` (${info.nodeRange})` : ""}`,
|
|
146
|
+
`pnpm: ${info.pnpmVersion ?? "-"}`,
|
|
147
|
+
`packageManager: ${info.packageManager ?? "-"}`,
|
|
148
|
+
`platform: ${info.platform}/${info.arch}`
|
|
149
|
+
].join("\n");
|
|
150
|
+
}
|
|
151
|
+
function formatEnvInfoMarkdown(info) {
|
|
152
|
+
return [
|
|
153
|
+
"# Repo environment",
|
|
154
|
+
"",
|
|
155
|
+
formatMarkdownTable$4([
|
|
156
|
+
["cwd", info.cwd],
|
|
157
|
+
["workspace", info.workspaceDir],
|
|
158
|
+
["packages", info.packageCount],
|
|
159
|
+
["node", info.nodeRange ? `${info.nodeVersion} (${info.nodeRange})` : info.nodeVersion],
|
|
160
|
+
["pnpm", info.pnpmVersion],
|
|
161
|
+
["packageManager", info.packageManager],
|
|
162
|
+
["platform", `${info.platform}/${info.arch}`]
|
|
163
|
+
])
|
|
164
|
+
].join("\n");
|
|
165
|
+
}
|
|
166
|
+
function formatEnvPathEntry(label, entry) {
|
|
167
|
+
return `${label}: ${entry.relativePath} (${entry.exists ? "exists" : "missing"})`;
|
|
168
|
+
}
|
|
169
|
+
function formatEnvPaths(paths) {
|
|
170
|
+
return [
|
|
171
|
+
`cwd: ${paths.cwd}`,
|
|
172
|
+
`workspace: ${paths.workspaceDir}`,
|
|
173
|
+
"",
|
|
174
|
+
formatEnvPathEntry("packageJson", paths.paths.packageJson),
|
|
175
|
+
formatEnvPathEntry("workspaceManifest", paths.paths.workspaceManifest),
|
|
176
|
+
formatEnvPathEntry("repoctlConfig", paths.paths.repoctlConfig),
|
|
177
|
+
...paths.paths.repoctlConfigs.map((entry) => formatEnvPathEntry("repoctlConfigCandidate", entry)),
|
|
178
|
+
formatEnvPathEntry("legacyConfig", paths.paths.legacyConfig),
|
|
179
|
+
...paths.paths.legacyConfigs.map((entry) => formatEnvPathEntry("legacyConfigCandidate", entry)),
|
|
180
|
+
formatEnvPathEntry("toolingDir", paths.paths.toolingDir),
|
|
181
|
+
formatEnvPathEntry("reportsDir", paths.paths.reportsDir),
|
|
182
|
+
formatEnvPathEntry("doctorReport", paths.paths.doctorReport),
|
|
183
|
+
formatEnvPathEntry("envReport", paths.paths.envReport),
|
|
184
|
+
formatEnvPathEntry("snapshotReport", paths.paths.snapshotReport),
|
|
185
|
+
formatEnvPathEntry("checkPlanReport", paths.paths.checkPlanReport)
|
|
186
|
+
].join("\n");
|
|
187
|
+
}
|
|
188
|
+
function formatEnvPathsMarkdown(paths) {
|
|
189
|
+
return [
|
|
190
|
+
"# Repo paths",
|
|
191
|
+
"",
|
|
192
|
+
formatMarkdownTable$4([["cwd", paths.cwd], ["workspace", paths.workspaceDir]]),
|
|
193
|
+
"",
|
|
194
|
+
"## Files",
|
|
195
|
+
"",
|
|
196
|
+
"| Path | Relative path | Status |",
|
|
197
|
+
"| --- | --- | --- |",
|
|
198
|
+
...Object.entries(paths.paths).flatMap(([label, value]) => Array.isArray(value) ? value.map((entry) => [label, entry]) : [[label, value]]).map(([label, entry]) => `| ${label} | ${entry.relativePath} | ${entry.exists ? "exists" : "missing"} |`)
|
|
199
|
+
].join("\n");
|
|
200
|
+
}
|
|
201
|
+
function formatEnvSnapshot(snapshot) {
|
|
202
|
+
return [
|
|
203
|
+
`generatedAt: ${snapshot.generatedAt}`,
|
|
204
|
+
"",
|
|
205
|
+
formatEnvInfo$1(snapshot.env),
|
|
206
|
+
"",
|
|
207
|
+
`doctor: ${snapshot.doctor.summary.pass} pass, ${snapshot.doctor.summary.warn} warn, ${snapshot.doctor.summary.fail} fail`,
|
|
208
|
+
`check: ${snapshot.checkPlan.mode}`,
|
|
209
|
+
...snapshot.checkPlan.commands.map((command) => `- ${command.command}`)
|
|
210
|
+
].join("\n");
|
|
211
|
+
}
|
|
212
|
+
function formatEnvSnapshotMarkdown(snapshot) {
|
|
213
|
+
const warningsAndFailures = snapshot.doctor.checks.filter((check) => check.status !== "pass");
|
|
214
|
+
return [
|
|
215
|
+
"# Repo environment snapshot",
|
|
216
|
+
"",
|
|
217
|
+
`Generated at: ${snapshot.generatedAt}`,
|
|
218
|
+
"",
|
|
219
|
+
"## Environment",
|
|
220
|
+
"",
|
|
221
|
+
formatMarkdownTable$4([
|
|
222
|
+
["cwd", snapshot.env.cwd],
|
|
223
|
+
["workspace", snapshot.env.workspaceDir],
|
|
224
|
+
["packages", snapshot.env.packageCount],
|
|
225
|
+
["node", snapshot.env.nodeRange ? `${snapshot.env.nodeVersion} (${snapshot.env.nodeRange})` : snapshot.env.nodeVersion],
|
|
226
|
+
["pnpm", snapshot.env.pnpmVersion],
|
|
227
|
+
["packageManager", snapshot.env.packageManager],
|
|
228
|
+
["platform", `${snapshot.env.platform}/${snapshot.env.arch}`]
|
|
229
|
+
]),
|
|
230
|
+
"",
|
|
231
|
+
"## Diagnostics",
|
|
232
|
+
"",
|
|
233
|
+
formatMarkdownTable$4([
|
|
234
|
+
["doctor pass", snapshot.doctor.summary.pass],
|
|
235
|
+
["doctor warn", snapshot.doctor.summary.warn],
|
|
236
|
+
["doctor fail", snapshot.doctor.summary.fail],
|
|
237
|
+
["check mode", snapshot.checkPlan.mode]
|
|
238
|
+
]),
|
|
239
|
+
"",
|
|
240
|
+
...warningsAndFailures.length > 0 ? [
|
|
241
|
+
"## Doctor findings",
|
|
242
|
+
"",
|
|
243
|
+
...warningsAndFailures.map((check) => `- ${check.status}: ${check.title}${check.fix ? ` (fix: ${check.fix})` : ""}`),
|
|
244
|
+
""
|
|
245
|
+
] : [],
|
|
246
|
+
"## Check plan",
|
|
247
|
+
"",
|
|
248
|
+
...snapshot.checkPlan.commands.map((command) => `- \`${command.command}\` - ${command.description}`)
|
|
249
|
+
].join("\n");
|
|
250
|
+
}
|
|
251
|
+
function replaceAll$4(value, search, replacement) {
|
|
252
|
+
return search.length > 0 ? value.split(search).join(replacement) : value;
|
|
253
|
+
}
|
|
254
|
+
function redactValue(value, replacements) {
|
|
255
|
+
if (typeof value === "string") return replacements.reduce((result, [search, replacement]) => replaceAll$4(result, search, replacement), value);
|
|
256
|
+
if (Array.isArray(value)) return value.map((item) => redactValue(item, replacements));
|
|
257
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactValue(item, replacements)]));
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
260
|
+
function createPathReplacements(cwd, workspaceDir) {
|
|
261
|
+
return [
|
|
262
|
+
[workspaceDir, "<workspace>"],
|
|
263
|
+
[cwd, "<cwd>"],
|
|
264
|
+
[os.homedir(), "<home>"]
|
|
265
|
+
].filter(([search], index, entries) => search.length > 0 && entries.findIndex(([value]) => value === search) === index).sort(([left], [right]) => right.length - left.length);
|
|
266
|
+
}
|
|
267
|
+
function redactEnvInfo(info) {
|
|
268
|
+
return redactValue(info, createPathReplacements(info.cwd, info.workspaceDir));
|
|
269
|
+
}
|
|
270
|
+
function redactEnvPaths(paths) {
|
|
271
|
+
return redactValue(paths, createPathReplacements(paths.cwd, paths.workspaceDir));
|
|
272
|
+
}
|
|
273
|
+
function redactEnvSnapshot(snapshot) {
|
|
274
|
+
return redactValue(snapshot, createPathReplacements(snapshot.env.cwd, snapshot.env.workspaceDir));
|
|
275
|
+
}
|
|
276
|
+
function createEnvInfoOutput(info, opts) {
|
|
277
|
+
const outputInfo = opts.redact ? redactEnvInfo(info) : info;
|
|
278
|
+
if (opts.json) return JSON.stringify(outputInfo, null, 2);
|
|
279
|
+
if (opts.markdown) return formatEnvInfoMarkdown(outputInfo);
|
|
280
|
+
return formatEnvInfo$1(outputInfo);
|
|
281
|
+
}
|
|
282
|
+
function createEnvPathsOutput(paths, opts) {
|
|
283
|
+
const outputPaths = opts.redact ? redactEnvPaths(paths) : paths;
|
|
284
|
+
if (opts.json) return JSON.stringify(outputPaths, null, 2);
|
|
285
|
+
if (opts.markdown) return formatEnvPathsMarkdown(outputPaths);
|
|
286
|
+
return formatEnvPaths(outputPaths);
|
|
287
|
+
}
|
|
288
|
+
function createEnvSnapshotOutput(snapshot, opts) {
|
|
289
|
+
const outputSnapshot = opts.redact ? redactEnvSnapshot(snapshot) : snapshot;
|
|
290
|
+
if (opts.json) return JSON.stringify(outputSnapshot, null, 2);
|
|
291
|
+
if (opts.markdown) return formatEnvSnapshotMarkdown(outputSnapshot);
|
|
292
|
+
return formatEnvSnapshot(outputSnapshot);
|
|
293
|
+
}
|
|
294
|
+
function hasStrictEnvSnapshotIssues(snapshot) {
|
|
295
|
+
return snapshot.doctor.summary.fail > 0 || snapshot.doctor.summary.warn > 0;
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/cli/commands/env/support.ts
|
|
299
|
+
function formatEnvInfo(info) {
|
|
300
|
+
return [
|
|
301
|
+
`cwd: ${info.cwd}`,
|
|
302
|
+
`workspace: ${info.workspaceDir}`,
|
|
303
|
+
`packages: ${info.packageCount}`,
|
|
304
|
+
`node: ${info.nodeVersion}${info.nodeRange ? ` (${info.nodeRange})` : ""}`,
|
|
305
|
+
`pnpm: ${info.pnpmVersion ?? "-"}`,
|
|
306
|
+
`packageManager: ${info.packageManager ?? "-"}`,
|
|
307
|
+
`platform: ${info.platform}/${info.arch}`
|
|
308
|
+
].join("\n");
|
|
309
|
+
}
|
|
310
|
+
function formatEnvSupportBundle(bundle) {
|
|
311
|
+
return [
|
|
312
|
+
`generatedAt: ${bundle.generatedAt}`,
|
|
313
|
+
"",
|
|
314
|
+
formatEnvInfo(bundle.env),
|
|
315
|
+
"",
|
|
316
|
+
`config: ${bundle.config.file ?? "-"}`,
|
|
317
|
+
`doctor: ${bundle.doctor.summary.pass} pass, ${bundle.doctor.summary.warn} warn, ${bundle.doctor.summary.fail} fail`,
|
|
318
|
+
`check: ${bundle.checkPlan.mode}`,
|
|
319
|
+
`paths: ${bundle.paths.workspaceDir}`,
|
|
320
|
+
...bundle.checkPlan.commands.map((command) => `- ${command.command}`)
|
|
321
|
+
].join("\n");
|
|
322
|
+
}
|
|
323
|
+
function formatMarkdownTable$3(rows) {
|
|
324
|
+
const formatCell = (value) => String(value ?? "-").split("|").join("\\|").split("\n").join("<br>");
|
|
325
|
+
return [
|
|
326
|
+
"| Field | Value |",
|
|
327
|
+
"| --- | --- |",
|
|
328
|
+
...rows.map(([label, value]) => `| ${label} | ${formatCell(value)} |`)
|
|
329
|
+
].join("\n");
|
|
330
|
+
}
|
|
331
|
+
function formatSupportBundleMarkdown(bundle) {
|
|
332
|
+
const warningsAndFailures = bundle.doctor.checks.filter((check) => check.status !== "pass");
|
|
333
|
+
return [
|
|
334
|
+
"# Repo support bundle",
|
|
335
|
+
"",
|
|
336
|
+
`Generated at: ${bundle.generatedAt}`,
|
|
337
|
+
"",
|
|
338
|
+
"## Environment",
|
|
339
|
+
"",
|
|
340
|
+
formatMarkdownTable$3([
|
|
341
|
+
["cwd", bundle.env.cwd],
|
|
342
|
+
["workspace", bundle.env.workspaceDir],
|
|
343
|
+
["packages", bundle.env.packageCount],
|
|
344
|
+
["node", bundle.env.nodeRange ? `${bundle.env.nodeVersion} (${bundle.env.nodeRange})` : bundle.env.nodeVersion],
|
|
345
|
+
["pnpm", bundle.env.pnpmVersion],
|
|
346
|
+
["packageManager", bundle.env.packageManager],
|
|
347
|
+
["platform", `${bundle.env.platform}/${bundle.env.arch}`]
|
|
348
|
+
]),
|
|
349
|
+
"",
|
|
350
|
+
"## Diagnostics",
|
|
351
|
+
"",
|
|
352
|
+
formatMarkdownTable$3([
|
|
353
|
+
["doctor pass", bundle.doctor.summary.pass],
|
|
354
|
+
["doctor warn", bundle.doctor.summary.warn],
|
|
355
|
+
["doctor fail", bundle.doctor.summary.fail],
|
|
356
|
+
["check mode", bundle.checkPlan.mode],
|
|
357
|
+
["config file", bundle.config.file ?? "-"]
|
|
358
|
+
]),
|
|
359
|
+
"",
|
|
360
|
+
...warningsAndFailures.length > 0 ? [
|
|
361
|
+
"## Doctor findings",
|
|
362
|
+
"",
|
|
363
|
+
...warningsAndFailures.map((check) => `- ${check.status}: ${check.title}${check.fix ? ` (fix: ${check.fix})` : ""}`),
|
|
364
|
+
""
|
|
365
|
+
] : [],
|
|
366
|
+
"## Check plan",
|
|
367
|
+
"",
|
|
368
|
+
...bundle.checkPlan.commands.map((command) => `- \`${command.command}\` - ${command.description}`),
|
|
369
|
+
"",
|
|
370
|
+
"## Report paths",
|
|
371
|
+
"",
|
|
372
|
+
formatMarkdownTable$3([
|
|
373
|
+
["doctor", bundle.paths.paths.doctorReport.relativePath],
|
|
374
|
+
["env", bundle.paths.paths.envReport.relativePath],
|
|
375
|
+
["snapshot", bundle.paths.paths.snapshotReport.relativePath],
|
|
376
|
+
["check plan", bundle.paths.paths.checkPlanReport.relativePath]
|
|
377
|
+
])
|
|
378
|
+
].join("\n");
|
|
379
|
+
}
|
|
380
|
+
function replaceAll$3(value, search, replacement) {
|
|
381
|
+
return search.length > 0 ? value.split(search).join(replacement) : value;
|
|
382
|
+
}
|
|
383
|
+
function redactSupportBundleValue(value, replacements) {
|
|
384
|
+
if (typeof value === "string") return replacements.reduce((result, [search, replacement]) => replaceAll$3(result, search, replacement), value);
|
|
385
|
+
if (Array.isArray(value)) return value.map((item) => redactSupportBundleValue(item, replacements));
|
|
386
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactSupportBundleValue(item, replacements)]));
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
function redactSupportBundle(bundle) {
|
|
390
|
+
return redactSupportBundleValue(bundle, [
|
|
391
|
+
[bundle.env.workspaceDir, "<workspace>"],
|
|
392
|
+
[bundle.env.cwd, "<cwd>"],
|
|
393
|
+
[os.homedir(), "<home>"]
|
|
394
|
+
].filter(([search], index, entries) => search.length > 0 && entries.findIndex(([value]) => value === search) === index).sort(([left], [right]) => right.length - left.length));
|
|
395
|
+
}
|
|
396
|
+
function createEnvSupportBundleOutput(bundle, opts) {
|
|
397
|
+
const outputBundle = opts.redact ? redactSupportBundle(bundle) : bundle;
|
|
398
|
+
return opts.json ? JSON.stringify(outputBundle, null, 2) : opts.markdown ? formatSupportBundleMarkdown(outputBundle) : formatEnvSupportBundle(outputBundle);
|
|
399
|
+
}
|
|
400
|
+
function hasStrictSupportBundleIssues(bundle) {
|
|
401
|
+
return bundle.doctor.summary.fail > 0 || bundle.doctor.summary.warn > 0;
|
|
402
|
+
}
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/cli/commands/env.ts
|
|
405
|
+
async function emitEnvInfo(info, opts, cwd) {
|
|
406
|
+
const content = createEnvInfoOutput(info, opts);
|
|
407
|
+
if (!opts.out) {
|
|
408
|
+
logger.log(content);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const outFile = path.resolve(cwd, opts.out);
|
|
412
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
413
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
414
|
+
}
|
|
415
|
+
async function emitEnvPaths(paths, opts, cwd) {
|
|
416
|
+
const content = createEnvPathsOutput(paths, opts);
|
|
417
|
+
if (!opts.out) {
|
|
418
|
+
logger.log(content);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const outFile = path.resolve(cwd, opts.out);
|
|
422
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
423
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
424
|
+
}
|
|
425
|
+
async function emitEnvSnapshot(snapshot, opts, cwd) {
|
|
426
|
+
const content = createEnvSnapshotOutput(snapshot, opts);
|
|
427
|
+
if (!opts.out) logger.log(content);
|
|
428
|
+
else {
|
|
429
|
+
const outFile = path.resolve(cwd, opts.out);
|
|
430
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
431
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
432
|
+
}
|
|
433
|
+
if (opts.strict && hasStrictEnvSnapshotIssues(snapshot)) process.exitCode = 1;
|
|
434
|
+
}
|
|
435
|
+
async function emitEnvSupportBundle(bundle, opts, cwd) {
|
|
436
|
+
const content = createEnvSupportBundleOutput(bundle, opts);
|
|
437
|
+
if (!opts.out) logger.log(content);
|
|
438
|
+
else {
|
|
439
|
+
const outFile = path.resolve(cwd, opts.out);
|
|
440
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
441
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
442
|
+
}
|
|
443
|
+
if (opts.strict && hasStrictSupportBundleIssues(bundle)) process.exitCode = 1;
|
|
444
|
+
}
|
|
445
|
+
function registerEnvCommands(program, cwd) {
|
|
446
|
+
const envCommand = program.command("env").alias("e").description("环境命令");
|
|
447
|
+
envCommand.command("info").description("输出当前仓库环境信息").alias("i").option("--json", "输出 JSON,方便脚本消费").option("--markdown", "输出 Markdown,方便粘贴到 issue 或 PR").option("--out <file>", "把当前输出写入文件").option("--redact", "脱敏 workspace/cwd/home 绝对路径后再输出").action(async (opts) => {
|
|
448
|
+
const { collectEnvInfo } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
449
|
+
await emitEnvInfo(await collectEnvInfo(cwd), opts, cwd);
|
|
109
450
|
});
|
|
110
|
-
|
|
111
|
-
});
|
|
451
|
+
envCommand.command("snapshot").description("输出排障快照,包含环境、doctor 和 check 计划").alias("s").option("--json", "输出 JSON,方便脚本消费").option("--markdown", "输出 Markdown,方便粘贴到 issue 或 PR").option("--out <file>", "把当前输出写入文件").option("--redact", "脱敏 workspace/cwd/home 绝对路径后再输出").option("--strict", "输出快照后,如果 doctor 有 fail 或 warn 则返回失败码").action(async (opts) => {
|
|
452
|
+
const { collectEnvSnapshot } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
453
|
+
await emitEnvSnapshot(await collectEnvSnapshot(cwd), opts, cwd);
|
|
454
|
+
});
|
|
455
|
+
envCommand.command("paths").description("输出当前仓库关键路径和报告建议位置").alias("p").option("--json", "输出 JSON,方便脚本消费").option("--markdown", "输出 Markdown,方便粘贴到 issue 或 PR").option("--out <file>", "把当前输出写入文件").option("--redact", "脱敏 workspace/cwd/home 绝对路径后再输出").action(async (opts) => {
|
|
456
|
+
const { collectEnvPaths } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
457
|
+
await emitEnvPaths(await collectEnvPaths(cwd), opts, cwd);
|
|
458
|
+
});
|
|
459
|
+
envCommand.command("support").description("输出完整排障包,包含环境、路径、配置、doctor 和 check 计划").alias("b").option("--json", "输出 JSON,方便脚本消费").option("--markdown", "输出 Markdown,方便粘贴到 issue 或 PR").option("--out <file>", "把当前输出写入文件").option("--redact", "脱敏 workspace/cwd/home 绝对路径后再输出").option("--strict", "输出排障包后,如果 doctor 有 fail 或 warn 则返回失败码").action(async (opts) => {
|
|
460
|
+
const { collectEnvSupportBundle } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
461
|
+
await emitEnvSupportBundle(await collectEnvSupportBundle(cwd), opts, cwd);
|
|
462
|
+
});
|
|
463
|
+
envCommand.command("mirror").description("设置 VS Code binary mirror").alias("m").action(async () => {
|
|
464
|
+
const { setVscodeBinaryMirror } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
465
|
+
await setVscodeBinaryMirror(cwd);
|
|
466
|
+
logger.success("env mirror finished!");
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/cli/commands/package.ts
|
|
471
|
+
function registerPackageCommands(program, cwd) {
|
|
472
|
+
program.command("package").alias("pkg").description("子包命令").command("create").description("创建一个新的子包").alias("new").argument("[name]").option("-t, --template <template>", "直接使用指定模板,跳过模板选择").option("--dry-run", "预览将要创建的目录与 package 信息,不写入文件").option("--json", "以 JSON 输出创建预览,隐含 --dry-run").option("--out <file>", "把创建预览写入文件,隐含 --dry-run").action(async (inputName, opts) => {
|
|
473
|
+
const { runCreateFlow } = await import("./create-flow-BEHRojMs.mjs");
|
|
474
|
+
const result = await runCreateFlow(cwd, inputName, {
|
|
475
|
+
...opts.template !== void 0 ? { template: opts.template } : {},
|
|
476
|
+
...opts.dryRun || opts.json || opts.out ? { dryRun: true } : {},
|
|
477
|
+
...opts.json ? { json: true } : {},
|
|
478
|
+
...opts.out !== void 0 ? { out: opts.out } : {}
|
|
479
|
+
});
|
|
480
|
+
if (result.dryRun || result.failed) return;
|
|
481
|
+
logger.success("package create finished!");
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/cli/commands/skills.ts
|
|
486
|
+
const skillTargets = ["codex", "claude"];
|
|
487
|
+
function registerSkillsCommands(program, cwd) {
|
|
488
|
+
program.command("skills").alias("sk").description("技能工具集").command("sync").description("同步 resources/skills/icebreakers-monorepo-cli 到全局目录").alias("s").option("--codex", "同步到 ~/.codex/skills").option("--claude", "同步到 ~/.claude/skills").option("--all", "同步全部目标").action(async (opts) => {
|
|
489
|
+
const { syncSkills } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
490
|
+
const selected = /* @__PURE__ */ new Set();
|
|
491
|
+
if (opts.all) for (const target of skillTargets) selected.add(target);
|
|
492
|
+
else {
|
|
493
|
+
if (opts.codex) selected.add("codex");
|
|
494
|
+
if (opts.claude) selected.add("claude");
|
|
495
|
+
}
|
|
496
|
+
const results = await syncSkills(selected.size ? {
|
|
497
|
+
cwd,
|
|
498
|
+
targets: [...selected]
|
|
499
|
+
} : { cwd });
|
|
500
|
+
if (!results.length) {
|
|
501
|
+
logger.info("未选择任何目标,已跳过同步。");
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
logger.info(`[已同步的目标]:\n${results.map((item) => `- ${item.target}: ${item.dest}`).join("\n")}\n`);
|
|
505
|
+
logger.success("skills sync finished!");
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/cli/commands/templates.ts
|
|
510
|
+
function formatTemplateTable(choices) {
|
|
511
|
+
const rows = choices.map((choice) => ({
|
|
512
|
+
key: choice.key,
|
|
513
|
+
category: choice.category ?? "-",
|
|
514
|
+
target: choice.target,
|
|
515
|
+
description: choice.description ?? ""
|
|
516
|
+
}));
|
|
517
|
+
const headers = {
|
|
518
|
+
key: "key",
|
|
519
|
+
category: "category",
|
|
520
|
+
target: "target",
|
|
521
|
+
description: "description"
|
|
522
|
+
};
|
|
523
|
+
const widths = {
|
|
524
|
+
key: Math.max(headers.key.length, ...rows.map((row) => row.key.length)),
|
|
525
|
+
category: Math.max(headers.category.length, ...rows.map((row) => row.category.length)),
|
|
526
|
+
target: Math.max(headers.target.length, ...rows.map((row) => row.target.length))
|
|
527
|
+
};
|
|
528
|
+
return [
|
|
529
|
+
`${headers.key.padEnd(widths.key)} ${headers.category.padEnd(widths.category)} ${headers.target.padEnd(widths.target)} ${headers.description}`,
|
|
530
|
+
`${"-".repeat(widths.key)} ${"-".repeat(widths.category)} ${"-".repeat(widths.target)} ${"-".repeat(headers.description.length)}`,
|
|
531
|
+
...rows.map((row) => `${row.key.padEnd(widths.key)} ${row.category.padEnd(widths.category)} ${row.target.padEnd(widths.target)} ${row.description}`)
|
|
532
|
+
].join("\n");
|
|
533
|
+
}
|
|
534
|
+
function formatTemplateDetail(choice) {
|
|
535
|
+
return [
|
|
536
|
+
`key: ${choice.key}`,
|
|
537
|
+
`label: ${choice.label}`,
|
|
538
|
+
`category: ${choice.category ?? "-"}`,
|
|
539
|
+
`source: templates/${choice.source}`,
|
|
540
|
+
`default target: ${choice.target}`,
|
|
541
|
+
`description: ${choice.description ?? "-"}`
|
|
542
|
+
].join("\n");
|
|
543
|
+
}
|
|
544
|
+
function escapeMarkdownTableCell(value) {
|
|
545
|
+
return value.replaceAll("|", "\\|");
|
|
546
|
+
}
|
|
547
|
+
function formatTemplateMarkdownTable(choices) {
|
|
548
|
+
return [
|
|
549
|
+
"| Key | Category | Source | Default target | Description |",
|
|
550
|
+
"| --- | --- | --- | --- | --- |",
|
|
551
|
+
...choices.map((choice) => [
|
|
552
|
+
`\`${choice.key}\``,
|
|
553
|
+
choice.category ?? "-",
|
|
554
|
+
`\`templates/${choice.source}\``,
|
|
555
|
+
`\`${choice.target}\``,
|
|
556
|
+
choice.description ?? ""
|
|
557
|
+
].map((value) => escapeMarkdownTableCell(value)).join(" | ")).map((row) => `| ${row} |`)
|
|
558
|
+
].join("\n");
|
|
559
|
+
}
|
|
560
|
+
function formatTemplateMarkdownDetail(choice) {
|
|
561
|
+
return [
|
|
562
|
+
`# ${choice.key}`,
|
|
563
|
+
"",
|
|
564
|
+
choice.description ?? "",
|
|
565
|
+
"",
|
|
566
|
+
"| Field | Value |",
|
|
567
|
+
"| --- | --- |",
|
|
568
|
+
`| Label | ${escapeMarkdownTableCell(choice.label)} |`,
|
|
569
|
+
`| Category | ${escapeMarkdownTableCell(choice.category ?? "-")} |`,
|
|
570
|
+
`| Source | \`templates/${escapeMarkdownTableCell(choice.source)}\` |`,
|
|
571
|
+
`| Default target | \`${escapeMarkdownTableCell(choice.target)}\` |`
|
|
572
|
+
].join("\n");
|
|
573
|
+
}
|
|
574
|
+
function formatTemplateHealthStatus(status) {
|
|
575
|
+
if (status === "pass") return pc.green("PASS");
|
|
576
|
+
if (status === "warn") return pc.yellow("WARN");
|
|
577
|
+
return pc.red("FAIL");
|
|
578
|
+
}
|
|
579
|
+
function formatTemplateHealthReport(report, color = false) {
|
|
580
|
+
const status = color ? formatTemplateHealthStatus : (value) => value.toUpperCase();
|
|
581
|
+
const lines = [
|
|
582
|
+
`templates: ${report.templatesDir}`,
|
|
583
|
+
`count: ${report.templateCount}`,
|
|
584
|
+
""
|
|
585
|
+
];
|
|
586
|
+
for (const check of report.checks) {
|
|
587
|
+
const prefix = check.template ? `${check.template}: ` : "";
|
|
588
|
+
lines.push(`[${status(check.status)}] ${prefix}${check.title}`);
|
|
589
|
+
lines.push(` ${check.detail}`);
|
|
590
|
+
if (check.fix) lines.push(` fix: ${check.fix}`);
|
|
591
|
+
}
|
|
592
|
+
lines.push("");
|
|
593
|
+
lines.push(color ? `summary: ${pc.green(String(report.summary.pass))} pass, ${pc.yellow(String(report.summary.warn))} warn, ${pc.red(String(report.summary.fail))} fail` : `summary: ${report.summary.pass} pass, ${report.summary.warn} warn, ${report.summary.fail} fail`);
|
|
594
|
+
return lines.join("\n");
|
|
595
|
+
}
|
|
596
|
+
async function emitTemplateOutput(content, options) {
|
|
597
|
+
if (!options.out) {
|
|
598
|
+
logger.log(content);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
const outFile = path.resolve(process.cwd(), options.out);
|
|
602
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
603
|
+
logger.success(`wrote ${path.relative(process.cwd(), outFile)}`);
|
|
604
|
+
}
|
|
605
|
+
function registerTemplatesCommands(program) {
|
|
606
|
+
program.command("templates").alias("tpl").description("列出可用的内置模板").argument("[key]", "查看指定模板详情").option("-c, --category <category>", "按模板分类过滤:library / app / service / docs / tool").option("--check", "检查内置模板元数据、目录和临时文件").option("--json", "输出 JSON,方便脚本消费").option("--markdown", "输出 Markdown,方便同步文档").option("--out <file>", "把当前输出写入文件").action(async (key, opts) => {
|
|
607
|
+
const { getTemplateChoice, getTemplateChoices, isTemplateCategory, suggestTemplateKey, templateCategories } = await import("@icebreakers/monorepo-templates");
|
|
608
|
+
if (opts.check) {
|
|
609
|
+
const { checkTemplates } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
610
|
+
const report = await checkTemplates();
|
|
611
|
+
if (opts.json) await emitTemplateOutput(JSON.stringify(report, null, 2), opts);
|
|
612
|
+
else await emitTemplateOutput(formatTemplateHealthReport(report, !opts.out), opts);
|
|
613
|
+
if (report.summary.fail > 0) process.exitCode = 1;
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (key) {
|
|
617
|
+
const choice = getTemplateChoice(key);
|
|
618
|
+
if (!choice) {
|
|
619
|
+
logger.error(`unknown template: ${key}`);
|
|
620
|
+
const suggestion = suggestTemplateKey(key);
|
|
621
|
+
if (suggestion) logger.info(`did you mean \`${suggestion}\`?`);
|
|
622
|
+
logger.info("run `repo templates` to list available templates");
|
|
623
|
+
process.exitCode = 1;
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (opts.json) {
|
|
627
|
+
await emitTemplateOutput(JSON.stringify(choice, null, 2), opts);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (opts.markdown) {
|
|
631
|
+
await emitTemplateOutput(formatTemplateMarkdownDetail(choice), opts);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
await emitTemplateOutput(`Template detail:\n${formatTemplateDetail(choice)}`, opts);
|
|
635
|
+
if (!opts.out) logger.info(`next: run \`repo new <name> --template ${choice.key}\``);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
let category;
|
|
639
|
+
if (opts.category) {
|
|
640
|
+
if (!isTemplateCategory(opts.category)) {
|
|
641
|
+
logger.error(`unknown template category: ${opts.category}`);
|
|
642
|
+
logger.info(`available categories: ${templateCategories.join(", ")}`);
|
|
643
|
+
process.exitCode = 1;
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
category = opts.category;
|
|
647
|
+
}
|
|
648
|
+
const choices = getTemplateChoices(category ? { category } : {});
|
|
649
|
+
if (opts.json) {
|
|
650
|
+
await emitTemplateOutput(JSON.stringify(choices, null, 2), opts);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (opts.markdown) {
|
|
654
|
+
await emitTemplateOutput(formatTemplateMarkdownTable(choices), opts);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
await emitTemplateOutput(`Available templates:\n${formatTemplateTable(choices)}`, opts);
|
|
658
|
+
if (!opts.out) logger.info("next: run `repo new <name> --template <key>`");
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
//#endregion
|
|
662
|
+
//#region src/cli/utils.ts
|
|
663
|
+
function normalizeCliOpts(cwd, opts) {
|
|
664
|
+
return {
|
|
665
|
+
...opts,
|
|
666
|
+
core: opts.core ?? false,
|
|
667
|
+
cwd
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function normalizeCleanOptions(opts) {
|
|
671
|
+
const overrides = {};
|
|
672
|
+
if (opts.yes) overrides.autoConfirm = true;
|
|
673
|
+
if (opts.includePrivate) overrides.includePrivate = true;
|
|
674
|
+
if (opts.pinnedVersion) overrides.pinnedVersion = opts.pinnedVersion;
|
|
675
|
+
return overrides;
|
|
676
|
+
}
|
|
677
|
+
function normalizeToolingTargets(tooling) {
|
|
678
|
+
if (!tooling.length) return;
|
|
679
|
+
const unknown = tooling.filter((item) => !initToolingTargets.includes(item));
|
|
680
|
+
if (unknown.length > 0) throw new Error(`未知的 init tooling 目标: ${unknown.join(", ")}`);
|
|
681
|
+
return tooling;
|
|
682
|
+
}
|
|
683
|
+
//#endregion
|
|
684
|
+
//#region src/cli/commands/tooling.ts
|
|
685
|
+
function registerToolingCommands(program, cwd) {
|
|
686
|
+
program.command("tooling").alias("tg").description("工程化配置命令").command("init").description(`生成 tooling 配置(可选值:${initToolingTargets.join(", ")})`).alias("i").argument("[tooling...]").option("-a, --all", "生成全部 tooling 配置").option("-f, --force", "覆盖已存在的 tooling 配置文件").action(async (tooling = [], opts) => {
|
|
687
|
+
const normalizedTooling = normalizeToolingTargets(tooling);
|
|
688
|
+
const { initTooling } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
689
|
+
await initTooling(cwd, {
|
|
690
|
+
...normalizedTooling ? { targets: normalizedTooling } : {},
|
|
691
|
+
...opts.all !== void 0 ? { all: opts.all } : {},
|
|
692
|
+
...opts.force !== void 0 ? { force: opts.force } : {}
|
|
693
|
+
});
|
|
694
|
+
logger.success("tooling init finished!");
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
//#endregion
|
|
698
|
+
//#region src/cli/commands/check/output.ts
|
|
699
|
+
function formatCheckPlan(plan) {
|
|
700
|
+
const lines = [
|
|
701
|
+
`cwd: ${plan.cwd}`,
|
|
702
|
+
`mode: ${plan.mode}`,
|
|
703
|
+
""
|
|
704
|
+
];
|
|
705
|
+
for (const command of plan.commands) {
|
|
706
|
+
lines.push(`- ${command.command}`);
|
|
707
|
+
lines.push(` ${command.description}`);
|
|
708
|
+
}
|
|
709
|
+
return lines.join("\n");
|
|
710
|
+
}
|
|
711
|
+
function formatMarkdownTable$2(rows) {
|
|
712
|
+
const formatCell = (value) => String(value ?? "-").split("|").join("\\|").split("\n").join("<br>");
|
|
713
|
+
return [
|
|
714
|
+
"| Field | Value |",
|
|
715
|
+
"| --- | --- |",
|
|
716
|
+
...rows.map(([label, value]) => `| ${label} | ${formatCell(value)} |`)
|
|
717
|
+
].join("\n");
|
|
718
|
+
}
|
|
719
|
+
function formatCheckPlanMarkdown(plan) {
|
|
720
|
+
return [
|
|
721
|
+
"# Repo check plan",
|
|
722
|
+
"",
|
|
723
|
+
formatMarkdownTable$2([
|
|
724
|
+
["cwd", plan.cwd],
|
|
725
|
+
["mode", plan.mode],
|
|
726
|
+
["commands", plan.commands.length]
|
|
727
|
+
]),
|
|
728
|
+
"",
|
|
729
|
+
"## Commands",
|
|
730
|
+
"",
|
|
731
|
+
...plan.commands.map((command) => `- \`${command.command}\` - ${command.description}`)
|
|
732
|
+
].join("\n");
|
|
733
|
+
}
|
|
734
|
+
function replaceAll$2(value, search, replacement) {
|
|
735
|
+
return search.length > 0 ? value.split(search).join(replacement) : value;
|
|
736
|
+
}
|
|
737
|
+
function redactCheckPlanValue(value, replacements) {
|
|
738
|
+
if (typeof value === "string") return replacements.reduce((result, [search, replacement]) => replaceAll$2(result, search, replacement), value);
|
|
739
|
+
if (Array.isArray(value)) return value.map((item) => redactCheckPlanValue(item, replacements));
|
|
740
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactCheckPlanValue(item, replacements)]));
|
|
741
|
+
return value;
|
|
742
|
+
}
|
|
743
|
+
function redactCheckPlan(plan) {
|
|
744
|
+
return redactCheckPlanValue(plan, [[plan.cwd, "<cwd>"], [os.homedir(), "<home>"]].filter(([search], index, entries) => search.length > 0 && entries.findIndex(([value]) => value === search) === index).sort(([left], [right]) => right.length - left.length));
|
|
745
|
+
}
|
|
746
|
+
function createCheckPlanOutput(plan, opts) {
|
|
747
|
+
const outputPlan = opts.redact ? redactCheckPlan(plan) : plan;
|
|
748
|
+
if (opts.json) return JSON.stringify(outputPlan, null, 2);
|
|
749
|
+
if (opts.markdown) return formatCheckPlanMarkdown(outputPlan);
|
|
750
|
+
return formatCheckPlan(outputPlan);
|
|
751
|
+
}
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/cli/commands/doctor/output.ts
|
|
754
|
+
function formatDoctorStatus(status) {
|
|
755
|
+
if (status === "pass") return pc.green("PASS");
|
|
756
|
+
if (status === "warn") return pc.yellow("WARN");
|
|
757
|
+
return pc.red("FAIL");
|
|
758
|
+
}
|
|
759
|
+
function formatDoctorReport(report, color = false) {
|
|
760
|
+
const status = color ? formatDoctorStatus : (value) => value.toUpperCase();
|
|
761
|
+
const lines = [
|
|
762
|
+
`workspace: ${report.workspaceDir}`,
|
|
763
|
+
`packages: ${report.packageCount}`,
|
|
764
|
+
""
|
|
765
|
+
];
|
|
766
|
+
for (const check of report.checks) {
|
|
767
|
+
lines.push(`[${status(check.status)}] ${check.title}`);
|
|
768
|
+
lines.push(` ${check.detail}`);
|
|
769
|
+
if (check.fix) lines.push(` fix: ${check.fix}`);
|
|
770
|
+
}
|
|
771
|
+
lines.push("");
|
|
772
|
+
lines.push(color ? `summary: ${pc.green(String(report.summary.pass))} pass, ${pc.yellow(String(report.summary.warn))} warn, ${pc.red(String(report.summary.fail))} fail` : `summary: ${report.summary.pass} pass, ${report.summary.warn} warn, ${report.summary.fail} fail`);
|
|
773
|
+
return lines.join("\n");
|
|
774
|
+
}
|
|
775
|
+
function formatMarkdownTable$1(rows) {
|
|
776
|
+
const formatCell = (value) => String(value ?? "-").split("|").join("\\|").split("\n").join("<br>");
|
|
777
|
+
return [
|
|
778
|
+
"| Field | Value |",
|
|
779
|
+
"| --- | --- |",
|
|
780
|
+
...rows.map(([label, value]) => `| ${label} | ${formatCell(value)} |`)
|
|
781
|
+
].join("\n");
|
|
782
|
+
}
|
|
783
|
+
function formatDoctorMarkdown(report) {
|
|
784
|
+
const warningsAndFailures = report.checks.filter((check) => check.status !== "pass");
|
|
785
|
+
return [
|
|
786
|
+
"# Repo doctor report",
|
|
787
|
+
"",
|
|
788
|
+
formatMarkdownTable$1([
|
|
789
|
+
["workspace", report.workspaceDir],
|
|
790
|
+
["packages", report.packageCount],
|
|
791
|
+
["pass", report.summary.pass],
|
|
792
|
+
["warn", report.summary.warn],
|
|
793
|
+
["fail", report.summary.fail]
|
|
794
|
+
]),
|
|
795
|
+
"",
|
|
796
|
+
...warningsAndFailures.length > 0 ? [
|
|
797
|
+
"## Findings",
|
|
798
|
+
"",
|
|
799
|
+
...warningsAndFailures.map((check) => `- ${check.status}: ${check.title}${check.fix ? ` (fix: ${check.fix})` : ""}`),
|
|
800
|
+
""
|
|
801
|
+
] : [],
|
|
802
|
+
"## Checks",
|
|
803
|
+
"",
|
|
804
|
+
...report.checks.map((check) => `- ${check.status}: ${check.title}`)
|
|
805
|
+
].join("\n");
|
|
806
|
+
}
|
|
807
|
+
function replaceAll$1(value, search, replacement) {
|
|
808
|
+
return search.length > 0 ? value.split(search).join(replacement) : value;
|
|
809
|
+
}
|
|
810
|
+
function redactDoctorReportValue(value, replacements) {
|
|
811
|
+
if (typeof value === "string") return replacements.reduce((result, [search, replacement]) => replaceAll$1(result, search, replacement), value);
|
|
812
|
+
if (Array.isArray(value)) return value.map((item) => redactDoctorReportValue(item, replacements));
|
|
813
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactDoctorReportValue(item, replacements)]));
|
|
814
|
+
return value;
|
|
815
|
+
}
|
|
816
|
+
function redactDoctorReport(report) {
|
|
817
|
+
return redactDoctorReportValue(report, [
|
|
818
|
+
[report.workspaceDir, "<workspace>"],
|
|
819
|
+
[report.cwd, "<cwd>"],
|
|
820
|
+
[os.homedir(), "<home>"]
|
|
821
|
+
].filter(([search], index, entries) => search.length > 0 && entries.findIndex(([value]) => value === search) === index).sort(([left], [right]) => right.length - left.length));
|
|
822
|
+
}
|
|
823
|
+
function createDoctorReportOutput(report, opts) {
|
|
824
|
+
const outputReport = opts.redact ? redactDoctorReport(report) : report;
|
|
825
|
+
if (opts.json) return JSON.stringify(outputReport, null, 2);
|
|
826
|
+
if (opts.markdown) return formatDoctorMarkdown(outputReport);
|
|
827
|
+
return formatDoctorReport(outputReport);
|
|
828
|
+
}
|
|
829
|
+
function createInteractiveDoctorReportOutput(report, opts) {
|
|
830
|
+
return formatDoctorReport(opts.redact ? redactDoctorReport(report) : report, true);
|
|
831
|
+
}
|
|
832
|
+
function hasDoctorBlockingIssues(report, opts) {
|
|
833
|
+
return report.summary.fail > 0 || opts.strict === true && report.summary.warn > 0;
|
|
834
|
+
}
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region src/cli/commands/top-level.ts
|
|
837
|
+
async function emitDoctorReport(report, opts, cwd) {
|
|
838
|
+
const content = opts.json || opts.markdown || opts.out ? createDoctorReportOutput(report, opts) : createInteractiveDoctorReportOutput(report, opts);
|
|
839
|
+
if (!opts.out) {
|
|
840
|
+
logger.log(content);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
const outFile = path.resolve(cwd, opts.out);
|
|
844
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
845
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
846
|
+
}
|
|
847
|
+
async function emitCheckPlan(plan, opts, cwd) {
|
|
848
|
+
const content = createCheckPlanOutput(plan, opts);
|
|
849
|
+
if (!opts.out) {
|
|
850
|
+
logger.log(content);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const outFile = path.resolve(cwd, opts.out);
|
|
854
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
855
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
856
|
+
}
|
|
857
|
+
function registerTopLevelCommands(program, cwd) {
|
|
858
|
+
program.command("init").description("初始化当前 workspace,并生成推荐配置").alias("setup").option("--preset <preset>", "初始化预设:minimal / standard", "standard").option("-f, --force", "覆盖已存在的 tooling 配置文件").action(async (opts) => {
|
|
859
|
+
const { init } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
860
|
+
await init(cwd, {
|
|
861
|
+
...opts.preset !== void 0 ? { preset: opts.preset } : {},
|
|
862
|
+
...opts.force !== void 0 ? { force: opts.force } : {}
|
|
863
|
+
});
|
|
864
|
+
logger.success("init finished!");
|
|
865
|
+
logger.info("next: run `pnpm install` and `pnpm build`");
|
|
866
|
+
});
|
|
867
|
+
program.command("new").description("创建新的 package / app").argument("[name]").option("-t, --template <template>", "直接使用指定模板,跳过模板选择").option("--dry-run", "预览将要创建的目录与 package 信息,不写入文件").option("--json", "以 JSON 输出创建预览,隐含 --dry-run").option("--out <file>", "把创建预览写入文件,隐含 --dry-run").action(async (inputName, opts) => {
|
|
868
|
+
const { runCreateFlow } = await import("./create-flow-BEHRojMs.mjs");
|
|
869
|
+
const result = await runCreateFlow(cwd, inputName, {
|
|
870
|
+
...opts.template !== void 0 ? { template: opts.template } : {},
|
|
871
|
+
...opts.dryRun || opts.json || opts.out ? { dryRun: true } : {},
|
|
872
|
+
...opts.json ? { json: true } : {},
|
|
873
|
+
...opts.out !== void 0 ? { out: opts.out } : {}
|
|
874
|
+
});
|
|
875
|
+
if (result.dryRun || result.failed) return;
|
|
876
|
+
logger.success("new finished!");
|
|
877
|
+
logger.info("next: run `pnpm install` and start the new workspace package");
|
|
878
|
+
});
|
|
879
|
+
program.command("check").description("执行推荐的本地校验").option("--full", "执行完整校验").option("--staged", "仅执行 staged 相关校验").option("--edit-file <file>", "执行 commit message 校验").option("--dry-run", "预览将要执行的校验,不实际运行").option("--json", "以 JSON 输出校验计划,隐含 --dry-run").option("--markdown", "以 Markdown 输出校验计划,隐含 --dry-run").option("--out <file>", "把校验计划写入文件,隐含 --dry-run").option("--redact", "脱敏 cwd/home 绝对路径后再输出").action(async (opts) => {
|
|
880
|
+
const options = {
|
|
881
|
+
cwd,
|
|
882
|
+
...opts.full !== void 0 ? { full: opts.full } : {},
|
|
883
|
+
...opts.staged !== void 0 ? { staged: opts.staged } : {},
|
|
884
|
+
...opts.editFile !== void 0 ? { editFile: opts.editFile } : {}
|
|
885
|
+
};
|
|
886
|
+
const { resolveRecommendedCheckPlan, runRecommendedCheck } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
887
|
+
if (opts.dryRun || opts.json || opts.markdown || opts.out) {
|
|
888
|
+
await emitCheckPlan(resolveRecommendedCheckPlan(options), opts, cwd);
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
await runRecommendedCheck(options);
|
|
892
|
+
logger.success("check finished!");
|
|
893
|
+
});
|
|
894
|
+
program.command("doctor").description("诊断当前仓库是否适合直接开始使用").option("--json", "输出 JSON 报告,方便 CI 或脚本消费").option("--markdown", "输出 Markdown 报告,方便粘贴到 issue 或 PR").option("--out <file>", "把诊断报告写入文件").option("--redact", "脱敏 workspace/cwd/home 绝对路径后再输出").option("--strict", "把 warning 也视为失败,适合 CI 门禁").action(async (opts) => {
|
|
895
|
+
const { runDoctor } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
896
|
+
const report = await runDoctor(cwd);
|
|
897
|
+
await emitDoctorReport(report, opts, cwd);
|
|
898
|
+
if (opts.out || opts.json || opts.markdown) {
|
|
899
|
+
if (hasDoctorBlockingIssues(report, opts)) process.exitCode = 1;
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (report.summary.fail > 0) {
|
|
903
|
+
logger.error(`doctor found ${report.summary.fail} blocking issue(s).`);
|
|
904
|
+
process.exitCode = 1;
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
if (report.summary.warn > 0) {
|
|
908
|
+
if (opts.strict) {
|
|
909
|
+
logger.error(`doctor found ${report.summary.warn} warning(s) in strict mode.`);
|
|
910
|
+
process.exitCode = 1;
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
logger.warn(`doctor found ${report.summary.warn} suggestion(s).`);
|
|
914
|
+
}
|
|
915
|
+
logger.success("doctor finished!");
|
|
916
|
+
});
|
|
917
|
+
program.command("upgrade").description("同步仓库标准资产与脚本").option("-i,--interactive").option("-c,--core", "仅同步核心配置,跳过 GitHub 相关资产").option("--outDir <dir>", "Output directory").option("-s,--skip-overwrite", "skip overwrite").action(async (opts) => {
|
|
918
|
+
const { upgradeMonorepo } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
919
|
+
await upgradeMonorepo(normalizeCliOpts(cwd, opts));
|
|
920
|
+
logger.success("upgrade finished!");
|
|
921
|
+
});
|
|
922
|
+
program.command("sync").description("兼容入口:同步仓库标准资产与脚本").option("-i,--interactive").option("-c,--core", "仅同步核心配置,跳过 GitHub 相关资产").option("--outDir <dir>", "Output directory").option("-s,--skip-overwrite", "skip overwrite").action(async (opts) => {
|
|
923
|
+
const { upgradeMonorepo } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
924
|
+
await upgradeMonorepo(normalizeCliOpts(cwd, opts));
|
|
925
|
+
logger.success("sync finished!");
|
|
926
|
+
});
|
|
927
|
+
program.command("clean").description("兼容入口:清理选中的 workspace 包").option("-y, --yes", "跳过交互直接清理(等价 autoConfirm)").option("--include-private", "包含 private 包").option("--pinned-version <version>", "覆盖写入的 @icebreakers/monorepo 版本").action(async (opts) => {
|
|
928
|
+
const { cleanProjects } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
929
|
+
await cleanProjects(cwd, normalizeCleanOptions(opts));
|
|
930
|
+
logger.success("clean finished!");
|
|
931
|
+
});
|
|
932
|
+
program.command("mirror").description("兼容入口:设置 VS Code binary mirror").action(async () => {
|
|
933
|
+
const { setVscodeBinaryMirror } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
934
|
+
await setVscodeBinaryMirror(cwd);
|
|
935
|
+
logger.success("mirror finished!");
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
//#endregion
|
|
939
|
+
//#region src/cli/commands/verify.ts
|
|
940
|
+
function registerVerifyCommands(program, cwd) {
|
|
941
|
+
const verifyCommand = program.command("verify").alias("v").description("本地校验工具集");
|
|
942
|
+
verifyCommand.command("pre-push").description("按推送变更范围执行 build/test/tsd 校验").alias("push").action(async () => {
|
|
943
|
+
const { verifyPrePush } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
944
|
+
await verifyPrePush({ cwd });
|
|
945
|
+
});
|
|
946
|
+
verifyCommand.command("pre-commit").description("执行 lint-staged 校验").alias("commit").action(async () => {
|
|
947
|
+
const { verifyPreCommit } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
948
|
+
await verifyPreCommit({ cwd });
|
|
949
|
+
});
|
|
950
|
+
verifyCommand.command("commit-msg").description("执行 commitlint 校验").alias("msg").argument("<edit-file>").action(async (editFile) => {
|
|
951
|
+
const { verifyCommitMsg } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
952
|
+
await verifyCommitMsg({
|
|
953
|
+
cwd,
|
|
954
|
+
editFile
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
verifyCommand.command("staged-typecheck").description("按暂存文件所在 workspace 执行 typecheck").alias("tc").argument("[files...]").action(async (files = []) => {
|
|
958
|
+
const { verifyStagedTypecheck } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
959
|
+
verifyStagedTypecheck(files, { cwd });
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
//#endregion
|
|
963
|
+
//#region src/cli/commands/workspace.ts
|
|
964
|
+
function collectValues(value, previous = []) {
|
|
965
|
+
return [...previous, value];
|
|
966
|
+
}
|
|
967
|
+
function formatWorkspaceList(result) {
|
|
968
|
+
const lines = [`workspace: ${result.workspaceDir}`, `packages: ${result.packages.length}`];
|
|
969
|
+
for (const pkg of result.packages) {
|
|
970
|
+
const name = pkg.name ?? "(unnamed)";
|
|
971
|
+
const privateMark = pkg.private ? " private" : "";
|
|
972
|
+
lines.push(`- ${name} ${pkg.relativeDir}${privateMark}`);
|
|
973
|
+
}
|
|
974
|
+
return lines.join("\n");
|
|
975
|
+
}
|
|
976
|
+
function formatMarkdownCell(value) {
|
|
977
|
+
return String(value ?? "-").split("|").join("\\|").split("\n").join("<br>");
|
|
978
|
+
}
|
|
979
|
+
function formatMarkdownTable(rows) {
|
|
980
|
+
return [
|
|
981
|
+
"| Field | Value |",
|
|
982
|
+
"| --- | --- |",
|
|
983
|
+
...rows.map(([label, value]) => `| ${label} | ${formatMarkdownCell(value)} |`)
|
|
984
|
+
].join("\n");
|
|
985
|
+
}
|
|
986
|
+
function formatWorkspaceListMarkdown(result) {
|
|
987
|
+
return [
|
|
988
|
+
"# Repo workspaces",
|
|
989
|
+
"",
|
|
990
|
+
formatMarkdownTable([
|
|
991
|
+
["cwd", result.cwd],
|
|
992
|
+
["workspace", result.workspaceDir],
|
|
993
|
+
["packages", result.packages.length]
|
|
994
|
+
]),
|
|
995
|
+
"",
|
|
996
|
+
"## Packages",
|
|
997
|
+
"",
|
|
998
|
+
"| Name | Path | Private | Description |",
|
|
999
|
+
"| --- | --- | --- | --- |",
|
|
1000
|
+
...result.packages.map((pkg) => {
|
|
1001
|
+
const name = pkg.name ?? "(unnamed)";
|
|
1002
|
+
const description = pkg.description ?? "-";
|
|
1003
|
+
return `| ${formatMarkdownCell(name)} | ${formatMarkdownCell(pkg.relativeDir)} | ${pkg.private ? "yes" : "no"} | ${formatMarkdownCell(description)} |`;
|
|
1004
|
+
})
|
|
1005
|
+
].join("\n");
|
|
1006
|
+
}
|
|
1007
|
+
function replaceAll(value, search, replacement) {
|
|
1008
|
+
return search.length > 0 ? value.split(search).join(replacement) : value;
|
|
1009
|
+
}
|
|
1010
|
+
function redactWorkspaceValue(value, replacements) {
|
|
1011
|
+
if (typeof value === "string") return replacements.reduce((result, [search, replacement]) => replaceAll(result, search, replacement), value);
|
|
1012
|
+
if (Array.isArray(value)) return value.map((item) => redactWorkspaceValue(item, replacements));
|
|
1013
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactWorkspaceValue(item, replacements)]));
|
|
1014
|
+
return value;
|
|
1015
|
+
}
|
|
1016
|
+
function redactWorkspaceList(result) {
|
|
1017
|
+
return redactWorkspaceValue(result, [
|
|
1018
|
+
[result.workspaceDir, "<workspace>"],
|
|
1019
|
+
[result.cwd, "<cwd>"],
|
|
1020
|
+
[os.homedir(), "<home>"]
|
|
1021
|
+
].filter(([search], index, entries) => search.length > 0 && entries.findIndex(([value]) => value === search) === index).sort(([left], [right]) => right.length - left.length));
|
|
1022
|
+
}
|
|
1023
|
+
async function emitWorkspaceList(result, opts) {
|
|
1024
|
+
const outputResult = opts.redact ? redactWorkspaceList(result) : result;
|
|
1025
|
+
const content = opts.json ? JSON.stringify(outputResult, null, 2) : opts.markdown ? formatWorkspaceListMarkdown(outputResult) : formatWorkspaceList(outputResult);
|
|
1026
|
+
if (!opts.out) {
|
|
1027
|
+
logger.log(content);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
const outFile = path.resolve(process.cwd(), opts.out);
|
|
1031
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
1032
|
+
logger.success(`wrote ${path.relative(process.cwd(), outFile)}`);
|
|
1033
|
+
}
|
|
1034
|
+
function registerWorkspaceCommands(program, cwd) {
|
|
1035
|
+
const workspaceCommand = program.command("workspace").alias("ws").description("工作区命令");
|
|
1036
|
+
workspaceCommand.command("upgrade").description("升级/同步 monorepo 相关包").alias("up").option("-i,--interactive").option("-c,--core", "仅同步核心配置,跳过 GitHub 相关资产").option("--outDir <dir>", "Output directory").option("-s,--skip-overwrite", "skip overwrite").action(async (opts) => {
|
|
1037
|
+
const { upgradeMonorepo } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
1038
|
+
await upgradeMonorepo(normalizeCliOpts(cwd, opts));
|
|
1039
|
+
logger.success("workspace upgrade finished!");
|
|
1040
|
+
});
|
|
1041
|
+
workspaceCommand.command("init").description("初始化工作区元信息(README、package.json、changeset、issue template)").alias("i").action(async () => {
|
|
1042
|
+
const { initMetadata } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
1043
|
+
await initMetadata(cwd);
|
|
1044
|
+
logger.success("workspace init finished!");
|
|
1045
|
+
});
|
|
1046
|
+
workspaceCommand.command("list").description("列出 workspace 包").alias("ls").option("--json", "输出 JSON").option("--markdown", "输出 Markdown,方便粘贴到 issue 或 PR").option("--redact", "脱敏 workspace/cwd/home 绝对路径后再输出").option("--include-private", "包含 private 包").option("--include-root", "包含 workspace 根包").option("-p, --pattern <glob>", "追加自定义 workspace glob,可重复", collectValues).option("--out <file>", "把当前列表输出写入文件").action(async (opts) => {
|
|
1047
|
+
const { getWorkspacePackageSummaries } = await import("./workspace-DS6LAL71.mjs").then((n) => n.a);
|
|
1048
|
+
await emitWorkspaceList(await getWorkspacePackageSummaries(cwd, {
|
|
1049
|
+
ignorePrivatePackage: !opts.includePrivate,
|
|
1050
|
+
ignoreRootPackage: !opts.includeRoot,
|
|
1051
|
+
...opts.pattern?.length ? { patterns: opts.pattern } : {}
|
|
1052
|
+
}), opts);
|
|
1053
|
+
});
|
|
1054
|
+
workspaceCommand.command("clean").description("清除选中的包").alias("rm").option("-y, --yes", "跳过交互直接清理(等价 autoConfirm)").option("--include-private", "包含 private 包").option("--pinned-version <version>", "覆盖写入的 @icebreakers/monorepo 版本").action(async (opts) => {
|
|
1055
|
+
const { cleanProjects } = await import("./commands-MPDw9wMy.mjs").then((n) => n.t);
|
|
1056
|
+
await cleanProjects(cwd, normalizeCleanOptions(opts));
|
|
1057
|
+
logger.success("workspace clean finished!");
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
//#endregion
|
|
1061
|
+
//#region src/cli/program.ts
|
|
1062
|
+
const cwd = process.cwd();
|
|
1063
|
+
const program = new Command();
|
|
1064
|
+
program.name(cliName).version(version).description("One-command repo setup and maintenance for pnpm/turbo workspaces.");
|
|
1065
|
+
registerTopLevelCommands(program, cwd);
|
|
1066
|
+
registerTemplatesCommands(program);
|
|
1067
|
+
registerWorkspaceCommands(program, cwd);
|
|
1068
|
+
registerToolingCommands(program, cwd);
|
|
1069
|
+
registerEnvCommands(program, cwd);
|
|
1070
|
+
registerConfigCommands(program, cwd);
|
|
1071
|
+
registerSkillsCommands(program, cwd);
|
|
1072
|
+
registerVerifyCommands(program, cwd);
|
|
1073
|
+
registerAiCommands(program, cwd);
|
|
1074
|
+
registerPackageCommands(program, cwd);
|
|
1075
|
+
program.addHelpText("after", `
|
|
1076
|
+
Quick start:
|
|
1077
|
+
Existing repo:
|
|
1078
|
+
$ ${cliName} setup
|
|
1079
|
+
$ ${cliName} doctor
|
|
1080
|
+
$ ${cliName} templates
|
|
1081
|
+
$ ${cliName} new my-package
|
|
1082
|
+
$ ${cliName} check
|
|
1083
|
+
|
|
1084
|
+
Faster in generated repos:
|
|
1085
|
+
$ pnpm setup
|
|
1086
|
+
$ pnpm doctor
|
|
1087
|
+
$ pnpm new my-package
|
|
1088
|
+
$ pnpm check
|
|
1089
|
+
|
|
1090
|
+
Keep the repo current:
|
|
1091
|
+
$ ${cliName} upgrade
|
|
1092
|
+
|
|
1093
|
+
Zero-install cleanup:
|
|
1094
|
+
$ pnpm dlx repo@latest clean --yes
|
|
1095
|
+
|
|
1096
|
+
Compatibility shortcuts:
|
|
1097
|
+
$ repoctl setup
|
|
1098
|
+
$ repoctl doctor
|
|
1099
|
+
$ repoctl new
|
|
1100
|
+
$ repoctl check
|
|
1101
|
+
`);
|
|
112
1102
|
//#endregion
|
|
113
1103
|
//#region src/cli.ts
|
|
114
|
-
program.
|
|
1104
|
+
if (process.argv.length <= 2) program.outputHelp();
|
|
1105
|
+
else program.parse();
|
|
115
1106
|
//#endregion
|
|
116
1107
|
export {};
|