Files
hose-use/scripts/check-version-sync.ts
T
gitea b1e9c7eed3 chore: 统一对外接口规范目录为 hose-open-api
将 specs/openapi 迁移为 specs/hose-open-api,与内部接口规范目录命名对齐。
同步 README、规范打包、版本更新与版本一致性检查,以及发布验证夹具。

验证:929 项测试通过,类型检查和版本检查通过;打包 JSON 字节内容不变。
2026-10-30 14:11:17 +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;
}