#!/usr/bin/env node

/**
 * Version generation script
 *
 * Reads package.json and generates cli/version.ts with the version information.
 * This ensures the version is available for both development and bundled builds.
 */

import { readFileSync, writeFileSync } from "node:fs";
import process from "node:process";

try {
  // Read version from package.json
  const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
  const version = packageJson.version;

  // Generate version.ts content
  const versionFileContent = `// Auto-generated file - do not edit manually
// This file is generated by scripts/generate-version.js
export const VERSION = "${version}";
`;

  // Write version.ts file
  writeFileSync("cli/version.ts", versionFileContent);

  console.log(`✅ Generated cli/version.ts with version: ${version}`);
} catch (error) {
  console.error("❌ Failed to generate version.ts:", error.message);
  process.exit(1);
}
