Files
hose-use/scripts/release/check-version-sync.ts
T
gitea c71b20c25b chore: 按用途整理工程脚本与验证入口
将内部脚本归入 build、release、generate、dev 和 checks,保留公开安装脚本路径。
同步命令、CI、发布流程、脚本间调用及根目录定位,补齐脚本说明与完成报告。

验证:929 项测试、类型与版本检查通过;二进制及插件构建、冒烟与打包通过。
OpenAPI 产物不变;工作流 Schema 导出存在基线即可复现的 Zod transform 错误,单独记录。
2026-10-30 14:15:32 +08:00

33 lines
1.4 KiB
TypeScript

#!/usr/bin/env bun
import { readFileSync, existsSync } from "node:fs";
import { join } from "node:path";
const root = join(import.meta.dirname, "../..");
const packageVersion = (JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as { version: string }).version;
const expected: Array<[string, string | undefined]> = [
["package.json", packageVersion],
[".zcode-plugin/plugin.json", readJsonVersion(".zcode-plugin/plugin.json")],
["specs/hose-open-api/openapi.yaml", readFileSync(join(root, "specs/hose-open-api/openapi.yaml"), "utf8").match(/^\s+version:\s+([^\s]+)\s*$/m)?.[1]],
["specs/openapi.json", readJsonVersion("specs/openapi.json", ["info", "version"])],
];
const mismatches = expected.filter(([, value]) => value !== packageVersion);
if (mismatches.length) {
console.error(`Version drift detected; expected ${packageVersion}:`);
for (const [file, value] of mismatches) console.error(` ${file}: ${value ?? "missing"}`);
process.exit(1);
}
console.log(`Version synchronized: ${packageVersion}`);
function readJsonVersion(file: string, path: string[] = ["version"]): string | undefined {
const fullPath = join(root, file);
if (!existsSync(fullPath)) return undefined;
let value: unknown = JSON.parse(readFileSync(fullPath, "utf8"));
for (const key of path) {
if (!value || typeof value !== "object") return undefined;
value = (value as Record<string, unknown>)[key];
}
return typeof value === "string" ? value : undefined;
}