@diagc/cli 1.1.4 → 1.1.6

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,3 +1,4 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
3
  import path from 'node:path';
3
4
  import { errMessage, isDrawings } from '@diagc/core/internal';
@@ -5,6 +6,16 @@ import { classifyAssetRef, rewriteAssetRefs, safeAssetPath } from './assets.js';
5
6
  import { buildGallery } from './gallery.js';
6
7
  import { discoverDiagrams } from './discover.js';
7
8
  import { stampHtml } from './html.js';
9
+ /** The model's display name from its artifact, for a diagram this run did not read. */
10
+ async function titleOf(modelPath) {
11
+ try {
12
+ const name = JSON.parse(await readFile(modelPath, 'utf8')).name;
13
+ return typeof name === 'string' ? name : undefined;
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
8
19
  async function readMaybe(p) {
9
20
  try {
10
21
  return await readFile(p);
@@ -54,16 +65,17 @@ export async function publishDiagrams(opts) {
54
65
  if (opts.images)
55
66
  await mkdir(opts.staticDir, { recursive: true });
56
67
  const cache = new Map();
57
- let all = await discoverDiagrams(opts.artifactsDir, opts.srcDir);
68
+ const all = await discoverDiagrams(opts.artifactsDir, opts.srcDir);
69
+ let chosen = all;
58
70
  if (opts.names !== undefined && opts.names.length > 0) {
59
71
  const want = new Set(opts.names);
60
- all = all.filter((d) => want.has(d.name));
72
+ chosen = all.filter((d) => want.has(d.name));
61
73
  }
62
74
  const pages = [];
63
75
  const images = [];
64
76
  // diagram name → the model's display name, for the index cards
65
77
  const titles = new Map();
66
- for (const d of all) {
78
+ for (const d of chosen) {
67
79
  try {
68
80
  const modelRaw = JSON.parse(await readFile(d.modelPath, 'utf8'));
69
81
  titles.set(d.name, modelRaw.name);
@@ -98,16 +110,29 @@ export async function publishDiagrams(opts) {
98
110
  continue;
99
111
  }
100
112
  }
101
- // Only diagrams whose page was actually written belong in the gallery — a
102
- // source that failed before its HTML wrote would otherwise get a dead link.
113
+ // A diagram this run published gets a card for the page it wrote now and a thumbnail
114
+ // for the image it rendered now: what an earlier run left must not stand in for it
115
+ // (the Pages workflow counts thumbnails to catch a run with no usable Chrome), and a
116
+ // diagram that failed gets no card. A run scoped by name leaves the other pages in
117
+ // place, so the index keeps those diagrams as they are on disk. A page whose diagram
118
+ // is not discovered (its artifact is gone) gets no card.
103
119
  const written = new Set(pages);
120
+ const rendered = new Set(images);
121
+ const inRun = new Set(chosen.map((d) => d.name));
122
+ const entries = [];
123
+ for (const d of all) {
124
+ const pagePath = path.join(opts.htmlDir, `${d.name}.html`);
125
+ const pngPath = path.join(opts.staticDir, `${d.name}.png`);
126
+ const thisRun = inRun.has(d.name);
127
+ if (!(thisRun ? written.has(pagePath) : existsSync(pagePath)))
128
+ continue;
129
+ entries.push({
130
+ name: d.name,
131
+ title: titles.get(d.name) ?? (await titleOf(d.modelPath)) ?? d.name,
132
+ hasImage: thisRun ? rendered.has(pngPath) : existsSync(pngPath),
133
+ });
134
+ }
104
135
  const galleryPath = path.join(opts.htmlDir, 'index.html');
105
- await writeFile(galleryPath, buildGallery(all
106
- .filter((d) => written.has(path.join(opts.htmlDir, `${d.name}.html`)))
107
- .map((d) => ({
108
- name: d.name,
109
- title: titles.get(d.name) ?? d.name,
110
- hasImage: images.includes(path.join(opts.staticDir, `${d.name}.png`)),
111
- })), opts.link !== undefined ? { link: opts.link } : {}));
136
+ await writeFile(galleryPath, buildGallery(entries, opts.link !== undefined ? { link: opts.link } : {}));
112
137
  return { pages, images, gallery: galleryPath };
113
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagc/cli",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Bogdan Frankovskyi",
@@ -44,7 +44,7 @@
44
44
  "fast-glob": "^3.3.0",
45
45
  "jiti": "^2.0.0",
46
46
  "playwright-core": "^1.62.0",
47
- "@diagc/core": "1.1.4"
47
+ "@diagc/core": "1.1.6"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"