@icebreakers/monorepo 5.1.1 → 5.3.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.
@@ -1,14 +1,14 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { i as getWorkspacePackages, n as getWorkspaceData, r as getWorkspacePackageSummaries } from "./workspace-MCKewElu.mjs";
3
- import { _ as isIgnorableFsError, c as devDependencies$1, d as logger, g as fs$1, i as packageDir, n as assetsDir, o as templatesDir, s as dependencies, t as initToolingTargets, u as version$1 } from "./types-CLzhRYdV.mjs";
3
+ import { b as fs$1, c as devDependencies$1, d as localize, h as logger, i as packageDir, n as assetsDir, o as templatesDir, p as resolveRepoctlLocale, s as dependencies, t as initToolingTargets, u as version$1, x as isIgnorableFsError } from "./types-CGwtAKfx.mjs";
4
4
  import { a as loadMonorepoConfig, c as resolveToolingConfig, i as getRepoctlConfigCandidates, o as loadMonorepoConfigDetails, s as resolveCommandConfig } from "./config-p842Knhq.mjs";
5
- import { f as defineTsconfigConfig } from "./tooling-Bn3XOfO0.mjs";
5
+ import { f as defineTsconfigConfig } from "./tooling-CdZRpvYw.mjs";
6
6
  import gitUrlParse from "git-url-parse";
7
7
  import { simpleGit } from "simple-git";
8
8
  import { findWorkspaceDir } from "@pnpm/find-workspace-dir";
9
9
  import path from "pathe";
10
10
  import process from "node:process";
11
- import { access, readFile, readdir, realpath } from "node:fs/promises";
11
+ import { access, readFile, readdir, realpath, rm } from "node:fs/promises";
12
12
  import { execFileSync, spawnSync } from "node:child_process";
13
13
  import fs from "node:fs";
14
14
  import path$1 from "node:path";
