inject-theme-preload.ts 609 B

123456789101112131415161718
  1. /**
  2. * Injects the theme preload script into index.html.
  3. * Run this as part of the build process.
  4. */
  5. import { generatePreloadScript } from "@opencode-ai/ui/theme"
  6. const htmlPath = new URL("../index.html", import.meta.url).pathname
  7. const html = await Bun.file(htmlPath).text()
  8. const script = generatePreloadScript()
  9. const injectedHtml = html.replace(
  10. /<script id="oc-theme-preload-script">\s*\/\* THEME_PRELOAD_SCRIPT \*\/\s*<\/script>/,
  11. `<script id="oc-theme-preload-script">${script}</script>`,
  12. )
  13. await Bun.write(htmlPath, injectedHtml)
  14. console.log("Injected theme preload script into index.html")