// Regenerates src/version.ts from package.json's version field.
// Run automatically by the npm `version` lifecycle hook.
// src/version.ts is committed to git (not gitignored) so a fresh clone
// builds without first running this script.
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { join, dirname } from "node:path";

const root = dirname(dirname(fileURLToPath(import.meta.url)));
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf-8"));
const out =
  "// Auto-generated by scripts/sync-version.mjs via the npm `version` lifecycle hook.\n" +
  "// Do not edit by hand — run `npm version <major|minor|patch>` instead.\n" +
  `export const VERSION = "${pkg.version}";\n`;
writeFileSync(join(root, "src/version.ts"), out);
console.error(`synced src/version.ts -> ${pkg.version}`);
