home / client / scripts / defines.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
// The two closure-defines every build of the hub needs, in one place so dev,
// build and test cannot drift apart.
//
//   home.config/APP-VERSION            <- client/version.json (the update banner
//                                         compares it against the live one)
//   home.config/CATALOG-SNAPSHOT-JSON  <- client/catalog.json, MINIFIED
//
// The snapshot rides in as a define STRING rather than a generated source file:
// Vite had resolveJsonModule, shadow does not, and committing a generated copy
// of catalog.json would let the two drift. client/catalog.json stays the single
// source of truth (house rule 8). JSON.stringify's escapes are all valid EDN
// string escapes, so the value survives --config-merge verbatim.
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

export const CLIENT = dirname(dirname(fileURLToPath(import.meta.url)));

export function appVersion() {
  return JSON.parse(readFileSync(join(CLIENT, "version.json"), "utf8")).version;
}

/** The minified catalog — the same bytes scripts/build.mjs writes to dist. */
export function catalogJson() {
  return JSON.stringify(JSON.parse(readFileSync(join(CLIENT, "catalog.json"), "utf8")));
}

/** `--config-merge` args for the :app build (the :bridge build needs none). */
export function appDefines() {
  return [
    "--config-merge",
    `{:closure-defines {home.config/APP-VERSION ${appVersion()}` +
      ` home.config/CATALOG-SNAPSHOT-JSON ${JSON.stringify(catalogJson())}}}`,
  ];
}

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