| 1 | import { build } from "esbuild" ; |
| 2 | import { readFile, mkdtemp, rm } from "node:fs/promises" ; |
| 3 | import { tmpdir } from "node:os" ; |
| 4 | import { join } from "node:path" ; |
| 5 | import { signerBundle, nostrNameBundle } from "./bundle-config.mjs" ; |
| 6 | |
| 7 | const root = new URL(".." , import.meta.url); |
| 8 | const temporaryDirectory = await mkdtemp(join(tmpdir(), "tinyrelay-bundles-" )); |
| 9 | const bundles = [ |
| 10 | ["signer" , signerBundle(join(temporaryDirectory, "signer.js" )), "tinyclient/signer.js" ], |
| 11 | ["nostr-name" , nostrNameBundle(join(temporaryDirectory, "nostr-name.js" )), "tinyclient/nostr-name.js" ], |
| 12 | ]; |
| 13 | |
| 14 | try { |
| 15 | for (const [name, config, checkedInPath] of bundles) { |
| 16 | await build(config); |
| 17 | const [built, checkedIn] = await Promise.all([ |
| 18 | readFile(config.outfile), |
| 19 | readFile(new URL(checkedInPath, root)), |
| 20 | ]); |
| 21 | if (!built.equals(checkedIn)) { |
| 22 | throw new Error(`${checkedInPath} is stale; run npm run build:${name}` ); |
| 23 | } |
| 24 | } |
| 25 | console.log(`verified ${bundles.length} generated browser bundles` ); |
| 26 | } finally { |
| 27 | await rm(temporaryDirectory, { recursive: true, force: true }); |
| 28 | } |