1// Bundles signer-entry.js, beside this file, into src/gen/signer.ts, a string the relay2// serves at /signer.js. `--check` rebuilds in memory and fails when the3// committed file is stale, so typecheck catches a forgotten rebuild.4import { buildSync } from "esbuild";5import { createHash } from "node:crypto";6import { readFileSync, writeFileSync } from "node:fs";78const OUT = new URL("../../src/gen/signer.ts", import.meta.url);9const result = buildSync({10 entryPoints: [new URL("./signer-entry.js", import.meta.url).pathname],11 bundle: true,12 minify: true,13 format: "iife",14 platform: "browser",15 target: "es2020",16 write: false,17 legalComments: "none",18 logLevel: "silent",19});20const js = result.outputFiles[0].text;21const hash = createHash("sha256").update(js).digest("hex").slice(0, 12);22const file = `// Generated by scripts/build/build-signer.mjs from scripts/build/signer-entry.js. Do not edit; run npm run build:signer.23export const SIGNER_HASH = ${JSON.stringify(hash)};24export const SIGNER_JS = ${JSON.stringify(js)};25`;26if (process.argv.includes("--check")) {27 let cur = "";28 try {29 cur = readFileSync(OUT, "utf8");30 } catch {31 /* missing */32 }33 if (cur !== file) {34 console.error("src/gen/signer.ts is stale: run npm run build:signer");35 process.exit(1);36 }37} else {38 writeFileSync(OUT, file);39 console.log(`src/gen/signer.ts: ${(js.length / 1024).toFixed(0)} KB, ${hash}`);40}