/** * Emit the single browser artifact `client.js` from `src/panel.js` and * `src/qrcode.js`. * * A bundle's client half is served as one self-contained module; it cannot * import a sibling file or a package dependency at runtime. This script inlines * both sources into the `window.__ModuleLoader__.load` shell, which is the same * shape the reference plugins ship. * * Run: `node scripts/build-client.mjs` */ import { readFileSync, writeFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' const here = dirname(fileURLToPath(import.meta.url)) const root = join(here, '..') /** Read a source file and turn its ESM exports into plain declarations. */ function inline(relativePath) { const source = readFileSync(join(root, relativePath), 'utf8') return source .replace(/^import .*$/gm, '') .replace(/^export (?=(?:function|const|let|class)\b)/gm, '') .trim() } const qrcode = inline('src/qrcode.js') const panel = inline('src/panel.js') const artifact = `/** * @sutong/dsh-lan-access — browser half (generated by scripts/build-client.mjs). * * Do not edit this file: change src/panel.js or src/qrcode.js and rebuild. */ window.__ModuleLoader__.load({ id: "@sutong/dsh-lan-access", factory: function (require) { "use strict"; var React = require("react"); // ── inlined src/qrcode.js ──────────────────────────────────────────────── var __qrcode = (function () { ${qrcode.replace(/^/gm, ' ')} return { encodeQR: encodeQR, MAX_VERSION: MAX_VERSION }; })(); var encodeQR = __qrcode.encodeQR; // ── inlined src/panel.js ───────────────────────────────────────────────── ${panel.replace(/^/gm, ' ')} return { inject: inject, apply: apply }; }, }); ` const out = join(root, 'client.js') writeFileSync(out, artifact) console.log(`wrote ${out} (${artifact.length} bytes)`)