mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 14:27:26 +00:00
Both sync-schemas.ts and packages/codex-plugin/build.mts were hand-rolling
the same "compare source to target, print drift, exit 1 in --check mode"
pattern with slightly different output shapes. Extract:
- walkFiles(root, filter?) — recursive relative-path lister shared with
the codex-plugin drift checker
- reportAndExit(drifted, { checkMode, label, fixCommand }) — prints a
unified ✓/✗ summary, caps drift list, exits non-zero in check mode
Both callers now produce the same output shape so contributors see the
same UI whether they're syncing schemas or the codex plugin:
✗ <label> is out of sync:
changed <path>
missing <path>
extra <path>
Run `<fix command>` and commit the result.
Verified: lint, format:check, sync-schemas:check, check:codex-plugin all
pass. Drift injection tests pass on both sync paths. Pre-commit hook still
auto-rebuilds the plugin skills/ copy on source changes and correctly
skips when only the plugin copy is edited (no clobber cycle).
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
#!/usr/bin/env tsx
|
|
/**
|
|
* Mirror JSON Schemas from `packages/core/schemas/` into `docs/schema/` so
|
|
* Mintlify serves them at `https://hyperframes.heygen.com/schema/*`. The core
|
|
* copies stay authoritative — they're exported from `@hyperframes/core` for
|
|
* npm consumers — and this script is the single contract that prevents the
|
|
* docs mirror from drifting.
|
|
*
|
|
* Usage:
|
|
* bun run sync-schemas # copy core → docs
|
|
* bun run sync-schemas --check # exit non-zero if copies are stale (CI)
|
|
*
|
|
* `docs/schema/hyperframes.json` is authored directly in docs (no source in
|
|
* core) so it's skipped by this script.
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
import type { DriftEntry } from "./lib/sync.ts";
|
|
import { reportAndExit } from "./lib/sync.ts";
|
|
|
|
const ROOT = join(import.meta.dirname, "..");
|
|
const SOURCE_DIR = join(ROOT, "packages/core/schemas");
|
|
const TARGET_DIR = join(ROOT, "docs/schema");
|
|
const MIRRORED = ["registry.json", "registry-item.json"];
|
|
|
|
function main() {
|
|
const checkMode = process.argv.includes("--check");
|
|
const drifted: DriftEntry[] = [];
|
|
|
|
for (const name of MIRRORED) {
|
|
const source = readFileSync(join(SOURCE_DIR, name), "utf-8");
|
|
const targetPath = join(TARGET_DIR, name);
|
|
const target = (() => {
|
|
try {
|
|
return readFileSync(targetPath, "utf-8");
|
|
} catch {
|
|
return null;
|
|
}
|
|
})();
|
|
|
|
if (target === source) continue;
|
|
|
|
drifted.push({ kind: target === null ? "missing" : "changed", path: name });
|
|
if (!checkMode) {
|
|
writeFileSync(targetPath, source);
|
|
}
|
|
}
|
|
|
|
reportAndExit(drifted, {
|
|
checkMode,
|
|
label: "docs/schema/",
|
|
fixCommand: "bun run sync-schemas",
|
|
});
|
|
}
|
|
|
|
main();
|