import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf-8'));
const outDir = path.join(root, 'src/generated');
mkdirSync(outDir, { recursive: true });
writeFileSync(
  path.join(outDir, 'version.ts'),
  `// Auto-generated by scripts/generate-version.mjs — do not edit\nexport const VERSION = ${JSON.stringify(pkg.version)} as const;\n`,
);
