clone

nostr relays on demand at <name>.bind.ws: claim one with your key, pay in zaps past the free allowance

dependabot/npm_and_yarn/npm-f01a459b0f
bindws / scripts / build / build-connections.mjs
build-connections.mjs 1.7K
1// Folds connection-templates/*.jsonc into src/gen/connections.ts, the app2// shortcut library the relay offers, in file order. `--check` rebuilds in3// memory and fails when the committed file is stale, so typecheck catches a4// forgotten rebuild.5import { readdirSync, readFileSync, writeFileSync } from "node:fs";6import { stripComments } from "../check/jsonc.mjs";78const DIR = new URL("../../connection-templates/", import.meta.url);9const OUT = new URL("../../src/gen/connections.ts", import.meta.url);10const files = readdirSync(DIR).filter((f) => f.endsWith(".jsonc")).sort();11// The folder's README is the catalog: every template has a row there.12const readme = readFileSync(new URL("README.md", DIR), "utf8");13const missing = files.filter((f) => !readme.includes(`](${f})`));14if (missing.length) {15 console.error(`connection-templates/README.md has no row for: ${missing.join(", ")}`);16 process.exit(1);17}18const templates = files.map((f) => {19 const doc = JSON.parse(stripComments(readFileSync(new URL(f, DIR), "utf8")));20 delete doc.$schema;21 return { name: f.replace(/^\d+-/, "").replace(/\.jsonc$/, ""), document: doc };22});23const file = `// Generated by scripts/build/build-connections.mjs from connection-templates/. Do not edit; run npm run build:connections.24export const CONNECTION_LIBRARY: { name: string; document: unknown }[] = ${JSON.stringify(templates, null, 2)};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/connections.ts is stale: run npm run build:connections");35 process.exit(1);36 }37} else {38 writeFileSync(OUT, file);39 console.log(`src/gen/connections.ts: ${templates.length} connection templates`);40}