// Assembles sux.user.js: metadata block + the extension's ../shared.js (reused // verbatim, scoped so it doesn't leak a global) + src/main.js with the panel // markup and styles inlined. // // node userscript/build.mjs write sux.user.js // node userscript/build.mjs --check exit 1 if sux.user.js is stale import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; const here = dirname(fileURLToPath(import.meta.url)); const read = (p) => readFileSync(join(here, p), "utf8"); const indent = (s) => s.replace(/^(?=.)/gm, " "); export function build() { const main = read("src/main.js") .replace("__SUX_PANEL_CSS__", () => JSON.stringify(read("src/panel.css"))) .replace("__SUX_PANEL_HTML__", () => JSON.stringify(read("src/panel.html"))); return [ read("src/meta.txt"), "// Generated by userscript/build.mjs — edit userscript/src/ and ../shared.js, not this file.", "(function () {", ' "use strict";', "", " var SuxShared = (function (globalThis) {", indent(indent(read("../shared.js").trimEnd())), " return globalThis.SuxShared;", " })({});", "", indent(main.trimEnd()), "})();", "", ].join("\n"); } if (process.argv[1] === fileURLToPath(import.meta.url)) { const out = join(here, "sux.user.js"); const next = build(); if (process.argv.includes("--check")) { let current = ""; try { current = readFileSync(out, "utf8"); } catch { /* missing */ } if (current !== next) { console.error("sux.user.js is stale — run: node userscript/build.mjs"); process.exit(1); } } else { writeFileSync(out, next); console.log("wrote " + out); } }