// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved.

import { readFileSync, writeFileSync } from "fs";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const root = resolve(__dirname, "..");
const changelogPath = resolve(root, "CHANGELOG.md");
const outPath = resolve(root, "src/lib/changelog.generated.ts");
const pkg = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8"));

const md = readFileSync(changelogPath, "utf8");
const escaped = JSON.stringify(md);

writeFileSync(
  outPath,
  `// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved.\n` +
    `// Generated by scripts/build-changelog.ts — do not edit.\n\n` +
    `export const CHANGELOG_MD = ${escaped};\n` +
    `export const PACKAGE_NAME = ${JSON.stringify(pkg.name)};\n` +
    `export const PACKAGE_VERSION = ${JSON.stringify(pkg.version)};\n`,
);

console.log(`Wrote ${outPath} (${md.length} chars).`);
