@geml/geml 1.3.2 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +1,64 @@
1
- #!/usr/bin/env node
2
- // geml codemap render — render every codemap document to a sibling .html.
3
- //
4
- // geml codemap render [codemap-dir]
5
- //
6
- // The output folder then works with NO server: open index.html straight from
7
- // disk (file://). Module click-through opens each container page inside the
8
- // graph area (nested frame), so the whole map is browsable offline — this is
9
- // the "copy the folder to someone" mode. For a live view that never goes
10
- // stale, use `geml codemap serve` instead.
11
- import { readdirSync, readFileSync, writeFileSync } from "node:fs";
12
- import { join, basename } from "node:path";
13
- import { parse, renderHtml } from "../dist/geml.js";
14
-
15
- if (process.argv[2] === "--help" || process.argv[2] === "-h") {
16
- console.error("usage: geml codemap render [codemap-dir] (dir defaults to ./.geml-code-graph)");
17
- process.exit(2);
18
- }
19
- const dir = process.argv[2] || ".geml-code-graph";
20
-
21
- // One shared cache for the whole batch: every page's graph slice crosses the
22
- // same neighbour documents, and a fresh parse per page turns N pages into
23
- // O(N x working set) — hours at repo scale. A one-shot process has no
24
- // staleness to worry about, so cache unconditionally (the whole codemap's
25
- // text + parsed docs live in memory for the duration of the run).
26
- const texts = new Map(); // rel -> text | null
27
- const parsed = new Map(); // text -> Document
28
- const loadDoc = (rel) => {
29
- if (!texts.has(rel)) {
30
- try { texts.set(rel, readFileSync(join(dir, rel), "utf8")); } catch { texts.set(rel, null); }
31
- }
32
- return texts.get(rel);
33
- };
34
- const parseDoc = (s) => {
35
- let d = parsed.get(s);
36
- if (!d) { d = parse(s); parsed.set(s, d); }
37
- return d;
38
- };
39
-
40
- let n = 0;
41
- const failed = [];
42
- let files;
43
- try {
44
- files = readdirSync(dir);
45
- } catch {
46
- console.error(`error: cannot read directory ${dir}`);
47
- process.exit(1);
48
- }
49
- for (const f of files) {
50
- if (!f.endsWith(".geml")) continue;
51
- try {
52
- const text = loadDoc(f);
53
- if (text === null) throw new Error("unreadable");
54
- const doc = parseDoc(text);
55
- const html = renderHtml(doc, { source: basename(f), loadDoc, parseDoc });
56
- writeFileSync(join(dir, f.replace(/\.geml$/, ".html")), html);
57
- n++;
58
- } catch (e) {
59
- failed.push(f);
60
- console.error(`render: ${f}: ${e.message}`);
61
- }
62
- }
63
- console.error(`rendered ${n} page(s) -> ${dir}${failed.length ? `; FAILED: ${failed.join(", ")}` : ""}`);
64
- process.exit(failed.length ? 1 : 0);
1
+ #!/usr/bin/env node
2
+ // geml codemap render — render every codemap document to a sibling .html.
3
+ //
4
+ // geml codemap render [codemap-dir]
5
+ //
6
+ // The output folder then works with NO server: open index.html straight from
7
+ // disk (file://). Module click-through opens each container page inside the
8
+ // graph area (nested frame), so the whole map is browsable offline — this is
9
+ // the "copy the folder to someone" mode. For a live view that never goes
10
+ // stale, use `geml codemap serve` instead.
11
+ import { readdirSync, readFileSync, writeFileSync } from "node:fs";
12
+ import { join, basename } from "node:path";
13
+ import { parse, renderHtml } from "../dist/geml.js";
14
+
15
+ if (process.argv[2] === "--help" || process.argv[2] === "-h") {
16
+ console.error("usage: geml codemap render [codemap-dir] (dir defaults to ./.geml-code-graph)");
17
+ process.exit(2);
18
+ }
19
+ const dir = process.argv[2] || ".geml-code-graph";
20
+
21
+ // One shared cache for the whole batch: every page's graph slice crosses the
22
+ // same neighbour documents, and a fresh parse per page turns N pages into
23
+ // O(N x working set) — hours at repo scale. A one-shot process has no
24
+ // staleness to worry about, so cache unconditionally (the whole codemap's
25
+ // text + parsed docs live in memory for the duration of the run).
26
+ const texts = new Map(); // rel -> text | null
27
+ const parsed = new Map(); // text -> Document
28
+ const loadDoc = (rel) => {
29
+ if (!texts.has(rel)) {
30
+ try { texts.set(rel, readFileSync(join(dir, rel), "utf8")); } catch { texts.set(rel, null); }
31
+ }
32
+ return texts.get(rel);
33
+ };
34
+ const parseDoc = (s) => {
35
+ let d = parsed.get(s);
36
+ if (!d) { d = parse(s); parsed.set(s, d); }
37
+ return d;
38
+ };
39
+
40
+ let n = 0;
41
+ const failed = [];
42
+ let files;
43
+ try {
44
+ files = readdirSync(dir);
45
+ } catch {
46
+ console.error(`error: cannot read directory ${dir}`);
47
+ process.exit(1);
48
+ }
49
+ for (const f of files) {
50
+ if (!f.endsWith(".geml")) continue;
51
+ try {
52
+ const text = loadDoc(f);
53
+ if (text === null) throw new Error("unreadable");
54
+ const doc = parseDoc(text);
55
+ const html = renderHtml(doc, { source: basename(f), loadDoc, parseDoc });
56
+ writeFileSync(join(dir, f.replace(/\.geml$/, ".html")), html);
57
+ n++;
58
+ } catch (e) {
59
+ failed.push(f);
60
+ console.error(`render: ${f}: ${e.message}`);
61
+ }
62
+ }
63
+ console.error(`rendered ${n} page(s) -> ${dir}${failed.length ? `; FAILED: ${failed.join(", ")}` : ""}`);
64
+ process.exit(failed.length ? 1 : 0);