#!/usr/bin/env node
// Regenerate src/version.ts from package.json so the exported VERSION
// constant cannot drift from the published package version.
//
// Invoked by package.json scripts before tasks that need src/version.ts
// to match package.json.

import { readFileSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const here = dirname(fileURLToPath(import.meta.url));
const pkgPath = join(here, "..", "package.json");
const outPath = join(here, "..", "src", "version.ts");

const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));

const contents = `// AUTO-GENERATED by scripts/sync-version.mjs — do not edit by hand.
// Sourced from package.json so VERSION cannot drift from the published version.
export const VERSION = "${pkg.version}";
`;

writeFileSync(outPath, contents);
