import { build } from "esbuild"; import tempfile from "tempfile"; import { promises as fs } from "fs"; import { resolve } from "path"; import { colord } from "colord"; import { hex } from "wcag-contrast"; import { formatWithPrettier } from "../utils/prettier.js"; import { Builder } from "./builder.js"; import { exec } from "../utils/exec.js"; import { APP_BACK_ALIVE_SIGNAL } from "../notifier.js"; export const COLORS_TS_PATH = "src/back/colors.ts"; // keeping it in src/back instead of just src to make typescript hints work there export const COLORS_CSS_PATH = "src/colors.css"; export const COLORS_HTML_PATH = "public/dist/colors.html"; export class ColorsBuilder extends Builder { getName(): string { return "colors"; } ownsFile(file_path: string) { return file_path == COLORS_TS_PATH; } async dispose(): Promise {} async _build() { const outfile = tempfile({ extension: "mjs" }); await build({ entryPoints: [COLORS_TS_PATH], bundle: true, format: "esm", outfile, }); await fs.appendFile( outfile, /* HTML */ ``.replaceAll(/<\/?script>/g, "") // `, "html" ); await Promise.all([ fs.writeFile(resolve(this.project_dir, COLORS_CSS_PATH), css), fs.writeFile(resolve(this.project_dir, COLORS_HTML_PATH), html), ]); } }