@@ -91,21 +91,21 @@ var GitClient = class {
91
91
  //#endregion
92
92
  //#region src/commands/ai.ts
93
93
  const agenticSections = [
94
- "目标/产物",
95
- "约束(性能/风格/兼容/不可改动范围)",
96
- "验收标准(要跑的命令、预期输出/文件)",
97
- "仓库路径",
98
- "允许操作(可/不可写文件,可运行的命令清单,可否联网)",
99
- "上下文线索(日志/文件/模块/相关 issue)",
100
- "里程碑(根因→设计→实现→验证)"
94
+ ["Goal and deliverables", "目标与产物"],
95
+ ["Constraints (performance, style, compatibility, and protected scope)", "约束(性能、风格、兼容性和不可改动范围)"],
96
+ ["Acceptance criteria (commands, expected output, and files)", "验收标准(命令、预期输出和文件)"],
97
+ ["Repository paths", "仓库路径"],
98
+ ["Allowed operations (file writes, commands, and network access)", "允许操作(文件写入、可运行命令和网络访问)"],
99
+ ["Context (logs, files, modules, and related issues)", "上下文(日志、文件、模块和相关 issue)"],
100
+ ["Milestones (root cause, design, implementation, and verification)", "里程碑(根因、设计、实现和验证)"]
101
101
  ];
102
102
  const defaultAgenticBaseDir = "agentic/prompts";
103
103
  function renderMarkdownTemplate() {
104
- return `${agenticSections.map((title) => `## ${title}\n- `).join("\n\n")}\n`;
104
+ return `${agenticSections.map(([english, chinese]) => `## ${localize(english, chinese)}\n- `).join("\n\n")}\n`;
105
105
  }
106
106
  function renderJsonTemplate() {
107
107
  const payload = {};
108
- for (const title of agenticSections) payload[title] = "";
108
+ for (const [english] of agenticSections) payload[english] = "";
109
109
  return `${JSON.stringify(payload, null, 2)}\n`;
110
110
  }
111
111
  function createTimestampFolderName(date = /* @__PURE__ */ new Date()) {
@@ -119,7 +119,7 @@ async function generateAgenticTemplate(options = {}) {
119
119
  const cwd = options.cwd ?? process.cwd();
120
120
  const format = options.format ?? "md";
121
121
  const baseDir = options.baseDir ?? "agentic/prompts";
122
- if (format !== "md" && format !== "json") throw new Error(`不支持的模板格式:${format}`);
122
+ if (format !== "md" && format !== "json") throw new Error(localize(`Unsupported template format: ${format}`, `不支持的模板格式:${format}`));
123
123
  const template = format === "md" ? renderMarkdownTemplate() : renderJsonTemplate();
124
124
  const ext = format === "json" ? "json" : "md";
125
125
  let outputPath = options.output;
@@ -132,16 +132,16 @@ async function generateAgenticTemplate(options = {}) {
132
132
  const targetDir = path.dirname(targetPath);
133
133
  await fs$1.ensureDir(targetDir);
134
134
  const exists = await fs$1.pathExists(targetPath);
135
- if (exists && !options.force) throw new Error(`目标文件已存在:${path.relative(cwd, targetPath)}`);
135
+ if (exists && !options.force) throw new Error(localize(`Target file already exists: ${path.relative(cwd, targetPath)}`, `目标文件已存在:${path.relative(cwd, targetPath)}`));
136
136
  await fs$1.outputFile(targetPath, template, "utf8");
137
- const actionLabel = exists ? "已覆盖模板" : "已生成模板";
138
- logger.success(`${actionLabel}:${path.relative(cwd, targetPath)}`);
137
+ const actionLabel = exists ? localize("Overwrote template", "已覆盖模板") : localize("Generated template", "已生成模板");
138
+ logger.success(`${actionLabel}: ${path.relative(cwd, targetPath)}`);
139
139
  return template;
140
140
  }
141
141
  async function loadAgenticTasks(filePath, cwd) {
142
142
  const fullPath = path.resolve(cwd, filePath);
143
143
  const tasks = await fs$1.readJson(fullPath);
144
- if (!Array.isArray(tasks)) throw new TypeError("任务清单需要是数组");
144
+ if (!Array.isArray(tasks)) throw new TypeError(localize("The task list must be an array.", "任务清单需要是数组"));
145
145
  return tasks;
146
146
  }
147
147
  async function generateAgenticTemplates(tasks, defaults = {}) {
@@ -383,11 +383,12 @@ async function verifyPrePush(options = {}) {
383
383
  function verifyStagedTypecheck(stagedFiles, options = {}) {
384
384
  const cwd = options.cwd ?? process.cwd();
385
385
  const spawn = options.spawn ?? spawnSync;
386
- const workspaceDirs = [...new Set(stagedFiles.filter((file) => {
386
+ let workspaceDirs = [...new Set(stagedFiles.filter((file) => {
387
387
  const basename = path$1.basename(file);
388
388
  return typecheckExtensions.has(path$1.extname(file)) || typecheckBasenames.has(basename);
389
389
  }).map((file) => resolveTypecheckWorkspaceDir(file, cwd)))];
390
390
  if (workspaceDirs.length === 0) return;
391
+ if (workspaceDirs.includes(cwd)) workspaceDirs = [cwd];
391
392
  for (const workspaceDir of workspaceDirs) runPnpmCommand(cwd, `[lint-staged:typecheck] ${path$1.relative(cwd, workspaceDir) || "."}`, [
392
393
  "--dir",
393
394
  workspaceDir,
@@ -445,7 +446,7 @@ function resolveRecommendedCheckPlan(options) {
445
446
  commands: [{
446
447
  name: "commit-msg",
447
448
  command: `repo verify commit-msg ${editFile}`,
448
- description: "校验 commit message 文件是否符合提交规范。"
449
+ description: localize("Validate a commit message file.", "校验 commit message 文件是否符合提交规范。")
449
450
  }]
450
451
  };
451
452
  if (full) return {
@@ -454,7 +455,7 @@ function resolveRecommendedCheckPlan(options) {
454
455
  commands: [{
455
456
  name: "pre-push",
456
457
  command: "repo verify pre-push",
457
- description: "执行完整 pre-push 校验,包含整仓 lint/typecheck,并按变更范围运行 build/test/tsd。"
458
+ description: localize("Run full pre-push verification with lint, typecheck, build, test, and tsd.", "执行完整 pre-push 校验,包含整仓 lint/typecheck,并按变更范围运行 build/test/tsd。")
458
459
  }]
459
460
  };
460
461
  if (staged) return {
@@ -463,11 +464,11 @@ function resolveRecommendedCheckPlan(options) {
463
464
  commands: [{
464
465
  name: "pre-commit",
465
466
  command: "repo verify pre-commit",
466
- description: "执行 pre-commit 校验。"
467
+ description: localize("Run pre-commit verification.", "执行 pre-commit 校验。")
467
468
  }, {
468
469
  name: "staged-typecheck",
469
470
  command: "repo verify staged-typecheck <staged files>",
470
- description: "按暂存 TypeScript/Vue 文件所在 workspace 路由 typecheck。"
471
+ description: localize("Route typecheck to workspaces containing staged TypeScript or Vue files.", "按暂存 TypeScript/Vue 文件所在 workspace 路由 typecheck。")
471
472
  }]
472
473
  };
473
474
  return {
@@ -476,7 +477,7 @@ function resolveRecommendedCheckPlan(options) {
476
477
  commands: [{
477
478
  name: "pre-commit",
478
479
  command: "repo verify pre-commit",
479
- description: "执行默认轻量本地校验。"
480
+ description: localize("Run the default lightweight local verification.", "执行默认轻量本地校验。")
480
481
  }]
481
482
  };
482
483
  }
@@ -509,7 +510,7 @@ async function resolveFullWorkspaceCheckPlan(cwd) {
509
510
  ].filter((name) => hasRootScript({ scripts }, name)).map((name) => ({
510
511
  name,
511
512
  command: `pnpm ${name}`,
512
- description: `运行根 package.json 的 ${name} 脚本。`,
513
+ description: localize(`Run the ${name} script from the root package.json.`, `运行根 package.json 的 ${name} 脚本。`),
513
514
  available: true
514
515
  }))
515
516
  };
@@ -715,11 +716,11 @@ async function syncSkills(options = {}) {
715
716
  const cwd = options.cwd ?? process.cwd();
716
717
  if (!await fs$1.pathExists(skillSourceDir)) {
717
718
  const relative = path.relative(cwd, skillSourceDir);
718
- throw new Error(`未找到技能目录:${relative || skillSourceDir}`);
719
+ throw new Error(localize(`Skill directory not found: ${relative || skillSourceDir}`, `未找到技能目录:${relative || skillSourceDir}`));
719
720
  }
720
721
  let targets = normalizeTargets(options.targets);
721
722
  if (!targets?.length) targets = normalizeTargets(await checkbox({
722
- message: "请选择需要同步的技能目标",
723
+ message: localize("Select skill synchronization targets", "请选择需要同步的技能目标"),
723
724
  choices: skillTargets.map((target) => ({
724
725
  name: target,
725
726
  value: target,
@@ -767,7 +768,7 @@ async function cleanProjects(cwd, overrides) {
767
768
  let cleanDirs = [];
768
769
  if (cleanConfig?.autoConfirm) cleanDirs = filteredPackages.map((pkg) => pkg.rootDir);
769
770
  else cleanDirs = await checkbox({
770
- message: "请选择需要清理的目录",
771
+ message: localize("Select directories to remove", "请选择需要清理的目录"),
771
772
  choices: filteredPackages.map((x) => {
772
773
  const baseChoice = {
773
774
  name: path.relative(workspaceDir, x.rootDir),
@@ -1061,7 +1062,7 @@ async function resolveCreateNewProjectPlan(options) {
1061
1062
  if (!templateDefinitions[requestedTemplateName]) throw new Error(formatUnknownTemplateError(requestedTemplateName, availableTemplates));
1062
1063
  const template = requestedTemplateName;
1063
1064
  const templateDefinition = templateDefinitions[template];
1064
- if (!templateDefinition) throw new Error(`未找到名为 ${template} 的模板,请检查 repoctl.config.ts`);
1065
+ if (!templateDefinition) throw new Error(localize(`Template ${template} was not found; check repoctl.config.ts.`, `未找到名为 ${template} 的模板,请检查 repoctl.config.ts`));
1065
1066
  const sourceDir = path.join(templatesRoot, templateDefinition.source);
1066
1067
  const targetName = name && name.length > 0 ? name : templateDefinition.target;
1067
1068
  const targetDir = path.join(cwd, targetName);
@@ -1186,7 +1187,7 @@ async function updateWorkspaceManifest(workspaceDir, targetName) {
1186
1187
  */
1187
1188
  async function createNewProject(options) {
1188
1189
  const plan = await resolveCreateNewProjectPlan(options);
1189
- if (plan.targetExists) throw new Error(`${pc.red("目标目录已存在")}: ${path.relative(plan.cwd, plan.targetDir)}`);
1190
+ if (plan.targetExists) throw new Error(`${pc.red(localize("Target directory already exists", "目标目录已存在"))}: ${path.relative(plan.cwd, plan.targetDir)}`);
1190
1191
  await fs$1.ensureDir(plan.targetDir);
1191
1192
  await scaffoldTemplate({
1192
1193
  sourceDir: plan.sourceDir,
@@ -1203,7 +1204,89 @@ async function createNewProject(options) {
1203
1204
  await fs$1.outputJson(path.resolve(plan.targetDir, plan.packageJsonFileName), sourceJson, { spaces: 2 });
1204
1205
  }
1205
1206
  await updateWorkspaceManifest(plan.cwd, plan.targetName);
1206
- logger.success(`${pc.bgGreenBright(pc.white(`[${plan.template}]`))} ${plan.targetName} 项目创建成功!`);
1207
+ logger.success(localize(`${pc.bgGreenBright(pc.white(`[${plan.template}]`))} Created ${plan.targetName}.`, `${pc.bgGreenBright(pc.white(`[${plan.template}]`))} ${plan.targetName} 项目创建成功!`));
1208
+ }
1209
+ //#endregion
1210
+ //#region src/commands/doctor/helpers.ts
1211
+ function createCheck(check) {
1212
+ return check;
1213
+ }
1214
+ function summarizeChecks(checks) {
1215
+ return checks.reduce((summary, check) => {
1216
+ summary[check.status] += 1;
1217
+ return summary;
1218
+ }, {
1219
+ pass: 0,
1220
+ warn: 0,
1221
+ fail: 0
1222
+ });
1223
+ }
1224
+ function getWorkspacePatterns(manifest) {
1225
+ if (typeof manifest !== "object" || manifest === null) return [];
1226
+ const packages = manifest.packages;
1227
+ return Array.isArray(packages) ? packages.filter((item) => typeof item === "string") : [];
1228
+ }
1229
+ function isWorkspacePatternCovered(relativeDir, patterns) {
1230
+ const normalized = relativeDir.split("\\").join("/");
1231
+ return patterns.some((pattern) => {
1232
+ if (pattern.startsWith("!")) return false;
1233
+ if (pattern.endsWith("/*")) {
1234
+ const base = pattern.slice(0, -2);
1235
+ return normalized.startsWith(`${base}/`) && normalized.slice(base.length + 1).split("/").length === 1;
1236
+ }
1237
+ if (pattern.endsWith("/**")) return normalized.startsWith(`${pattern.slice(0, -3)}/`);
1238
+ return normalized === pattern;
1239
+ });
1240
+ }
1241
+ //#endregion
1242
+ //#region src/commands/doctor/context.ts
1243
+ async function isRepoctlSourceWorkspace(workspaceDir) {
1244
+ const [hasMonorepoSource, hasRepoctlSource] = await Promise.all([fs$1.pathExists(`${workspaceDir}/packages/monorepo/src/tooling/index.ts`), fs$1.pathExists(`${workspaceDir}/packages/repoctl/src/tooling-entry.ts`)]);
1245
+ return hasMonorepoSource && hasRepoctlSource;
1246
+ }
1247
+ async function findWorkspacePackageDirs(workspaceDir) {
1248
+ const result = [];
1249
+ for (const baseDir of [
1250
+ "apps",
1251
+ "packages",
1252
+ "examples"
1253
+ ]) {
1254
+ const absBaseDir = `${workspaceDir}/${baseDir}`;
1255
+ if (!await fs$1.pathExists(absBaseDir)) continue;
1256
+ const entries = await readdir(absBaseDir);
1257
+ await Promise.all(entries.map(async (entry) => {
1258
+ if (await fs$1.pathExists(`${absBaseDir}/${entry}/package.json`)) result.push(`${baseDir}/${entry}`);
1259
+ }));
1260
+ }
1261
+ return result.sort((left, right) => left.localeCompare(right));
1262
+ }
1263
+ async function collectDoctorContext(cwd) {
1264
+ const workspaceDir = await findWorkspaceDir(cwd) ?? cwd;
1265
+ const packageJsonPath = `${workspaceDir}/package.json`;
1266
+ const workspaceManifestPath = `${workspaceDir}/pnpm-workspace.yaml`;
1267
+ const [hasPackageJson, hasWorkspaceManifest, hasRepoctlConfig, hasLegacyMonorepoConfig, hasHuskyPreCommit, hasLintStagedConfig] = await Promise.all([
1268
+ fs$1.pathExists(packageJsonPath),
1269
+ fs$1.pathExists(workspaceManifestPath),
1270
+ fs$1.pathExists(`${workspaceDir}/repoctl.config.ts`),
1271
+ fs$1.pathExists(`${workspaceDir}/monorepo.config.ts`),
1272
+ fs$1.pathExists(`${workspaceDir}/.husky/pre-commit`),
1273
+ fs$1.pathExists(`${workspaceDir}/lint-staged.config.js`)
1274
+ ]);
1275
+ return {
1276
+ cwd,
1277
+ workspaceDir,
1278
+ packageJson: hasPackageJson ? await fs$1.readJson(packageJsonPath) : {},
1279
+ packageCount: hasWorkspaceManifest ? (await getWorkspacePackages(workspaceDir, { ignorePrivatePackage: false })).length : 0,
1280
+ workspacePatterns: hasWorkspaceManifest ? getWorkspacePatterns(YAML.parse(await fs$1.readFile(workspaceManifestPath, "utf8"))) : [],
1281
+ workspacePackageDirs: hasWorkspaceManifest ? await findWorkspacePackageDirs(workspaceDir) : [],
1282
+ hasPackageJson,
1283
+ hasWorkspaceManifest,
1284
+ hasRepoctlConfig,
1285
+ hasLegacyMonorepoConfig,
1286
+ hasHuskyPreCommit,
1287
+ hasLintStagedConfig,
1288
+ isSourceWorkspace: await isRepoctlSourceWorkspace(workspaceDir)
1289
+ };
1207
1290
  }
1208
1291
  //#endregion
1209
1292
  //#region src/commands/upgrade/release-migration.ts
@@ -1253,6 +1336,9 @@ async function migrateLegacyVersioning(workspaceDir) {
1253
1336
  //#endregion
1254
1337
  //#region src/commands/doctor/release.ts
1255
1338
  const releaseCiMinimumVersion = "5.1.0";
1339
+ function hasValidFixedGroups(fixed) {
1340
+ return fixed === void 0 || Array.isArray(fixed) && fixed.every((group) => Array.isArray(group) && group.length > 0 && group.every((name) => typeof name === "string" && name.trim().length > 0));
1341
+ }
1256
1342
  function check(id, title, status, detail, fix) {
1257
1343
  return {
1258
1344
  id,
@@ -1262,6 +1348,15 @@ function check(id, title, status, detail, fix) {
1262
1348
  ...fix ? { fix } : {}
1263
1349
  };
1264
1350
  }
1351
+ function minimumDependencyVersion(range) {
1352
+ const normalized = range?.startsWith("workspace:") ? range.slice(10) : range;
1353
+ if (!normalized || normalized === "*" || normalized === "^" || normalized === "~") return null;
1354
+ try {
1355
+ return minVersion(normalized);
1356
+ } catch {
1357
+ return null;
1358
+ }
1359
+ }
1265
1360
  async function collectReleaseChecks(workspaceDir, pkgJson) {
1266
1361
  const workflowPath = path.join(workspaceDir, ".github/workflows/release.yml");
1267
1362
  const [hasWorkflow, hasPreState, hasChangesetConfig] = await Promise.all([
@@ -1272,318 +1367,239 @@ async function collectReleaseChecks(workspaceDir, pkgJson) {
1272
1367
  if (!hasWorkflow && !hasPreState && !hasChangesetConfig) return [];
1273
1368
  const checks = [];
1274
1369
  const workflowStatus = await classifyReleaseWorkflow(workspaceDir);
1275
- if (workflowStatus === "managed") checks.push(check("release-workflow", "release workflow", "pass", `release workflow 已由 ${releaseWorkflowMarker} 管理。`));
1276
- else if (workflowStatus === "legacy") checks.push(check("release-workflow", "release workflow", "warn", "检测到旧的 Changesets release workflow。", "首次迁移运行 pnpm dlx repoctl@latest upgrade --yes。"));
1277
- else if (workflowStatus === "custom") checks.push(check("release-workflow", "release workflow", "warn", "release workflow 未包含 repoctl managed marker,可能存在自定义发布逻辑。", "确认内容后运行 repo upgrade --overwrite-release,或手动加入 repoctl-managed: release/v2。"));
1278
- if (hasPreState) checks.push(check("release-prerelease-state", "prerelease state", "warn", "检测到旧的 .changeset/pre.json。", "运行 pnpm dlx repoctl@latest upgrade --yes 将其迁移为 pnpm versioning.lanes。"));
1279
- if (hasChangesetConfig) checks.push(check("release-changeset-config", "changeset config", "warn", "检测到只属于 Changesets CLI 的 .changeset/config.json。", "运行 pnpm dlx repoctl@latest upgrade --yes 清理旧配置。"));
1370
+ if (workflowStatus === "managed") checks.push(check("release-workflow", "release workflow", "pass", localize(`The release workflow is managed by ${releaseWorkflowMarker}.`, `release workflow 已由 ${releaseWorkflowMarker} 管理。`)));
1371
+ else if (workflowStatus === "legacy") checks.push(check("release-workflow", "release workflow", "warn", localize("Found a legacy Changesets release workflow.", "检测到旧的 Changesets release workflow。"), localize("Run pnpm dlx repoctl@latest upgrade --yes for the initial migration.", "首次迁移运行 pnpm dlx repoctl@latest upgrade --yes。")));
1372
+ else if (workflowStatus === "custom") checks.push(check("release-workflow", "release workflow", "warn", localize("The release workflow has no repoctl managed marker and may contain custom logic.", "release workflow 未包含 repoctl managed marker,可能存在自定义发布逻辑。"), localize("Review it, then run repo upgrade --overwrite-release or add the managed marker manually.", "确认内容后运行 repo upgrade --overwrite-release,或手动加入 repoctl-managed: release/v2。")));
1373
+ if (hasPreState) checks.push(check("release-prerelease-state", "prerelease state", "warn", localize("Found legacy .changeset/pre.json prerelease state.", "检测到旧的 .changeset/pre.json。"), localize("Run pnpm dlx repoctl@latest upgrade --yes to migrate to pnpm versioning lanes.", "运行 pnpm dlx repoctl@latest upgrade --yes 将其迁移为 pnpm versioning.lanes。")));
1374
+ if (hasChangesetConfig) checks.push(check("release-changeset-config", "changeset config", "warn", localize("Found .changeset/config.json from the Changesets CLI.", "检测到只属于 Changesets CLI 的 .changeset/config.json。"), localize("Run pnpm dlx repoctl@latest upgrade --yes to remove legacy configuration.", "运行 pnpm dlx repoctl@latest upgrade --yes 清理旧配置。")));
1280
1375
  if (hasWorkflow) {
1281
1376
  const packageVersion = pkgJson.devDependencies?.["repoctl"] ?? pkgJson.dependencies?.["repoctl"];
1282
- const parsed = minVersion(packageVersion ?? "");
1283
- if (!parsed || !gte(parsed, "5.1.0")) checks.push(check("release-cli-version", "release CLI version", "warn", `repoctl 版本 ${packageVersion ?? "missing"} 不保证支持 release ci。`, `运行 pnpm dlx repoctl@latest upgrade --yes,或将 repoctl 升级到 >=${releaseCiMinimumVersion}。`));
1284
- else checks.push(check("release-cli-version", "release CLI version", "pass", `repoctl 版本 ${packageVersion} 支持 release ci。`));
1377
+ const parsed = minimumDependencyVersion(packageVersion);
1378
+ if (!parsed || !gte(parsed, "5.1.0")) checks.push(check("release-cli-version", "release CLI version", "warn", localize(`repoctl ${packageVersion ?? "missing"} does not guarantee release ci support.`, `repoctl 版本 ${packageVersion ?? "missing"} 不保证支持 release ci。`), localize(`Upgrade repoctl to >=${releaseCiMinimumVersion}.`, `运行 pnpm dlx repoctl@latest upgrade --yes,或将 repoctl 升级到 >=${releaseCiMinimumVersion}。`)));
1379
+ else checks.push(check("release-cli-version", "release CLI version", "pass", localize(`repoctl ${packageVersion} supports release ci.`, `repoctl 版本 ${packageVersion} 支持 release ci。`)));
1285
1380
  try {
1286
1381
  const workspace = YAML.parse(await readFile(path.join(workspaceDir, "pnpm-workspace.yaml"), "utf8"));
1287
- const hasFixed = Array.isArray(workspace.versioning?.fixed) && workspace.versioning.fixed.length > 0;
1382
+ const hasValidFixed = hasValidFixedGroups(workspace.versioning?.fixed);
1288
1383
  const hasRepositoryChangelog = workspace.versioning?.changelog?.storage === "repository";
1289
- checks.push(hasFixed && hasRepositoryChangelog ? check("release-versioning-config", "release versioning config", "pass", "pnpm fixed group 与 repository changelog 配置完整。") : check("release-versioning-config", "release versioning config", "warn", "pnpm-workspace.yaml 缺少 release 所需的 fixed 或 repository changelog 配置。", "运行 repo upgrade --yes 同步 pnpm versioning 配置。"));
1384
+ checks.push(hasValidFixed && hasRepositoryChangelog ? check("release-versioning-config", "release versioning config", "pass", localize("pnpm fixed groups are valid and repository changelog storage is configured.", "pnpm fixed group 配置合法,且已配置 repository changelog。")) : check("release-versioning-config", "release versioning config", "warn", localize("pnpm-workspace.yaml has invalid fixed groups or is missing repository changelog storage.", "pnpm-workspace.yaml 的 fixed group 配置不合法,或缺少 repository changelog 配置。"), localize("Run repo upgrade --yes to synchronize pnpm versioning configuration.", "运行 repo upgrade --yes 同步 pnpm versioning 配置。")));
1290
1385
  } catch {
1291
- checks.push(check("release-versioning-config", "release versioning config", "warn", "无法读取 pnpm-workspace.yaml 的 versioning 配置。", "运行 repo upgrade --yes 同步 pnpm versioning 配置。"));
1386
+ checks.push(check("release-versioning-config", "release versioning config", "warn", localize("Unable to read versioning configuration from pnpm-workspace.yaml.", "无法读取 pnpm-workspace.yaml 的 versioning 配置。"), localize("Run repo upgrade --yes to synchronize pnpm versioning configuration.", "运行 repo upgrade --yes 同步 pnpm versioning 配置。")));
1292
1387
  }
1293
1388
  }
1294
1389
  return checks;
1295
1390
  }
1296
1391
  //#endregion
1297
- //#region src/commands/doctor.ts
1392
+ //#region src/commands/doctor/tooling.ts
1298
1393
  const recommendedRepoScripts = {
1299
1394
  "repo:init": "repo init",
1300
1395
  "repo:new": "repo new",
1301
1396
  "repo:check": "repo check",
1302
1397
  "repo:doctor": "repo doctor"
1303
1398
  };
1304
- function createCheck(check) {
1305
- return check;
1306
- }
1307
- function summarizeChecks(checks) {
1308
- return checks.reduce((summary, check) => {
1309
- summary[check.status] += 1;
1310
- return summary;
1311
- }, {
1312
- pass: 0,
1313
- warn: 0,
1314
- fail: 0
1315
- });
1316
- }
1317
- function resolveToolPackageName(pkgJson) {
1318
- return [typeof pkgJson.devDependencies?.["repoctl"] === "string" ? {
1319
- name: "repoctl",
1320
- version: pkgJson.devDependencies["repoctl"]
1321
- } : null, typeof pkgJson.dependencies?.["repoctl"] === "string" ? {
1399
+ function resolveToolPackage(pkgJson) {
1400
+ const version = pkgJson.devDependencies?.["repoctl"] ?? pkgJson.dependencies?.["repoctl"];
1401
+ return typeof version === "string" ? {
1322
1402
  name: "repoctl",
1323
- version: pkgJson.dependencies["repoctl"]
1324
- } : null].find((value) => value !== null) ?? null;
1403
+ version
1404
+ } : null;
1325
1405
  }
1326
1406
  function hasScript(pkgJson, name) {
1327
1407
  return typeof pkgJson.scripts?.[name] === "string" && pkgJson.scripts[name].length > 0;
1328
1408
  }
1329
- function getMissingScripts(pkgJson, expected) {
1330
- return Object.keys(expected).filter((scriptName) => !hasScript(pkgJson, scriptName));
1331
- }
1332
- function getUnexpectedScripts(pkgJson, expected) {
1333
- return Object.entries(expected).filter(([scriptName, expectedCommand]) => hasScript(pkgJson, scriptName) && pkgJson.scripts?.[scriptName] !== expectedCommand).map(([scriptName]) => scriptName);
1334
- }
1335
- function getWorkspacePatterns(manifest) {
1336
- if (typeof manifest !== "object" || manifest === null) return [];
1337
- const packages = manifest.packages;
1338
- return Array.isArray(packages) ? packages.filter((item) => typeof item === "string") : [];
1339
- }
1340
- function isWorkspacePatternCovered(relativeDir, patterns) {
1341
- const normalized = relativeDir.split("\\").join("/");
1342
- return patterns.some((pattern) => {
1343
- if (pattern.startsWith("!")) return false;
1344
- if (pattern.endsWith("/*")) {
1345
- const base = pattern.slice(0, -2);
1346
- return normalized.startsWith(`${base}/`) && normalized.slice(base.length + 1).split("/").length === 1;
1347
- }
1348
- if (pattern.endsWith("/**")) return normalized.startsWith(`${pattern.slice(0, -3)}/`);
1349
- return normalized === pattern;
1350
- });
1351
- }
1352
- async function isRepoctlSourceWorkspace(workspaceDir) {
1353
- const [hasMonorepoSource, hasRepoctlSource] = await Promise.all([fs$1.pathExists(`${workspaceDir}/packages/monorepo/src/tooling/index.ts`), fs$1.pathExists(`${workspaceDir}/packages/repoctl/src/tooling-entry.ts`)]);
1354
- return hasMonorepoSource && hasRepoctlSource;
1355
- }
1356
- async function findWorkspacePackageDirs(workspaceDir) {
1357
- const result = [];
1409
+ async function findLegacyToolingFiles(context) {
1410
+ const files = [...context.isSourceWorkspace ? [] : [
1411
+ "eslint.config.js",
1412
+ "stylelint.config.js",
1413
+ "lint-staged.config.js",
1414
+ "vitest.config.ts"
1415
+ ]];
1358
1416
  for (const baseDir of [
1359
1417
  "apps",
1360
1418
  "packages",
1361
1419
  "examples"
1362
1420
  ]) {
1363
- const absBaseDir = `${workspaceDir}/${baseDir}`;
1364
- if (!await fs$1.pathExists(absBaseDir)) continue;
1365
- const entries = await readdir(absBaseDir);
1366
- await Promise.all(entries.map(async (entry) => {
1367
- const packageJsonPath = `${absBaseDir}/${entry}/package.json`;
1368
- if (await fs$1.pathExists(packageJsonPath)) result.push(`${baseDir}/${entry}`);
1369
- }));
1421
+ const absoluteBase = `${context.workspaceDir}/${baseDir}`;
1422
+ if (!await fs$1.pathExists(absoluteBase)) continue;
1423
+ for (const entry of await readdir(absoluteBase)) files.push(`${baseDir}/${entry}/eslint.config.js`, `${baseDir}/${entry}/vitest.config.ts`);
1370
1424
  }
1371
- return result.sort((left, right) => left.localeCompare(right));
1425
+ const legacyFiles = [];
1426
+ await Promise.all(files.map(async (file) => {
1427
+ const candidate = `${context.workspaceDir}/${file}`;
1428
+ if (await fs$1.pathExists(candidate) && hasLegacyToolingReference(await fs$1.readFile(candidate, "utf8"))) legacyFiles.push(file);
1429
+ }));
1430
+ return legacyFiles.sort((left, right) => left.localeCompare(right));
1372
1431
  }
1373
- async function runDoctor(cwd) {
1374
- const workspaceDir = await findWorkspaceDir(cwd) ?? cwd;
1375
- const packageJsonPath = `${workspaceDir}/package.json`;
1376
- const workspaceManifestPath = `${workspaceDir}/pnpm-workspace.yaml`;
1377
- const repoctlConfigPath = `${workspaceDir}/repoctl.config.ts`;
1378
- const legacyMonorepoConfigPath = `${workspaceDir}/monorepo.config.ts`;
1379
- const huskyPreCommitPath = `${workspaceDir}/.husky/pre-commit`;
1380
- const lintStagedConfigPath = `${workspaceDir}/lint-staged.config.js`;
1381
- const [hasPackageJson, hasWorkspaceManifest, hasRepoctlConfig, hasLegacyMonorepoConfig, hasHuskyPreCommit, hasLintStagedConfig] = await Promise.all([
1382
- fs$1.pathExists(packageJsonPath),
1383
- fs$1.pathExists(workspaceManifestPath),
1384
- fs$1.pathExists(repoctlConfigPath),
1385
- fs$1.pathExists(legacyMonorepoConfigPath),
1386
- fs$1.pathExists(huskyPreCommitPath),
1387
- fs$1.pathExists(lintStagedConfigPath)
1388
- ]);
1389
- const pkgJson = hasPackageJson ? await fs$1.readJson(packageJsonPath) : {};
1390
- const packageCount = hasWorkspaceManifest ? (await getWorkspacePackages(workspaceDir, { ignorePrivatePackage: false })).length : 0;
1391
- const workspacePatterns = hasWorkspaceManifest ? getWorkspacePatterns(YAML.parse(await fs$1.readFile(workspaceManifestPath, "utf8"))) : [];
1392
- const workspacePackageDirs = hasWorkspaceManifest ? await findWorkspacePackageDirs(workspaceDir) : [];
1393
- const isSourceWorkspace = await isRepoctlSourceWorkspace(workspaceDir);
1432
+ async function collectToolingChecks(context) {
1433
+ const checks = [];
1434
+ const toolPackage = resolveToolPackage(context.packageJson);
1435
+ checks.push(toolPackage ? createCheck({
1436
+ id: "tool-package",
1437
+ title: localize("repo CLI dependency", "repo CLI 依赖"),
1438
+ status: "pass",
1439
+ detail: localize(`Detected CLI dependency: ${toolPackage.name}@${toolPackage.version}`, `已检测到 CLI 依赖:${toolPackage.name}@${toolPackage.version}`)
1440
+ }) : createCheck({
1441
+ id: "tool-package",
1442
+ title: localize("repo CLI dependency", "repo CLI 依赖"),
1443
+ status: "fail",
1444
+ detail: localize("The root package.json does not contain a repoctl dependency.", "根 package.json 中没有 repoctl 依赖。"),
1445
+ fix: localize("Run repo init --yes or pnpm add -D repoctl.", "运行 repo init --yes,或执行 pnpm add -D repoctl。")
1446
+ }));
1447
+ const missing = Object.keys(recommendedRepoScripts).filter((name) => !hasScript(context.packageJson, name));
1448
+ const unexpected = Object.entries(recommendedRepoScripts).filter(([name, command]) => hasScript(context.packageJson, name) && context.packageJson.scripts?.[name] !== command).map(([name]) => name);
1449
+ checks.push(missing.length === 0 && unexpected.length === 0 ? createCheck({
1450
+ id: "root-scripts",
1451
+ title: localize("repo:* root scripts", "repo:* 根脚本"),
1452
+ status: "pass",
1453
+ detail: localize("Found repo:init, repo:new, repo:check, and repo:doctor root scripts.", "已检测到 repo:init、repo:new、repo:check 和 repo:doctor 根脚本。")
1454
+ }) : createCheck({
1455
+ id: "root-scripts",
1456
+ title: localize("repo:* root scripts", "repo:* 根脚本"),
1457
+ status: "warn",
1458
+ detail: localize(`Recommended root scripts need attention. Missing: ${missing.join(", ") || "none"}; unexpected: ${unexpected.join(", ") || "none"}.`, `推荐根脚本需要调整。缺少:${missing.join(", ") || "无"};命令不一致:${unexpected.join(", ") || "无"}。`),
1459
+ fix: localize("Run repo init --yes or update the scripts in package.json.", "运行 repo init --yes,或更新 package.json 中的脚本。")
1460
+ }));
1461
+ const legacyFiles = await findLegacyToolingFiles(context);
1462
+ checks.push(legacyFiles.length === 0 ? createCheck({
1463
+ id: "tooling-imports",
1464
+ title: localize("Tooling imports", "Tooling 导入"),
1465
+ status: "pass",
1466
+ detail: localize("Tooling configuration uses current repoctl entrypoints.", "Tooling 配置使用当前 repoctl 入口。")
1467
+ }) : createCheck({
1468
+ id: "tooling-imports",
1469
+ title: localize("Tooling imports", "Tooling 导入"),
1470
+ status: "warn",
1471
+ detail: localize(`These files reference legacy tooling entries: ${legacyFiles.join(", ")}.`, `以下文件引用旧 tooling 入口:${legacyFiles.join(", ")}。`),
1472
+ fix: localize("Run repo upgrade --yes to migrate to repoctl/tooling.", "运行 repo upgrade --yes 迁移到 repoctl/tooling。")
1473
+ }));
1474
+ return checks;
1475
+ }
1476
+ //#endregion
1477
+ //#region src/commands/doctor/workspace.ts
1478
+ function collectWorkspaceChecks(context) {
1479
+ const { hasPackageJson, hasWorkspaceManifest, hasRepoctlConfig, hasLegacyMonorepoConfig, hasHuskyPreCommit, hasLintStagedConfig, packageCount, packageJson, workspaceDir, workspacePackageDirs, workspacePatterns } = context;
1394
1480
  const checks = [hasPackageJson ? createCheck({
1395
1481
  id: "package-json",
1396
1482
  title: "package.json",
1397
1483
  status: "pass",
1398
- detail: `已找到根 package.json:${packageJsonPath}`
1484
+ detail: localize(`Found root package.json: ${workspaceDir}/package.json`, `已找到根 package.json:${workspaceDir}/package.json`)
1399
1485
  }) : createCheck({
1400
1486
  id: "package-json",
1401
1487
  title: "package.json",
1402
1488
  status: "fail",
1403
- detail: "当前目录缺少根 package.json。",
1404
- fix: "请在 monorepo 根目录执行命令,或先完成脚手架初始化。"
1489
+ detail: localize("The current directory does not contain a root package.json.", "当前目录缺少根 package.json。"),
1490
+ fix: localize("Run the command from the monorepo root or initialize the workspace first.", "请在 monorepo 根目录执行命令,或先完成工作区初始化。")
1405
1491
  }), hasWorkspaceManifest ? createCheck({
1406
1492
  id: "workspace-manifest",
1407
1493
  title: "pnpm workspace",
1408
1494
  status: "pass",
1409
- detail: `已找到 pnpm workspace,当前识别到 ${packageCount} 个 workspace 包。`
1495
+ detail: localize(`Found a pnpm workspace with ${packageCount} package(s).`, `已找到 pnpm workspace,当前识别到 ${packageCount} 个 workspace 包。`)
1410
1496
  }) : createCheck({
1411
1497
  id: "workspace-manifest",
1412
1498
  title: "pnpm workspace",
1413
1499
  status: "fail",
1414
- detail: "缺少 pnpm-workspace.yaml,当前目录不像一个完整的 pnpm monorepo 根目录。",
1415
- fix: "运行 repo init --yes 补充 pnpm-workspace.yaml,或确认你当前就在仓库根目录。"
1500
+ detail: localize("pnpm-workspace.yaml is missing; this directory is not a complete pnpm monorepo root.", "缺少 pnpm-workspace.yaml,当前目录不是完整的 pnpm monorepo 根目录。"),
1501
+ fix: localize("Run repo init --yes or switch to the workspace root.", "运行 repo init --yes,或切换到 workspace 根目录。")
1416
1502
  })];
1417
- const nodeRange = pkgJson.engines?.node;
1418
- if (typeof nodeRange === "string" && nodeRange.length > 0) checks.push(satisfies(process.version, nodeRange) ? createCheck({
1503
+ const nodeRange = packageJson.engines?.node;
1504
+ if (nodeRange) checks.push(satisfies(process.version, nodeRange) ? createCheck({
1419
1505
  id: "node-version",
1420
- title: "Node 版本",
1506
+ title: localize("Node version", "Node 版本"),
1421
1507
  status: "pass",
1422
- detail: `当前 Node 版本 ${process.version} 满足要求 ${nodeRange}。`
1508
+ detail: localize(`Node ${process.version} satisfies ${nodeRange}.`, `当前 Node 版本 ${process.version} 满足要求 ${nodeRange}。`)
1423
1509
  }) : createCheck({
1424
1510
  id: "node-version",
1425
- title: "Node 版本",
1511
+ title: localize("Node version", "Node 版本"),
1426
1512
  status: "fail",
1427
- detail: `当前 Node 版本 ${process.version} 不满足要求 ${nodeRange}。`,
1428
- fix: "切换到 package.json -> engines.node 要求的版本后再执行 install / build / check。"
1513
+ detail: localize(`Node ${process.version} does not satisfy ${nodeRange}.`, `当前 Node 版本 ${process.version} 不满足要求 ${nodeRange}。`),
1514
+ fix: localize("Switch to a version allowed by package.json engines.node before continuing.", "继续之前,请切换到 package.json engines.node 允许的版本。")
1429
1515
  }));
1430
1516
  else checks.push(createCheck({
1431
1517
  id: "node-version",
1432
- title: "Node 版本",
1518
+ title: localize("Node version", "Node 版本"),
1433
1519
  status: "warn",
1434
- detail: "根 package.json 未声明 engines.node,无法自动校验 Node 版本。",
1435
- fix: "建议补充 package.json -> engines.node,避免团队成员使用不一致的运行时。"
1436
- }));
1437
- const toolPackage = resolveToolPackageName(pkgJson);
1438
- checks.push(toolPackage ? createCheck({
1439
- id: "tool-package",
1440
- title: "repo CLI 依赖",
1441
- status: "pass",
1442
- detail: `已检测到 CLI 工具依赖:${toolPackage.name}@${toolPackage.version}`
1443
- }) : createCheck({
1444
- id: "tool-package",
1445
- title: "repo CLI 依赖",
1446
- status: "fail",
1447
- detail: "根 package.json 中未发现 repoctl 依赖。",
1448
- fix: "运行 repo init --yes 添加 repoctl devDependency,或手动执行 pnpm add -D repoctl。"
1520
+ detail: localize("The root package.json does not declare engines.node.", "根 package.json 未声明 engines.node。"),
1521
+ fix: localize("Declare package.json engines.node to keep runtimes consistent.", "请声明 package.json engines.node 以保持运行时一致。")
1449
1522
  }));
1450
- const missingRepoScripts = getMissingScripts(pkgJson, recommendedRepoScripts);
1451
- const unexpectedRepoScripts = getUnexpectedScripts(pkgJson, recommendedRepoScripts);
1452
- if (missingRepoScripts.length === 0 && unexpectedRepoScripts.length === 0) checks.push(createCheck({
1453
- id: "root-scripts",
1454
- title: "repo:* 根脚本",
1455
- status: "pass",
1456
- detail: "已检测到 repo:init / repo:new / repo:check / repo:doctor,推荐使用 pnpm run repo:doctor -- --json 这类无冲突入口。"
1457
- }));
1458
- else {
1459
- const details = [missingRepoScripts.length ? `缺少:${missingRepoScripts.join(", ")}` : null, unexpectedRepoScripts.length ? `命令不一致:${unexpectedRepoScripts.join(", ")}` : null].filter(Boolean).join(";");
1460
- checks.push(createCheck({
1461
- id: "root-scripts",
1462
- title: "repo:* 根脚本",
1463
- status: "warn",
1464
- detail: `推荐的 repo:* 根脚本未完全就绪。${details}。`,
1465
- fix: "运行 repo init --yes 同步推荐根脚本,或手动在 package.json 中补齐 repo:init / repo:new / repo:check / repo:doctor。"
1466
- }));
1467
- }
1468
1523
  if (hasLegacyMonorepoConfig) checks.push(createCheck({
1469
1524
  id: "config-file",
1470
- title: "配置文件",
1525
+ title: localize("Configuration file", "配置文件"),
1471
1526
  status: "fail",
1472
- detail: "检测到已废弃的 monorepo.config.ts,repoctl 不再加载该文件。",
1473
- fix: "将 monorepo.config.ts 改名为 repoctl.config.ts,并确认根配置只保留 repoctl.config.ts。"
1527
+ detail: localize("Found deprecated monorepo.config.ts; repoctl no longer loads it.", "检测到已废弃的 monorepo.config.ts;repoctl 不再加载该文件。"),
1528
+ fix: localize("Rename it to repoctl.config.ts and keep only the repoctl config.", "将其重命名为 repoctl.config.ts,并只保留 repoctl 配置。")
1474
1529
  }));
1475
1530
  else if (hasRepoctlConfig) checks.push(createCheck({
1476
1531
  id: "config-file",
1477
- title: "配置文件",
1532
+ title: localize("Configuration file", "配置文件"),
1478
1533
  status: "pass",
1479
- detail: "已检测到配置文件:repoctl.config.ts"
1534
+ detail: localize("Found repoctl.config.ts.", "已检测到 repoctl.config.ts。")
1480
1535
  }));
1481
1536
  else checks.push(createCheck({
1482
1537
  id: "config-file",
1483
- title: "配置文件",
1538
+ title: localize("Configuration file", "配置文件"),
1484
1539
  status: "warn",
1485
- detail: "当前仓库没有自定义配置文件,CLI 会完全使用默认行为。",
1486
- fix: "运行 repo upgrade --yes 同步默认 repoctl.config.ts,或手动添加 repoctl.config.ts。"
1540
+ detail: localize("No custom configuration file was found; the CLI will use defaults.", "未找到自定义配置文件;CLI 将使用默认配置。"),
1541
+ fix: localize("Run repo upgrade --yes or add repoctl.config.ts manually.", "运行 repo upgrade --yes,或手动添加 repoctl.config.ts。")
1487
1542
  }));
1488
1543
  if (hasHuskyPreCommit && hasLintStagedConfig) checks.push(createCheck({
1489
1544
  id: "commit-hooks",
1490
- title: "提交链路",
1545
+ title: localize("Commit hooks", "提交钩子"),
1491
1546
  status: "pass",
1492
- detail: "已检测到 .husky/pre-commit 与 lint-staged.config.js,提交前校验链路完整。"
1493
- }));
1494
- else if (hasHuskyPreCommit || hasLintStagedConfig) checks.push(createCheck({
1495
- id: "commit-hooks",
1496
- title: "提交链路",
1497
- status: "warn",
1498
- detail: "提交校验链路只配置了一半,Husky 与 lint-staged 没有同时就绪。",
1499
- fix: "运行 repo upgrade --yes 同步 .husky/pre-commit 与 lint-staged.config.js。"
1547
+ detail: localize("Found .husky/pre-commit and lint-staged.config.js.", "已检测到 .husky/pre-commit 和 lint-staged.config.js。")
1500
1548
  }));
1501
1549
  else checks.push(createCheck({
1502
1550
  id: "commit-hooks",
1503
- title: "提交链路",
1551
+ title: localize("Commit hooks", "提交钩子"),
1504
1552
  status: "warn",
1505
- detail: "当前仓库未检测到 Husky / lint-staged 提交校验入口。",
1506
- fix: "运行 repo upgrade --yes 同步 Husky 与 lint-staged 默认配置。"
1553
+ detail: localize("Husky and lint-staged are not both configured.", "Husky 和 lint-staged 尚未同时配置。"),
1554
+ fix: localize("Run repo upgrade --yes to synchronize the default hooks.", "运行 repo upgrade --yes 同步默认钩子。")
1507
1555
  }));
1508
- const configFiles = [...isSourceWorkspace ? [] : [
1509
- "eslint.config.js",
1510
- "stylelint.config.js",
1511
- "lint-staged.config.js",
1512
- "vitest.config.ts"
1513
- ], ...[
1556
+ const missingPatterns = [
1514
1557
  "apps",
1515
1558
  "packages",
1516
1559
  "examples"
1517
- ].flatMap((dir) => [`${dir}/*/eslint.config.js`, `${dir}/*/vitest.config.ts`])];
1518
- const legacyToolingFiles = [];
1519
- for (const filePattern of configFiles) {
1520
- if (filePattern.includes("*")) {
1521
- const [baseDir, rest] = filePattern.split("/*/");
1522
- const absBaseDir = `${workspaceDir}/${baseDir}`;
1523
- if (!await fs$1.pathExists(absBaseDir)) continue;
1524
- const entries = await readdir(absBaseDir);
1525
- await Promise.all(entries.map(async (entry) => {
1526
- const candidate = `${absBaseDir}/${entry}/${rest}`;
1527
- if (await fs$1.pathExists(candidate) && hasLegacyToolingReference(await fs$1.readFile(candidate, "utf8"))) legacyToolingFiles.push(`${baseDir}/${entry}/${rest}`);
1528
- }));
1529
- continue;
1530
- }
1531
- const candidate = `${workspaceDir}/${filePattern}`;
1532
- if (await fs$1.pathExists(candidate) && hasLegacyToolingReference(await fs$1.readFile(candidate, "utf8"))) legacyToolingFiles.push(filePattern);
1560
+ ].filter((base) => workspacePackageDirs.some((dir) => dir.startsWith(`${base}/`))).map((base) => `${base}/*`).filter((pattern) => !workspacePatterns.includes(pattern));
1561
+ if (hasWorkspaceManifest) {
1562
+ checks.push(createCheck(missingPatterns.length === 0 ? {
1563
+ id: "workspace-patterns",
1564
+ title: localize("Workspace patterns", "Workspace 匹配规则"),
1565
+ status: "pass",
1566
+ detail: localize("pnpm-workspace.yaml includes the existing conventional workspace directories.", "pnpm-workspace.yaml 已包含现有的常规 workspace 目录。")
1567
+ } : {
1568
+ id: "workspace-patterns",
1569
+ title: localize("Workspace patterns", "Workspace 匹配规则"),
1570
+ status: "warn",
1571
+ detail: localize(`pnpm-workspace.yaml is missing: ${missingPatterns.join(", ")}.`, `pnpm-workspace.yaml 缺少:${missingPatterns.join(", ")}。`),
1572
+ fix: localize("Run repo init --yes to append missing workspace patterns.", "运行 repo init --yes 追加缺失的 workspace 匹配规则。")
1573
+ }));
1574
+ const uncovered = workspacePackageDirs.filter((dir) => !isWorkspacePatternCovered(dir, workspacePatterns));
1575
+ checks.push(createCheck(uncovered.length === 0 ? {
1576
+ id: "workspace-package-coverage",
1577
+ title: localize("Workspace package coverage", "Workspace 包覆盖"),
1578
+ status: "pass",
1579
+ detail: localize("Every package.json in a conventional workspace directory is covered.", "常规 workspace 目录中的 package.json 均已覆盖。")
1580
+ } : {
1581
+ id: "workspace-package-coverage",
1582
+ title: localize("Workspace package coverage", "Workspace 包覆盖"),
1583
+ status: "warn",
1584
+ detail: localize(`These packages are not covered by pnpm-workspace.yaml: ${uncovered.join(", ")}.`, `以下包未被 pnpm-workspace.yaml 覆盖:${uncovered.join(", ")}。`),
1585
+ fix: localize("Run repo init --yes to append missing workspace patterns.", "运行 repo init --yes 追加缺失的 workspace 匹配规则。")
1586
+ }));
1533
1587
  }
1534
- if (legacyToolingFiles.length === 0) checks.push(createCheck({
1535
- id: "tooling-imports",
1536
- title: "tooling imports",
1537
- status: "pass",
1538
- detail: "tooling 配置未引用本地源码仓库 loader 或旧 @icebreakers/*-config wrapper。"
1539
- }));
1540
- else checks.push(createCheck({
1541
- id: "tooling-imports",
1542
- title: "tooling imports",
1543
- status: "warn",
1544
- detail: `以下配置引用了旧 tooling 入口:${legacyToolingFiles.join(", ")}。`,
1545
- fix: "运行 repo upgrade --yes 迁移为直接 import repoctl/tooling,并保留现有配置语义。"
1546
- }));
1547
- const missingCommonPatterns = (await Promise.all([
1548
- "apps",
1549
- "packages",
1550
- "examples"
1551
- ].map(async (base) => ({
1552
- base,
1553
- exists: await fs$1.pathExists(`${workspaceDir}/${base}`)
1554
- })))).filter((item) => item.exists).map((item) => item.base).map((base) => `${base}/*`).filter((pattern) => !workspacePatterns.includes(pattern));
1555
- if (hasWorkspaceManifest && missingCommonPatterns.length === 0) checks.push(createCheck({
1556
- id: "workspace-patterns",
1557
- title: "workspace patterns",
1558
- status: "pass",
1559
- detail: "pnpm-workspace.yaml 已包含 apps/* / packages/* / examples/* 常见目录。"
1560
- }));
1561
- else if (hasWorkspaceManifest) checks.push(createCheck({
1562
- id: "workspace-patterns",
1563
- title: "workspace patterns",
1564
- status: "warn",
1565
- detail: `pnpm-workspace.yaml 缺少常见目录:${missingCommonPatterns.join(", ")}。`,
1566
- fix: "运行 repo init --yes 追加缺失 workspace patterns。"
1567
- }));
1568
- const uncoveredWorkspacePackages = workspacePackageDirs.filter((dir) => !isWorkspacePatternCovered(dir, workspacePatterns));
1569
- if (hasWorkspaceManifest && uncoveredWorkspacePackages.length === 0) checks.push(createCheck({
1570
- id: "workspace-package-coverage",
1571
- title: "workspace package coverage",
1572
- status: "pass",
1573
- detail: "常见 workspace 目录下的 package.json 都已被 pnpm-workspace.yaml 覆盖。"
1574
- }));
1575
- else if (hasWorkspaceManifest) checks.push(createCheck({
1576
- id: "workspace-package-coverage",
1577
- title: "workspace package coverage",
1578
- status: "warn",
1579
- detail: `以下 package.json 未被 pnpm-workspace.yaml 覆盖:${uncoveredWorkspacePackages.join(", ")}。`,
1580
- fix: "运行 repo init --yes 追加缺失 workspace patterns。"
1581
- }));
1582
- checks.push(...await collectReleaseChecks(workspaceDir, pkgJson));
1588
+ return checks;
1589
+ }
1590
+ //#endregion
1591
+ //#region src/commands/doctor/index.ts
1592
+ async function runDoctor(cwd) {
1593
+ const context = await collectDoctorContext(cwd);
1594
+ const checks = [
1595
+ ...collectWorkspaceChecks(context),
1596
+ ...await collectToolingChecks(context),
1597
+ ...await collectReleaseChecks(context.workspaceDir, context.packageJson)
1598
+ ];
1583
1599
  return {
1584
1600
  cwd,
1585
- workspaceDir,
1586
- packageCount,
1601
+ workspaceDir: context.workspaceDir,
1602
+ packageCount: context.packageCount,
1587
1603
  checks,
1588
1604
  summary: summarizeChecks(checks)
1589
1605
  };
@@ -1833,17 +1849,26 @@ var devDependencies = {
1833
1849
  //#region src/commands/init/tooling/presets.ts
1834
1850
  const packageDependencies = {
1835
1851
  ...{
1836
- name: "monorepo-template",
1852
+ name: "repoctl-workspace",
1837
1853
  type: "module",
1838
1854
  version: "0.0.0",
1839
1855
  "private": true,
1840
- packageManager: "pnpm@11.21.0",
1856
+ packageManager: "pnpm@11.22.0",
1857
+ description: "Source workspace for repoctl, a task-first CLI for pnpm and Turborepo monorepos",
1841
1858
  author: "ice breaker <hi@sonofmagic.top>",
1859
+ homepage: "https://repo.icebreaker.top",
1842
1860
  repository: {
1843
1861
  "type": "git",
1844
- "url": "git+https://github.com/sonofmagic/monorepo-template.git"
1862
+ "url": "git+https://github.com/sonofmagic/repoctl.git"
1845
1863
  },
1846
- bugs: { "url": "https://github.com/sonofmagic/monorepo-template/issues" },
1864
+ bugs: { "url": "https://github.com/sonofmagic/repoctl/issues" },
1865
+ keywords: [
1866
+ "repoctl",
1867
+ "monorepo",
1868
+ "pnpm",
1869
+ "turborepo",
1870
+ "typescript"
1871
+ ],
1847
1872
  engines: { "node": ">=22.12.0" },
1848
1873
  scripts: {
1849
1874
  "build": "turbo run build",
@@ -1894,7 +1919,7 @@ const packageDependencies = {
1894
1919
  };
1895
1920
  function getDependencyVersion(name) {
1896
1921
  const version = packageDependencies[name];
1897
- if (!version) throw new Error(`未找到依赖 ${name} 的版本信息`);
1922
+ if (!version) throw new Error(localize(`No version information was found for dependency ${name}.`, `未找到依赖 ${name} 的版本信息。`));
1898
1923
  return version;
1899
1924
  }
1900
1925
  function getToolingPackageVersion() {
@@ -2014,7 +2039,7 @@ function resolveTargets(options) {
2014
2039
  }
2015
2040
  function normalizeInitToolingTargets(input) {
2016
2041
  const unknown = input.filter((item) => !initToolingTargets.includes(item));
2017
- if (unknown.length > 0) throw new Error(`未知的 init tooling 目标: ${unknown.join(", ")}`);
2042
+ if (unknown.length > 0) throw new Error(localize(`Unknown init tooling target: ${unknown.join(", ")}`, `未知的 init tooling 目标:${unknown.join(", ")}`));
2018
2043
  return input;
2019
2044
  }
2020
2045
  async function initTooling(cwd, options = {}) {
@@ -2026,7 +2051,7 @@ async function initTooling(cwd, options = {}) {
2026
2051
  updatedPackageJson: false
2027
2052
  };
2028
2053
  const pkgJsonPath = path.resolve(cwd, "package.json");
2029
- if (!await fs$1.pathExists(pkgJsonPath)) throw new Error(`未找到 package.json,无法初始化 tooling: ${pkgJsonPath}`);
2054
+ if (!await fs$1.pathExists(pkgJsonPath)) throw new Error(localize(`Cannot initialize tooling because package.json was not found: ${pkgJsonPath}`, `未找到 package.json,无法初始化 tooling:${pkgJsonPath}`));
2030
2055
  const packageJson = await fs$1.readJson(pkgJsonPath);
2031
2056
  const toolingPackageName = resolveToolingPackageName();
2032
2057
  const toolingImportSource = resolveToolingImportSource();
@@ -2045,7 +2070,7 @@ async function initTooling(cwd, options = {}) {
2045
2070
  }));
2046
2071
  if (exists && !options.force) {
2047
2072
  skippedFiles.push(preset.filepath);
2048
- logger.info(`skip existing init target: ${preset.filepath}`);
2073
+ logger.info(localize(`Skipped existing init target: ${preset.filepath}`, `跳过已存在的初始化目标:${preset.filepath}`));
2049
2074
  continue;
2050
2075
  }
2051
2076
  const content = await preset.getContent({
@@ -2228,6 +2253,15 @@ const categoryTitles = {
2228
2253
  maintenance: "🧰 Maintenance",
2229
2254
  other: "🧩 Other Changes"
2230
2255
  };
2256
+ const zhCNCategoryTitles = {
2257
+ breaking: "🚨 破坏性变更",
2258
+ features: "🚀 新功能",
2259
+ fixes: "🐞 问题修复",
2260
+ performance: "🏎 性能优化",
2261
+ docs: "📚 文档",
2262
+ maintenance: "🧰 维护",
2263
+ other: "🧩 其他变更"
2264
+ };
2231
2265
  function readVersionSection(changelog, version) {
2232
2266
  const versions = [...changelog.matchAll(/^## ([^\n]+)$/gm)];
2233
2267
  const index = versions.findIndex((match) => match[1] === version);
@@ -2461,6 +2495,12 @@ function buildEntries(release, commits) {
2461
2495
  }
2462
2496
  //#endregion
2463
2497
  //#region src/commands/release/notes/render.ts
2498
+ function isChinese(metadata) {
2499
+ return (metadata.locale ?? resolveRepoctlLocale()) === "zh-CN";
2500
+ }
2501
+ function localized(metadata, english, simplifiedChinese) {
2502
+ return isChinese(metadata) ? simplifiedChinese : english;
2503
+ }
2464
2504
  function formatReferenceLinks(entry, metadata) {
2465
2505
  const repository = metadata.repository && /^[^/]+\/[^/]+$/.test(metadata.repository) ? metadata.repository : void 0;
2466
2506
  const serverUrl = (metadata.serverUrl || "https://github.com").replace(/\/$/, "");
@@ -2481,7 +2521,7 @@ function formatCategoryEntries(entries, category, metadata, headingLevel, linkNp
2481
2521
  const matching = entries.filter((entry) => entry.category === category);
2482
2522
  if (!matching.length) return [];
2483
2523
  return [
2484
- `${"#".repeat(headingLevel)} ${categoryTitles[category]}`,
2524
+ `${"#".repeat(headingLevel)} ${isChinese(metadata) ? zhCNCategoryTitles[category] : categoryTitles[category]}`,
2485
2525
  "",
2486
2526
  ...matching.map((entry) => formatEntry(entry, metadata, linkNpmVersion))
2487
2527
  ];
@@ -2490,23 +2530,23 @@ function formatContributor(value) {
2490
2530
  if (value.startsWith("@")) return value;
2491
2531
  return /^[\w-]+$/.test(value) ? `@${value}` : value;
2492
2532
  }
2493
- function formatContributors(contributors) {
2533
+ function formatContributors(contributors, metadata) {
2494
2534
  const unique = [...new Set(contributors.map((value) => value.trim()).filter((value) => value && !isAutomationContributor(value)))].sort((a, b) => a.localeCompare(b));
2495
2535
  return unique.length ? [
2496
- "## ❤️ Contributors",
2536
+ `## ❤️ ${localized(metadata, "Contributors", "贡献者")}`,
2497
2537
  "",
2498
- `Thanks to ${unique.map(formatContributor).join(" · ")}`
2538
+ `${localized(metadata, "Thanks to", "感谢")} ${unique.map(formatContributor).join(" · ")}`
2499
2539
  ] : [];
2500
2540
  }
2501
2541
  function formatVersion(version, npmUrl) {
2502
2542
  return npmUrl ? `[\`${version}\`](${npmUrl})` : `\`${version}\``;
2503
2543
  }
2504
- function formatPackages(packages, linkNpmVersion) {
2544
+ function formatPackages(packages, linkNpmVersion, metadata) {
2505
2545
  if (!packages.length) return [];
2506
2546
  return [
2507
- "## Packages",
2547
+ `## ${localized(metadata, "Packages", "包")}`,
2508
2548
  "",
2509
- "| Package | From | To |",
2549
+ `| ${localized(metadata, "Package", "包")} | ${localized(metadata, "From", "原版本")} | ${localized(metadata, "To", "新版本")} |`,
2510
2550
  "| --- | --- | --- |",
2511
2551
  ...packages.map((pkg) => {
2512
2552
  const previous = pkg.previousVersion ? formatVersion(pkg.previousVersion, pkg.previousNpmUrl) : "—";
@@ -2516,31 +2556,33 @@ function formatPackages(packages, linkNpmVersion) {
2516
2556
  ];
2517
2557
  }
2518
2558
  function renderReleasePullRequest(document, metadata = {}) {
2559
+ const packageWord = isChinese(metadata) ? `${document.packages.length} 个包更新` : `${document.packages.length} package${document.packages.length === 1 ? "" : "s"} updated`;
2560
+ const changeWord = isChinese(metadata) ? `${document.entries.length} 项变更` : `${document.entries.length} change${document.entries.length === 1 ? "" : "s"}`;
2519
2561
  const sections = [
2520
- "# Release Notes",
2562
+ `# ${localized(metadata, "Release Notes", "发布说明")}`,
2521
2563
  "",
2522
- `> ${`${document.packages.length} package${document.packages.length === 1 ? "" : "s"}`} updated · ${`${document.entries.length} change${document.entries.length === 1 ? "" : "s"}`}`
2564
+ `> ${packageWord} · ${changeWord}`
2523
2565
  ];
2524
2566
  for (const category of categoryOrder.filter((category) => category !== "maintenance")) {
2525
2567
  const section = formatCategoryEntries(document.entries, category, metadata, 2, false);
2526
2568
  if (section.length) sections.push("", "", ...section);
2527
2569
  }
2528
2570
  const maintenance = formatCategoryEntries(document.entries, "maintenance", metadata, 2, false);
2529
- if (maintenance.length) sections.push("", "", "<details>", "<summary>🧰 Maintenance</summary>", "", ...maintenance.slice(2), "", "</details>");
2530
- sections.push("", "", ...formatPackages(document.packages, false));
2531
- sections.push("", "", ...formatContributors(document.contributors));
2571
+ if (maintenance.length) sections.push("", "", "<details>", `<summary>${localized(metadata, "🧰 Maintenance", "🧰 维护")}</summary>`, "", ...maintenance.slice(2), "", "</details>");
2572
+ sections.push("", "", ...formatPackages(document.packages, false, metadata));
2573
+ sections.push("", "", ...formatContributors(document.contributors, metadata));
2532
2574
  return sections.join("\n").replace(/\n{3,}/g, "\n\n").trim();
2533
2575
  }
2534
2576
  function renderGitHubRelease(document, metadata = {}) {
2535
- if (!document.entries.length) return "No significant changes.";
2577
+ if (!document.entries.length) return localized(metadata, "No significant changes.", "没有显著变更。");
2536
2578
  const sections = [];
2537
2579
  for (const category of categoryOrder) {
2538
2580
  const section = formatCategoryEntries(document.entries, category, metadata, 3, true);
2539
2581
  if (section.length) sections.push(...sections.length ? ["", ...section] : section);
2540
2582
  }
2541
2583
  const contributors = [...new Set(document.contributors)].filter((value) => !isAutomationContributor(value)).sort((a, b) => a.localeCompare(b));
2542
- if (contributors.length) sections.push("", "### ❤️ Contributors", "", `Thanks to ${contributors.map(formatContributor).join(" · ")}`);
2543
- if (document.compareUrls.length) sections.push("", `##### [View changes on GitHub](${document.compareUrls[0]})`);
2584
+ if (contributors.length) sections.push("", `### ❤️ ${localized(metadata, "Contributors", "贡献者")}`, "", `${localized(metadata, "Thanks to", "感谢")} ${contributors.map(formatContributor).join(" · ")}`);
2585
+ if (document.compareUrls.length) sections.push("", `##### [${localized(metadata, "View changes on GitHub", "在 GitHub 查看变更")}](${document.compareUrls[0]})`);
2544
2586
  return sections.join("\n");
2545
2587
  }
2546
2588
  //#endregion
@@ -2555,10 +2597,14 @@ var ReleaseCommandError = class extends Error {
2555
2597
  };
2556
2598
  //#endregion
2557
2599
  //#region src/commands/release/shared.ts
2600
+ function getReleaseEnv(options) {
2601
+ return options.env ?? process.env;
2602
+ }
2558
2603
  function run(command, args, options) {
2559
2604
  const result = (options.spawn ?? spawnSync)(command, args, {
2560
2605
  cwd: options.cwd,
2561
2606
  encoding: "utf8",
2607
+ env: getReleaseEnv(options),
2562
2608
  shell: false,
2563
2609
  stdio: "inherit"
2564
2610
  });
@@ -2568,6 +2614,7 @@ function capture(command, args, options) {
2568
2614
  const result = (options.spawn ?? spawnSync)(command, args, {
2569
2615
  cwd: options.cwd,
2570
2616
  encoding: "utf8",
2617
+ env: getReleaseEnv(options),
2571
2618
  shell: false,
2572
2619
  stdio: [
2573
2620
  "ignore",
@@ -2578,9 +2625,6 @@ function capture(command, args, options) {
2578
2625
  if (result.status !== 0) throw new ReleaseCommandError(`command failed: ${command} ${args.join(" ")}`, result.status ?? 1);
2579
2626
  return result.stdout?.toString().trim() ?? "";
2580
2627
  }
2581
- function getReleaseEnv(options) {
2582
- return options.env ?? process.env;
2583
- }
2584
2628
  function hasGitChanges(options) {
2585
2629
  return (options.spawn ?? spawnSync)("git", [
2586
2630
  "diff",
@@ -2646,10 +2690,8 @@ async function assertStableLaneAssignments(options) {
2646
2690
  const active = Object.entries(assignments).filter(([, lane]) => lane !== "main");
2647
2691
  if (active.length) throw new ReleaseCommandError(`stable releases require all packages on the main lane, found ${active.map(([name, lane]) => `${name}:${lane}`).join(", ")}`);
2648
2692
  }
2649
- function runQualityChecks(options) {
2650
- run("pnpm", ["run", "build"], options);
2651
- run("pnpm", ["run", "lint"], options);
2652
- run("pnpm", ["run", "test"], options);
2693
+ async function clearPublishSummary(cwd) {
2694
+ await rm(path.join(cwd, "pnpm-publish-summary.json"), { force: true });
2653
2695
  }
2654
2696
  function parsePublishSummary(content) {
2655
2697
  let parsed;
@@ -2796,7 +2838,12 @@ async function buildReleaseNoteDocument(cwd, previousVersions, metadata = {}) {
2796
2838
  }
2797
2839
  function buildGitHubReleaseBodyFromChangelog(packageName, packageVersion, changelog, metadata = {}) {
2798
2840
  const section = readVersionSection(changelog, packageVersion);
2799
- if (!section?.content) return "No significant changes.";
2841
+ if (!section?.content) return renderGitHubRelease({
2842
+ packages: [],
2843
+ entries: [],
2844
+ contributors: [],
2845
+ compareUrls: []
2846
+ }, metadata);
2800
2847
  return renderGitHubRelease(buildReleaseNoteDocumentFromReleases([{
2801
2848
  name: packageName,
2802
2849
  version: packageVersion,
@@ -3018,6 +3065,39 @@ var GitHubClient = class {
3018
3065
  }
3019
3066
  };
3020
3067
  //#endregion
3068
+ //#region src/commands/release/hooks.ts
3069
+ const defaultQualityScripts = [
3070
+ "build",
3071
+ "lint",
3072
+ "test"
3073
+ ];
3074
+ function validateScriptName(script) {
3075
+ const normalizedScript = script.trim();
3076
+ if (!normalizedScript) throw new ReleaseCommandError("release script name must not be empty");
3077
+ return normalizedScript;
3078
+ }
3079
+ function runScripts(scripts, options, extraEnv) {
3080
+ for (const script of scripts) run("pnpm", ["run", validateScriptName(script)], {
3081
+ ...options,
3082
+ ...extraEnv ? { env: {
3083
+ ...options.env ?? process.env,
3084
+ ...extraEnv
3085
+ } } : {}
3086
+ });
3087
+ }
3088
+ function runQualityScripts(options) {
3089
+ runScripts(options.config?.qualityScripts ?? defaultQualityScripts, options);
3090
+ }
3091
+ function runReleaseHooks(phase, options) {
3092
+ runScripts(options.config?.hooks?.[phase] ?? [], options);
3093
+ }
3094
+ function runAfterPublishHooks(packages, options) {
3095
+ runScripts(options.config?.hooks?.afterPublish ?? [], options, {
3096
+ REPO_RELEASE_PUBLISHED_PACKAGES: JSON.stringify(packages),
3097
+ REPO_RELEASE_PUBLISH_SUMMARY: path.resolve(options.cwd, "pnpm-publish-summary.json")
3098
+ });
3099
+ }
3100
+ //#endregion
3021
3101
  //#region src/commands/release/types.ts
3022
3102
  const prereleaseBranches = /* @__PURE__ */ new Set([
3023
3103
  "alpha",
@@ -3031,13 +3111,15 @@ async function releasePrerelease(options) {
3031
3111
  const branch = resolveBranch(options);
3032
3112
  if (!prereleaseBranches.has(branch)) throw new ReleaseCommandError(`repo release pre is only allowed on alpha, beta, rc, or next branches, got ${branch}`);
3033
3113
  await assertLaneAssignments(branch, options);
3034
- runQualityChecks(options);
3035
3114
  if (!await hasPendingIntents(options.cwd)) return;
3115
+ runReleaseHooks("beforeVersion", options);
3116
+ runQualityScripts(options);
3036
3117
  run("pnpm", [
3037
3118
  "version",
3038
3119
  "-r",
3039
3120
  "--no-git-checks"
3040
3121
  ], options);
3122
+ runReleaseHooks("afterVersion", options);
3041
3123
  if (!hasGitChanges(options)) return;
3042
3124
  run("git", ["add", "-A"], options);
3043
3125
  run("git", [
@@ -3045,6 +3127,8 @@ async function releasePrerelease(options) {
3045
3127
  "-m",
3046
3128
  `chore(release): ${branch} [skip ci]`
3047
3129
  ], options);
3130
+ runReleaseHooks("beforePublish", options);
3131
+ await clearPublishSummary(options.cwd);
3048
3132
  run("pnpm", [
3049
3133
  "publish",
3050
3134
  "-r",
@@ -3060,6 +3144,7 @@ async function releasePrerelease(options) {
3060
3144
  "origin",
3061
3145
  `HEAD:${branch}`
3062
3146
  ], options);
3147
+ return readPublishSummary(options.cwd);
3063
3148
  }
3064
3149
  async function enterPrerelease(tag, options) {
3065
3150
  if (!prereleaseBranches.has(tag)) throw new ReleaseCommandError(`unknown prerelease lane ${tag}; expected alpha, beta, rc, or next`);
@@ -3074,20 +3159,25 @@ async function prepareStable(options) {
3074
3159
  const branch = resolveBranch(options);
3075
3160
  if (branch !== "main") throw new ReleaseCommandError(`repo release stable prepare is only allowed on main, got ${branch}`);
3076
3161
  await assertStableLaneAssignments(options);
3077
- runQualityChecks(options);
3078
3162
  if (!await hasPendingIntents(options.cwd)) return false;
3163
+ runReleaseHooks("beforeVersion", options);
3164
+ runQualityScripts(options);
3079
3165
  run("pnpm", [
3080
3166
  "version",
3081
3167
  "-r",
3082
3168
  "--no-git-checks"
3083
3169
  ], options);
3170
+ runReleaseHooks("afterVersion", options);
3084
3171
  return hasGitChanges(options);
3085
3172
  }
3086
3173
  async function publishStable(options) {
3087
3174
  const branch = resolveBranch(options);
3088
3175
  if (branch !== "main") throw new ReleaseCommandError(`repo release stable publish is only allowed on main, got ${branch}`);
3089
3176
  await assertStableLaneAssignments(options);
3090
- runQualityChecks(options);
3177
+ if (await hasPendingIntents(options.cwd)) throw new ReleaseCommandError("stable publish found unconsumed change intents; prepare and merge the Release PR before publishing");
3178
+ runQualityScripts(options);
3179
+ runReleaseHooks("beforePublish", options);
3180
+ await clearPublishSummary(options.cwd);
3091
3181
  run("pnpm", [
3092
3182
  "publish",
3093
3183
  "-r",
@@ -3095,10 +3185,11 @@ async function publishStable(options) {
3095
3185
  "--provenance",
3096
3186
  "--no-git-checks"
3097
3187
  ], options);
3188
+ return readPublishSummary(options.cwd);
3098
3189
  }
3099
3190
  /** Compatibility entry point retained for existing generated repositories. */
3100
3191
  async function releaseStable(options) {
3101
- await publishStable(options);
3192
+ return publishStable(options);
3102
3193
  }
3103
3194
  //#endregion
3104
3195
  //#region src/commands/release/ci.ts
@@ -3136,6 +3227,9 @@ function resolveGitHub(options) {
3136
3227
  function resolveTarget(options) {
3137
3228
  return getReleaseEnv(options)["GITHUB_SHA"]?.trim() || capture("git", ["rev-parse", "HEAD"], options);
3138
3229
  }
3230
+ function resolveReleaseLocale(options) {
3231
+ return resolveRepoctlLocale({ env: getReleaseEnv(options) });
3232
+ }
3139
3233
  function formatPublishedPackageSummary(packages) {
3140
3234
  return ["Published packages:", ...packages.length ? packages.map((pkg) => ` - ${pkg.name}@${pkg.version}`) : [" (none)"]].join("\n");
3141
3235
  }
@@ -3148,6 +3242,7 @@ async function publishMetadata(packages, options, prerelease = false) {
3148
3242
  const target = resolveTarget(options);
3149
3243
  const releaseEnv = getReleaseEnv(options);
3150
3244
  const metadata = {
3245
+ locale: resolveReleaseLocale(options),
3151
3246
  ...releaseEnv["GITHUB_REPOSITORY"] ? { repository: releaseEnv["GITHUB_REPOSITORY"] } : {},
3152
3247
  ...releaseEnv["GITHUB_SERVER_URL"] ? { serverUrl: releaseEnv["GITHUB_SERVER_URL"] } : {}
3153
3248
  };
@@ -3243,6 +3338,7 @@ async function createReleasePullRequest(options) {
3243
3338
  const github = resolveGitHub(options);
3244
3339
  const releaseEnv = getReleaseEnv(options);
3245
3340
  const metadata = {
3341
+ locale: resolveReleaseLocale(options),
3246
3342
  commits: sourceCommits,
3247
3343
  ...releaseEnv["GITHUB_REPOSITORY"] ? { repository: releaseEnv["GITHUB_REPOSITORY"] } : {},
3248
3344
  ...releaseEnv["GITHUB_SERVER_URL"] ? { serverUrl: releaseEnv["GITHUB_SERVER_URL"] } : {}
@@ -3252,7 +3348,7 @@ async function createReleasePullRequest(options) {
3252
3348
  await github.ensurePullRequest({
3253
3349
  head: releaseBranch,
3254
3350
  base: "main",
3255
- title: "chore(release): version packages",
3351
+ title: resolveReleaseLocale(options) === "zh-CN" ? "chore(release): 更新包版本" : "chore(release): version packages",
3256
3352
  body: renderReleasePullRequest(noteDocument, metadata)
3257
3353
  });
3258
3354
  await github.closeLegacyReleasePullRequests?.({
@@ -3265,6 +3361,7 @@ async function recoverUnpublished(options) {
3265
3361
  const packageName = options.packageName || getReleaseEnv(options)["REPO_RELEASE_PACKAGE"]?.trim();
3266
3362
  const packageVersion = options.packageVersion || getReleaseEnv(options)["REPO_RELEASE_VERSION"]?.trim();
3267
3363
  if (!packageName || !packageVersion) throw new ReleaseCommandError("publish-unpublished requires REPO_RELEASE_PACKAGE and REPO_RELEASE_VERSION");
3364
+ if (await hasPendingIntents(options.cwd)) throw new ReleaseCommandError("publish-unpublished found unconsumed change intents; prepare and merge the Release PR before publishing");
3268
3365
  const actualVersion = capture("pnpm", [
3269
3366
  "--filter",
3270
3367
  packageName,
@@ -3274,6 +3371,9 @@ async function recoverUnpublished(options) {
3274
3371
  "require('./package.json').version"
3275
3372
  ], options);
3276
3373
  if (actualVersion !== packageVersion) throw new ReleaseCommandError(`expected ${packageName}@${packageVersion} in the workspace, found ${actualVersion}`);
3374
+ runQualityScripts(options);
3375
+ runReleaseHooks("beforePublish", options);
3376
+ await clearPublishSummary(options.cwd);
3277
3377
  run("pnpm", [
3278
3378
  "publish",
3279
3379
  "-r",
@@ -3288,7 +3388,10 @@ async function recoverUnpublished(options) {
3288
3388
  `${packageName}@${packageVersion}`,
3289
3389
  "version"
3290
3390
  ], options) !== packageVersion) throw new ReleaseCommandError(`npm did not report ${packageName}@${packageVersion} after recovery`);
3291
- await publishMetadata(await readPublishSummary(options.cwd), options);
3391
+ const packages = await readPublishSummary(options.cwd);
3392
+ await publishMetadata(packages, options);
3393
+ runAfterPublishHooks(packages, options);
3394
+ return packages;
3292
3395
  }
3293
3396
  function resolveMode(options) {
3294
3397
  const requested = options.mode || getReleaseEnv(options)["REPO_RELEASE_MODE"]?.trim();
@@ -3302,28 +3405,30 @@ async function releaseCi(options) {
3302
3405
  return;
3303
3406
  }
3304
3407
  if (mode === "publish") {
3305
- await publishStable(options);
3306
- await publishMetadata(await readPublishSummary(options.cwd), options);
3307
- return;
3308
- }
3309
- if (mode === "publish-unpublished") {
3310
- await recoverUnpublished(options);
3311
- return;
3408
+ const packages = await publishStable(options);
3409
+ await publishMetadata(packages, options);
3410
+ runAfterPublishHooks(packages, options);
3411
+ return packages;
3312
3412
  }
3413
+ if (mode === "publish-unpublished") return recoverUnpublished(options);
3313
3414
  if (mode !== "auto") throw new ReleaseCommandError(`unknown release CI mode ${mode}; expected auto, prepare, publish, or publish-unpublished`);
3314
3415
  const branch = resolveBranch(options);
3315
3416
  if (prereleaseBranches.has(branch)) {
3316
- await releasePrerelease(options);
3317
- await publishMetadata(await readPublishSummary(options.cwd), options, true);
3318
- return;
3417
+ const packages = await releasePrerelease(options);
3418
+ if (!packages) return;
3419
+ await publishMetadata(packages, options, true);
3420
+ runAfterPublishHooks(packages, options);
3421
+ return packages;
3319
3422
  }
3320
3423
  if (branch !== "main") throw new ReleaseCommandError(`repo release ci only supports main, alpha, beta, rc, or next branches, got ${branch}`);
3321
3424
  if (await hasPendingIntents(options.cwd)) {
3322
3425
  await createReleasePullRequest(options);
3323
3426
  return;
3324
3427
  }
3325
- await publishStable(options);
3326
- await publishMetadata(await readPublishSummary(options.cwd), options);
3428
+ const packages = await publishStable(options);
3429
+ await publishMetadata(packages, options);
3430
+ runAfterPublishHooks(packages, options);
3431
+ return packages;
3327
3432
  }
3328
3433
  //#endregion
3329
3434
  //#region src/commands/release/repair.ts
@@ -3478,27 +3583,27 @@ async function checkTemplates(options = {}) {
3478
3583
  checks.push(sourceDuplicates.length ? {
3479
3584
  id: "unique-source",
3480
3585
  status: "fail",
3481
- title: "模板 source 唯一性",
3482
- detail: `存在重复 source:${sourceDuplicates.map(([value, first, second]) => `${value} (${first}, ${second})`).join(", ")}`,
3483
- fix: "调整 template-data.mjs,确保每个模板 key 指向独立 source。"
3586
+ title: localize("Template source uniqueness", "模板 source 唯一性"),
3587
+ detail: localize(`Duplicate sources: ${sourceDuplicates.map(([value, first, second]) => `${value} (${first}, ${second})`).join(", ")}`, `存在重复 source:${sourceDuplicates.map(([value, first, second]) => `${value} (${first}, ${second})`).join(", ")}`),
3588
+ fix: localize("Update template-data.mjs so every template has a unique source.", "调整 template-data.mjs,确保每个模板 key 指向独立 source。")
3484
3589
  } : {
3485
3590
  id: "unique-source",
3486
3591
  status: "pass",
3487
- title: "模板 source 唯一性",
3488
- detail: "所有模板 source 都是唯一的。"
3592
+ title: localize("Template source uniqueness", "模板 source 唯一性"),
3593
+ detail: localize("Every template source is unique.", "所有模板 source 都是唯一的。")
3489
3594
  });
3490
3595
  const targetDuplicates = checkDuplicates(choices, "target");
3491
3596
  checks.push(targetDuplicates.length ? {
3492
3597
  id: "unique-target",
3493
3598
  status: "fail",
3494
- title: "模板 target 唯一性",
3495
- detail: `存在重复 target:${targetDuplicates.map(([value, first, second]) => `${value} (${first}, ${second})`).join(", ")}`,
3496
- fix: "调整 template-data.mjs,避免多个模板默认写入同一目标目录。"
3599
+ title: localize("Template target uniqueness", "模板 target 唯一性"),
3600
+ detail: localize(`Duplicate targets: ${targetDuplicates.map(([value, first, second]) => `${value} (${first}, ${second})`).join(", ")}`, `存在重复 target:${targetDuplicates.map(([value, first, second]) => `${value} (${first}, ${second})`).join(", ")}`),
3601
+ fix: localize("Update template-data.mjs so every template has a unique target.", "调整 template-data.mjs,避免多个模板默认写入同一目标目录。")
3497
3602
  } : {
3498
3603
  id: "unique-target",
3499
3604
  status: "pass",
3500
- title: "模板 target 唯一性",
3501
- detail: "所有模板 target 都是唯一的。"
3605
+ title: localize("Template target uniqueness", "模板 target 唯一性"),
3606
+ detail: localize("Every template target is unique.", "所有模板 target 都是唯一的。")
3502
3607
  });
3503
3608
  for (const choice of choices) {
3504
3609
  const sourceDir = path.join(templatesDir$1, choice.source);
@@ -3508,43 +3613,43 @@ async function checkTemplates(options = {}) {
3508
3613
  id: "source-dir",
3509
3614
  template: choice.key,
3510
3615
  status: "pass",
3511
- title: "模板目录",
3512
- detail: `${choice.key} source exists: ${path.relative(templatesDir$1, sourceDir)}`
3616
+ title: localize("Template directory", "模板目录"),
3617
+ detail: localize(`${choice.key} source exists: ${path.relative(templatesDir$1, sourceDir)}`, `${choice.key} 源目录存在:${path.relative(templatesDir$1, sourceDir)}`)
3513
3618
  } : {
3514
3619
  id: "source-dir",
3515
3620
  template: choice.key,
3516
3621
  status: "fail",
3517
- title: "模板目录",
3518
- detail: `${choice.key} 缺少 source 目录:${sourceDir}`,
3519
- fix: "补齐模板目录,或修正 template-data.mjs 中的 source。"
3622
+ title: localize("Template directory", "模板目录"),
3623
+ detail: localize(`${choice.key} is missing source directory: ${sourceDir}`, `${choice.key} 缺少 source 目录:${sourceDir}`),
3624
+ fix: localize("Add the directory or correct template-data.mjs.", "补齐模板目录,或修正 template-data.mjs 中的 source。")
3520
3625
  });
3521
3626
  checks.push(await fs$1.pathExists(packageJsonPath) ? {
3522
3627
  id: "package-json",
3523
3628
  template: choice.key,
3524
3629
  status: "pass",
3525
- title: "模板 package.json",
3526
- detail: `${choice.key} 包含 package.json。`
3630
+ title: localize("Template package.json", "模板 package.json"),
3631
+ detail: localize(`${choice.key} contains package.json.`, `${choice.key} 包含 package.json。`)
3527
3632
  } : {
3528
3633
  id: "package-json",
3529
3634
  template: choice.key,
3530
3635
  status: "fail",
3531
- title: "模板 package.json",
3532
- detail: `${choice.key} 缺少 package.json。`,
3533
- fix: "模板根目录应包含 package.json,脚手架会基于它重写 name/version/repository。"
3636
+ title: localize("Template package.json", "模板 package.json"),
3637
+ detail: localize(`${choice.key} is missing package.json.`, `${choice.key} 缺少 package.json。`),
3638
+ fix: localize("Template roots need package.json so scaffolding can rewrite metadata.", "模板根目录应包含 package.json,脚手架会基于它重写 name/version/repository。")
3534
3639
  });
3535
3640
  checks.push(choice.category && choice.description ? {
3536
3641
  id: "metadata",
3537
3642
  template: choice.key,
3538
3643
  status: "pass",
3539
- title: "模板元数据",
3540
- detail: `${choice.key} 已声明 category 和 description。`
3644
+ title: localize("Template metadata", "模板元数据"),
3645
+ detail: localize(`${choice.key} declares category and description.`, `${choice.key} 已声明 category 和 description。`)
3541
3646
  } : {
3542
3647
  id: "metadata",
3543
3648
  template: choice.key,
3544
3649
  status: "warn",
3545
- title: "模板元数据",
3546
- detail: `${choice.key} 缺少 category 或 description。`,
3547
- fix: "补充 template-data.mjs 中的 category 和 description,方便 CLI 和文档展示。"
3650
+ title: localize("Template metadata", "模板元数据"),
3651
+ detail: localize(`${choice.key} is missing category or description.`, `${choice.key} 缺少 category 或 description。`),
3652
+ fix: localize("Add category and description in template-data.mjs.", "补充 template-data.mjs 中的 category 和 description,方便 CLI 和文档展示。")
3548
3653
  });
3549
3654
  if (!sourceExists) continue;
3550
3655
  const skippedFiles = (await collectFiles(sourceDir)).filter((file) => shouldSkipTemplatePath(sourceDir, file)).map((file) => path.relative(sourceDir, file));
@@ -3552,15 +3657,15 @@ async function checkTemplates(options = {}) {
3552
3657
  id: "filtered-files",
3553
3658
  template: choice.key,
3554
3659
  status: "fail",
3555
- title: "模板临时文件",
3556
- detail: `${choice.key} 包含会被脚手架过滤的文件:${skippedFiles.join(", ")}`,
3557
- fix: "删除模板源目录里的临时、缓存或生成文件。"
3660
+ title: localize("Temporary template files", "模板临时文件"),
3661
+ detail: localize(`${choice.key} contains filtered files: ${skippedFiles.join(", ")}`, `${choice.key} 包含会被脚手架过滤的文件:${skippedFiles.join(", ")}`),
3662
+ fix: localize("Remove temporary, cache, or generated files from the template source.", "删除模板源目录里的临时、缓存或生成文件。")
3558
3663
  } : {
3559
3664
  id: "filtered-files",
3560
3665
  template: choice.key,
3561
3666
  status: "pass",
3562
- title: "模板临时文件",
3563
- detail: `${choice.key} 没有检测到会被过滤的临时文件。`
3667
+ title: localize("Temporary template files", "模板临时文件"),
3668
+ detail: localize(`${choice.key} contains no filtered temporary files.`, `${choice.key} 没有检测到会被过滤的临时文件。`)
3564
3669
  });
3565
3670
  }
3566
3671
  return {
@@ -3722,7 +3827,7 @@ async function scheduleOverwrite(intent, options) {
3722
3827
  async function flushPendingOverwrites(pending, options = {}) {
3723
3828
  if (!pending.length) return;
3724
3829
  if (options.noOverwrite) {
3725
- for (const item of pending) logger.info(`skip changed file: ${item.relPath}`);
3830
+ for (const item of pending) logger.info(localize(`Skipped changed file: ${item.relPath}`, `跳过已变更文件:${item.relPath}`));
3726
3831
  return;
3727
3832
  }
3728
3833
  if (options.yes || options.overwrite) {
@@ -3730,11 +3835,11 @@ async function flushPendingOverwrites(pending, options = {}) {
3730
3835
  return;
3731
3836
  }
3732
3837
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
3733
- for (const item of pending) logger.info(`skip changed file in non-interactive mode: ${item.relPath}`);
3838
+ for (const item of pending) logger.info(localize(`Skipped changed file in non-interactive mode: ${item.relPath}`, `非交互模式下跳过已变更文件:${item.relPath}`));
3734
3839
  return;
3735
3840
  }
3736
3841
  const selected = await checkbox({
3737
- message: "检测到以下文件内容与当前仓库不同,选择需要覆盖的文件",
3842
+ message: localize("Select changed managed files to overwrite", "检测到以下文件内容与当前仓库不同,请选择要覆盖的文件"),
3738
3843
  choices: pending.map((item) => ({
3739
3844
  name: pc.greenBright(item.relPath),
3740
3845
  value: item.targetPath,
@@ -3831,6 +3936,38 @@ function setPkgJson(sourcePkgJson, targetPkgJson, options) {
3831
3936
  }
3832
3937
  }
3833
3938
  //#endregion
3939
+ //#region src/commands/upgrade/text/index.ts
3940
+ const crlfPattern = /\r\n/g;
3941
+ function normalizeEol(input) {
3942
+ return input.replace(crlfPattern, "\n");
3943
+ }
3944
+ function normalizeGitignoreLine(line) {
3945
+ const trimmed = line.trim();
3946
+ if (!trimmed) return "";
3947
+ if (trimmed.startsWith("#")) return `#${trimmed.slice(1).trim()}`;
3948
+ return trimmed;
3949
+ }
3950
+ function isTextEquivalent(left, right) {
3951
+ return normalizeEol(left).trimEnd() === normalizeEol(right).trimEnd();
3952
+ }
3953
+ function mergeGitignore(source, target) {
3954
+ const sourceLines = normalizeEol(source).split("\n");
3955
+ const result = normalizeEol(target).split("\n");
3956
+ const seen = new Set(result.map((line) => normalizeGitignoreLine(line)).filter(Boolean));
3957
+ for (const line of sourceLines) {
3958
+ const normalized = normalizeGitignoreLine(line);
3959
+ if (!normalized || seen.has(normalized)) continue;
3960
+ seen.add(normalized);
3961
+ result.push(line);
3962
+ }
3963
+ while (result.length) {
3964
+ const last = result.at(-1);
3965
+ if (last === void 0 || last.trim().length > 0) break;
3966
+ result.pop();
3967
+ }
3968
+ return `${result.join("\n")}\n`;
3969
+ }
3970
+ //#endregion
3834
3971
  //#region src/commands/upgrade/workspace.ts
3835
3972
  function isPlainObject(value) {
3836
3973
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -3887,36 +4024,6 @@ function mergeWorkspaceManifest(source, target) {
3887
4024
  }
3888
4025
  //#endregion
3889
4026
  //#region src/commands/upgrade/index.ts
3890
- const crlfPattern = /\r\n/g;
3891
- function normalizeEol(input) {
3892
- return input.replace(crlfPattern, "\n");
3893
- }
3894
- function normalizeGitignoreLine(line) {
3895
- const trimmed = line.trim();
3896
- if (!trimmed) return "";
3897
- if (trimmed.startsWith("#")) return `#${trimmed.slice(1).trim()}`;
3898
- return trimmed;
3899
- }
3900
- function isTextEquivalent(left, right) {
3901
- return normalizeEol(left).trimEnd() === normalizeEol(right).trimEnd();
3902
- }
3903
- function mergeGitignore(source, target) {
3904
- const sourceLines = normalizeEol(source).split("\n");
3905
- const result = normalizeEol(target).split("\n");
3906
- const seen = new Set(result.map((line) => normalizeGitignoreLine(line)).filter(Boolean));
3907
- for (const line of sourceLines) {
3908
- const normalized = normalizeGitignoreLine(line);
3909
- if (!normalized || seen.has(normalized)) continue;
3910
- seen.add(normalized);
3911
- result.push(line);
3912
- }
3913
- while (result.length) {
3914
- const last = result.at(-1);
3915
- if (last === void 0 || last.trim().length > 0) break;
3916
- result.pop();
3917
- }
3918
- return `${result.join("\n")}\n`;
3919
- }
3920
4027
  /**
3921
4028
  * 将 assets 目录的模版文件同步到工程中,实现一键升级脚手架能力。
3922
4029
  */
@@ -3939,9 +4046,9 @@ async function upgradeMonorepo(opts) {
3939
4046
  const configTargets = upgradeConfig?.targets ?? [];
3940
4047
  const mergeTargets = upgradeConfig?.mergeTargets;
3941
4048
  let targets = configTargets.length ? mergeTargets === false ? [...configTargets] : [.../* @__PURE__ */ new Set([...baseTargets, ...configTargets])] : baseTargets;
3942
- if (merged.interactive) if (!process.stdin.isTTY || !process.stdout.isTTY) logger.info("skip interactive target selection in non-interactive mode");
4049
+ if (merged.interactive) if (!process.stdin.isTTY || !process.stdout.isTTY) logger.info(localize("Skipped interactive target selection in non-interactive mode.", "非交互模式下跳过交互式目标选择。"));
3943
4050
  else targets = await checkbox({
3944
- message: "选择你需要的文件",
4051
+ message: localize("Select the files you need", "选择你需要的文件"),
3945
4052
  choices: targets.map((x) => {
3946
4053
  return {
3947
4054
  value: x,
@@ -3971,7 +4078,7 @@ async function upgradeMonorepo(opts) {
3971
4078
  const targetPath = path.resolve(absOutDir, relPath);
3972
4079
  if (relPath === ".github/workflows/release.yml" && await fs$1.pathExists(targetPath)) {
3973
4080
  if (await classifyReleaseWorkflow(absOutDir) === "custom" && !merged.overwriteRelease) {
3974
- logger.warn("skip custom release workflow; use repo upgrade --overwrite-release to replace it");
4081
+ logger.warn(localize("Skipped custom release workflow; use repo upgrade --overwrite-release to replace it.", "已跳过自定义发布工作流;如需替换,请使用 repo upgrade --overwrite-release。"));
3975
4082
  continue;
3976
4083
  }
3977
4084
  }