#!/usr/bin/env -S node -r esbin
import fs from "fs"
import { resolve } from "path"

const path = resolve(__dirname, "../dist/reference.html")
const html = fs
  .readFileSync(path, "utf8")
  .replace(/<script src="([\w/.]+)"><\/script>/g, (_, $1) => {
    const script = fs.readFileSync(resolve(__dirname, "../dist", $1), "utf8")
    return `<script>${script}</script>`
  })
  .replace(/<link rel="stylesheet" href="([\w/.]+)"\/>/, (_, $1) => {
    const css = fs.readFileSync(resolve(__dirname, "../dist", $1), "utf8")
    return `<style>${css}</style>`
  })

fs.writeFileSync(path.replace(".html", "-bundled.html"), html)
