dev / templates / bot / scripts / build.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Build the committed dist/: four isolated shadow-cljs release builds (one per
// process entry — the two-stack law is enforced by build structure), assembled
// onto the fixed artifact paths systemd/install-fleet.sh expect:
//   dist/main.js  dist/worker.js  dist/rl/train.js  dist/fleet/link.js
// Then normalize the JVM-global gensym numbering so the dist is
// byte-deterministic (deploy/check-dist.sh rebuilds and diffs).
import { execFileSync } from "node:child_process";
import { rmSync, mkdirSync, copyFileSync } from "node:fs";
import { dirname, join } from "node:path";

const ROOT = join(dirname(new URL(import.meta.url).pathname), "..");
const run = (cmd, args) => execFileSync(cmd, args, { cwd: ROOT, stdio: "inherit" });

// ALWAYS a cold build: the JVM-global gensym counter numbers more than the
// normalizer's dyn vars can renumber, and a warm .shadow-cljs cache numbers
// them differently from the clean rebuild check-dist diffs against.
// Cold-to-cold is deterministic; warm-to-cold is not.
rmSync(join(ROOT, ".shadow-cljs"), { recursive: true, force: true });
rmSync(join(ROOT, "dist"), { recursive: true, force: true });
for (const b of ["esm-main", "esm-worker", "esm-train", "esm-link"]) {
  rmSync(join(ROOT, "target", b), { recursive: true, force: true });
}

// one JVM, four disjoint module graphs
run("npx", ["shadow-cljs", "release", "main", "worker", "train", "link"]);

const out = {
  "target/esm-main/main.js": "dist/main.js",
  "target/esm-worker/worker.js": "dist/worker.js",
  "target/esm-train/train.js": "dist/rl/train.js",
  "target/esm-link/link.js": "dist/fleet/link.js",
};
for (const [src, dst] of Object.entries(out)) {
  mkdirSync(join(ROOT, dirname(dst)), { recursive: true });
  copyFileSync(join(ROOT, src), join(ROOT, dst));
}
// canon hygiene: only the four .js files are copied, but keep the guard
rmSync(join(ROOT, "dist", "manifest.edn"), { force: true });

run("node", ["scripts/normalize-gensyms.mjs"]);
console.log("build: dist/ assembled (main, worker, rl/train, fleet/link)");

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/dev.git