home / client / scripts / dev.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Dev server: shadow-cljs watch on the :app build, served by :dev-http on BOTH
// 5173 and 4173 (public/ + dist-dev/ merged roots — the relay's origin
// allowlist covers 4173/5173 only; shadow's default 8080 would be refused).
//
// The theme and the two live-data files are build outputs, so they are staged
// into dist-dev/ up front — dev-http serves public/ first and falls through to
// dist-dev/, which is how index.html finds ./theme.css and ./catalog.json.
// (`ardz dev` stages the /id/ bridge under dist-dev/id/ the same way.)
//
// THE WATCH WRITES TO dist-dev/assets, NEVER dist/ (the :output-dir override
// below). This replaces the game1 canon's known wart where 4173 served dist/
// while the watch overwrote dist/assets: dist/ is `ardz build`'s RELEASE tree
// — goog.DEBUG=false, the PRODUCTION relay multiaddr, a service worker — and
// serving it on a dev port handed one tab of a dev drill a production-network
// client (fresh page before the watch's first build, or a browser-cached
// assets/main.js afterwards). Separate trees make the mixture impossible.
// Smoke a release with a standalone static server over dist/, never through
// these ports.
import { spawnSync } from "node:child_process";
import { cpSync, mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { CLIENT as client, appDefines, appVersion, catalogJson } from "./defines.mjs";

// The npm rewrites shadow needs, and their gates (see the script's header).
// Its exit status is CHECKED: patch-npm is what keeps dev and release running
// the same npm sources, and rule 2 in particular is the only place the dev
// pipeline gets the `__esModule` fix that build.mjs applies to a release dist.
// Letting it fail and starting the watcher anyway is how a hub that paints
// over a dead social-layer node reaches a developer with a green build log.
{
  const r = spawnSync(process.execPath, [join(client, "scripts", "patch-npm.mjs")], { cwd: client, stdio: "inherit" });
  if (r.status !== 0) process.exit(r.status ?? 1);
}

const distDev = join(client, "dist-dev");
mkdirSync(distDev, { recursive: true });
cpSync(join(client, "node_modules", "ardegazu-theme", "theme.css"), join(distDev, "theme.css"));
writeFileSync(join(distDev, "version.json"), JSON.stringify({ version: appVersion() }));
writeFileSync(join(distDev, "catalog.json"), catalogJson());

const r = spawnSync(
  join(client, "node_modules", ".bin", "shadow-cljs"),
  [
    "watch",
    "app",
    ...appDefines(),
    "--config-merge",
    // :output-dir — the watch's own tree; see the header. dist/ stays the
    // release build's alone. (a second --config-merge: shadow conj's them
    // and merges in order)
    '{:output-dir "dist-dev/assets"}',
  ],
  {
    cwd: client,
    stdio: "inherit",
  },
);
process.exit(r.status ?? 1);

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