#!/usr/bin/env node
// This script generates index.js from index.d.ts by converting TypeScript exports
// It adds .ts extensions to import paths since we're directly using TypeScript files with tsx

import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const rootDir = path.join(__dirname, "..")

// Read the TypeScript declaration file
const dtsPath = path.join(rootDir, "index.d.ts")
const dtsContent = fs.readFileSync(dtsPath, "utf8")

// Convert TypeScript declarations to JavaScript exports (adding .ts to imports)
const jsContent = dtsContent
  // Add TS file extension to relative imports
  .replace(/from\s+['"](\.\/.+?)['"];/g, (match, importPath) => {
    return `from "${importPath}.ts";`
  })
  // Handle comment lines
  .replace(/\/\/.*$/gm, (match) => match)

// Write the generated index.js file
const jsPath = path.join(rootDir, "index.js")

fs.writeFileSync(jsPath, jsContent)

console.log("Successfully generated index.js from index.d.ts")
