#!/usr/bin/env bun // Embeds the canonical `.js` sources as strings, so they import as plain TypeScript (tsc has no text loader). import path from "node:path" import { format, resolveConfig } from "prettier" const src = path.resolve(import.meta.dir, "../src") const names = [ "prelude", "prelude-live", "widget-templates/suggestions", "widget-templates/form", "widget-templates/confirm", "widget-templates/chart", "widget-templates/backdrop", ...[ "pie", "scatter", "histogram", "area", "heatmap", "treemap", "sankey", "graph", "tree", "timeline", "funnel", "radar", "gauge", "boxplot", "flowchart", "sequence", "table", ].map((name) => `widget-templates/${name}`), ] const sources = await Promise.all(names.map((name) => Bun.file(path.join(src, `${name}.js`)).text())) const file = path.join(src, "source.ts") const text = [ "// Generated by script/generate.ts from prelude.js, prelude-live.js and widget-templates/*.js. Do not edit; run `bun run generate`.", "", ...names.map( (name, index) => `export const ${path.basename(name).replace(/-(\w)/g, (_, letter: string) => letter.toUpperCase())} = ${JSON.stringify(sources[index])}`, ), "", ].join("\n") await Bun.write(file, await format(text, { ...(await resolveConfig(file)), filepath: file }))