@diagc/cli 0.14.1 → 1.0.0
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.
- package/assets/studio/assets/index-Caq_0xOc.js +109 -0
- package/assets/studio/index.html +1 -1
- package/assets/viewer/index.html +4 -4
- package/dist/api/dispatch.js +9 -3
- package/dist/api/handlers.d.ts +1 -1
- package/dist/api/handlers.js +26 -8
- package/dist/api/routes.js +51 -11
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +38 -17
- package/dist/compile.d.ts +1 -1
- package/dist/compile.js +1 -1
- package/dist/diff.d.ts +1 -1
- package/dist/diff.js +27 -6
- package/dist/eject.d.ts +1 -1
- package/dist/eject.js +1 -1
- package/dist/git-ref.js +4 -1
- package/dist/guide.js +1 -1
- package/dist/includes.d.ts +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.js +10 -5
- package/dist/lint.js +4 -2
- package/dist/publish/assets.d.ts +1 -1
- package/dist/publish/assets.js +6 -1
- package/dist/publish/discover.js +5 -1
- package/dist/publish/gallery.js +1 -3
- package/dist/publish/html.d.ts +1 -1
- package/dist/publish/html.js +1 -1
- package/dist/publish/publish.d.ts +1 -1
- package/dist/publish/publish.js +6 -6
- package/dist/publish/snapshot.js +16 -5
- package/dist/serve.js +5 -2
- package/dist/snapshots.d.ts +1 -1
- package/dist/snapshots.js +1 -1
- package/dist/watch.d.ts +1 -1
- package/dist/watch.js +1 -1
- package/package.json +2 -2
- package/assets/studio/assets/index-BTb7M_Is.js +0 -109
package/dist/api/dispatch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isIP } from 'node:net';
|
|
2
|
-
import { errMessage } from '@diagc/core';
|
|
2
|
+
import { errMessage } from '@diagc/core/internal';
|
|
3
3
|
import { matchRoute } from './routes.js';
|
|
4
4
|
async function readBody(req) {
|
|
5
5
|
const chunks = [];
|
|
@@ -79,7 +79,10 @@ function refusal(req, route) {
|
|
|
79
79
|
if (host !== undefined) {
|
|
80
80
|
const name = hostnameOf(host);
|
|
81
81
|
if (name !== 'localhost' && !name.endsWith('.localhost') && isIP(name) === 0) {
|
|
82
|
-
return {
|
|
82
|
+
return {
|
|
83
|
+
status: 403,
|
|
84
|
+
message: `Refused: '${name}' is not a local address. Open the studio by localhost or by IP address.`,
|
|
85
|
+
};
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
const origin = req.headers.origin;
|
|
@@ -95,7 +98,10 @@ function refusal(req, route) {
|
|
|
95
98
|
return { status: 403, message: 'Refused: the request comes from another origin.' };
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
|
-
if (route.bodyMode === 'json' &&
|
|
101
|
+
if (route.bodyMode === 'json' &&
|
|
102
|
+
!String(req.headers['content-type'] ?? '')
|
|
103
|
+
.toLowerCase()
|
|
104
|
+
.startsWith('application/json')) {
|
|
99
105
|
return { status: 415, message: 'This route takes application/json.' };
|
|
100
106
|
}
|
|
101
107
|
return null;
|
package/dist/api/handlers.d.ts
CHANGED
package/dist/api/handlers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { access, mkdir, readFile, readdir, rename, unlink } from 'node:fs/promises';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { IMAGE_REF, composeIncludes, errMessage, isDrawings, isLayoutOverlay, validate } from '@diagc/core';
|
|
4
|
+
import { IMAGE_REF, composeIncludes, errMessage, isDrawings, isLayoutOverlay, validate, } from '@diagc/core/internal';
|
|
5
5
|
import { writeFileAtomic } from '../atomic-write.js';
|
|
6
6
|
import { EjectError, ejectDiagram } from '../eject.js';
|
|
7
7
|
import { resolveInclude } from '../includes.js';
|
|
@@ -67,8 +67,8 @@ export async function listDiagramModels(diagramsDir, artifactsDir) {
|
|
|
67
67
|
if (editable && hasIncludes(model)) {
|
|
68
68
|
try {
|
|
69
69
|
const { model: composed, warnings } = await composeIncludes(model, path.resolve(file), lockedResolver(diagramsDir));
|
|
70
|
-
// compileFile refuses an invalid composed result outright
|
|
71
|
-
//
|
|
70
|
+
// compileFile refuses an invalid composed result outright, because the
|
|
71
|
+
// renderer assumes a validated model — an id collision
|
|
72
72
|
// between an umbrella-declared node and a namespaced include can pass
|
|
73
73
|
// composeIncludes (which only grafts) while still being invalid, so
|
|
74
74
|
// this must be checked here too, not just on compile.
|
|
@@ -355,7 +355,10 @@ export async function saveLibrary(diagramsDir, payload) {
|
|
|
355
355
|
return { status: 400, body: { issues: [{ message: 'Entry needs string id, name, category' }] } };
|
|
356
356
|
}
|
|
357
357
|
if (!catIds.has(entry.category)) {
|
|
358
|
-
return {
|
|
358
|
+
return {
|
|
359
|
+
status: 400,
|
|
360
|
+
body: { issues: [{ message: `Entry '${entry.id}' references unknown category '${entry.category}'` }] },
|
|
361
|
+
};
|
|
359
362
|
}
|
|
360
363
|
if (entryIds.has(entry.id))
|
|
361
364
|
return { status: 400, body: { issues: [{ message: `Duplicate entry '${entry.id}'` }] } };
|
|
@@ -365,9 +368,16 @@ export async function saveLibrary(diagramsDir, payload) {
|
|
|
365
368
|
return { status: 400, body: { issues: [{ message: `Entry '${entry.id}' missing template` }] } };
|
|
366
369
|
}
|
|
367
370
|
for (const [k, v] of Object.entries(t)) {
|
|
368
|
-
const ok = TEMPLATE_STRING_KEYS.has(k)
|
|
371
|
+
const ok = TEMPLATE_STRING_KEYS.has(k)
|
|
372
|
+
? typeof v === 'string'
|
|
373
|
+
: TEMPLATE_NUMBER_KEYS.has(k)
|
|
374
|
+
? typeof v === 'number'
|
|
375
|
+
: false;
|
|
369
376
|
if (!ok)
|
|
370
|
-
return {
|
|
377
|
+
return {
|
|
378
|
+
status: 400,
|
|
379
|
+
body: { issues: [{ message: `Entry '${entry.id}' has invalid template field '${k}'` }] },
|
|
380
|
+
};
|
|
371
381
|
}
|
|
372
382
|
}
|
|
373
383
|
const target = path.join(diagramsDir, 'library.json');
|
|
@@ -393,7 +403,10 @@ export async function saveAsset(diagramsDir, contentType, bytes) {
|
|
|
393
403
|
return { status: 400, body: { issues: [{ message: `Unsupported image type '${contentType}'` }] } };
|
|
394
404
|
}
|
|
395
405
|
if (bytes.length === 0 || bytes.length > MAX_ASSET_BYTES) {
|
|
396
|
-
return {
|
|
406
|
+
return {
|
|
407
|
+
status: 400,
|
|
408
|
+
body: { issues: [{ message: `Image must be 1 byte to ${MAX_ASSET_BYTES / 1024 / 1024} MB` }] },
|
|
409
|
+
};
|
|
397
410
|
}
|
|
398
411
|
const name = `${createHash('sha256').update(bytes).digest('hex').slice(0, 12)}.${ext}`;
|
|
399
412
|
const target = path.join(diagramsDir, 'assets', name);
|
|
@@ -412,7 +425,12 @@ export async function readAsset(diagramsDir, name) {
|
|
|
412
425
|
try {
|
|
413
426
|
const bytes = await readFile(path.join(diagramsDir, 'assets', name));
|
|
414
427
|
const ext = name.split('.').at(-1) ?? '';
|
|
415
|
-
return {
|
|
428
|
+
return {
|
|
429
|
+
status: 200,
|
|
430
|
+
body: null,
|
|
431
|
+
bytes,
|
|
432
|
+
contentType: ASSET_TYPE[ext === 'jpeg' ? 'jpg' : ext] ?? 'application/octet-stream',
|
|
433
|
+
};
|
|
416
434
|
}
|
|
417
435
|
catch {
|
|
418
436
|
return { status: 404, body: { issues: [{ message: `No asset '${name}'` }] } };
|
package/dist/api/routes.js
CHANGED
|
@@ -2,31 +2,70 @@
|
|
|
2
2
|
// IS the dispatch order (the rename entry must precede the generic save entry).
|
|
3
3
|
export const ROUTES = [
|
|
4
4
|
// --- assets: raw body in, raw bytes out ---
|
|
5
|
-
{
|
|
6
|
-
|
|
5
|
+
{
|
|
6
|
+
method: 'POST',
|
|
7
|
+
pattern: /^\/api\/assets$/,
|
|
8
|
+
bodyMode: 'raw',
|
|
9
|
+
handler: (h, c) => h.saveAsset(c.diagramsDir, c.contentType ?? '', c.body),
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
method: 'GET',
|
|
13
|
+
pattern: /^\/api\/assets\/([^/]+)$/,
|
|
14
|
+
handler: (h, c) => h.readAsset(c.diagramsDir, decodeURIComponent(c.match[1] ?? '')),
|
|
15
|
+
},
|
|
7
16
|
// --- library ---
|
|
8
17
|
{ method: 'GET', pattern: /^\/api\/library$/, handler: (h, c) => h.readLibrary(c.diagramsDir) },
|
|
9
|
-
{
|
|
18
|
+
{
|
|
19
|
+
method: 'PUT',
|
|
20
|
+
pattern: /^\/api\/library$/,
|
|
21
|
+
bodyMode: 'json',
|
|
22
|
+
handler: (h, c) => h.saveLibrary(c.diagramsDir, c.body),
|
|
23
|
+
},
|
|
10
24
|
// --- diagrams & layouts ---
|
|
11
|
-
{
|
|
25
|
+
{
|
|
26
|
+
method: 'GET',
|
|
27
|
+
pattern: /^\/api\/diagrams$/,
|
|
28
|
+
handler: (h, c) => h.listDiagramModels(c.diagramsDir, c.artifactsDir),
|
|
29
|
+
},
|
|
12
30
|
{ method: 'GET', pattern: /^\/api\/layouts$/, handler: (h, c) => h.listLayouts(c.diagramsDir) },
|
|
13
31
|
{ method: 'GET', pattern: /^\/api\/drawings$/, handler: (h, c) => h.listDrawings(c.diagramsDir) },
|
|
14
32
|
// Composed read must precede the generic read, whose `(.+)` would swallow
|
|
15
33
|
// `<name>/composed` as a filename.
|
|
16
|
-
{
|
|
17
|
-
|
|
34
|
+
{
|
|
35
|
+
method: 'GET',
|
|
36
|
+
pattern: /^\/api\/diagrams\/(.+)\/composed$/,
|
|
37
|
+
handler: (h, c) => h.readComposedDiagram(c.diagramsDir, decodeURIComponent(c.match[1] ?? '')),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
method: 'GET',
|
|
41
|
+
pattern: /^\/api\/diagrams\/(.+)$/,
|
|
42
|
+
handler: (h, c) => h.readDiagram(c.diagramsDir, decodeURIComponent(c.match[1] ?? '')),
|
|
43
|
+
},
|
|
18
44
|
// Rename must be checked before the generic save route, whose `(.+)`
|
|
19
45
|
// would otherwise swallow `<from>/rename` as a filename.
|
|
20
|
-
{
|
|
46
|
+
{
|
|
47
|
+
method: 'POST',
|
|
48
|
+
pattern: /^\/api\/diagrams\/(.+)\/rename$/,
|
|
49
|
+
bodyMode: 'json',
|
|
50
|
+
handler: async (h, c) => {
|
|
21
51
|
const to = c.body?.to;
|
|
22
52
|
if (typeof to !== 'string')
|
|
23
53
|
return { status: 400, body: { issues: [{ message: "Missing 'to' name" }] } };
|
|
24
54
|
return h.renameDiagram(c.diagramsDir, decodeURIComponent(c.match[1] ?? ''), to);
|
|
25
|
-
}
|
|
55
|
+
},
|
|
56
|
+
},
|
|
26
57
|
// Eject must also precede the generic save route, whose `(.+)` would
|
|
27
58
|
// swallow `<name>/eject` as a filename.
|
|
28
|
-
{
|
|
29
|
-
|
|
59
|
+
{
|
|
60
|
+
method: 'POST',
|
|
61
|
+
pattern: /^\/api\/diagrams\/(.+)\/eject$/,
|
|
62
|
+
handler: (h, c) => h.ejectDiagramSource(c.diagramsDir, c.artifactsDir, decodeURIComponent(c.match[1] ?? '')),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
method: 'POST',
|
|
66
|
+
pattern: /^\/api\/(diagrams|layouts|drawings)\/(.+)$/,
|
|
67
|
+
bodyMode: 'json',
|
|
68
|
+
handler: (h, c) => {
|
|
30
69
|
// decodeURIComponent throws on malformed percent-encoding — kept
|
|
31
70
|
// inside the boundary so a bad name yields 500, never a crash.
|
|
32
71
|
const name = decodeURIComponent(c.match[2] ?? '');
|
|
@@ -35,7 +74,8 @@ export const ROUTES = [
|
|
|
35
74
|
: c.match[1] === 'layouts'
|
|
36
75
|
? h.saveLayout(c.diagramsDir, name, c.body)
|
|
37
76
|
: h.saveDrawings(c.diagramsDir, name, c.body);
|
|
38
|
-
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
39
79
|
];
|
|
40
80
|
/** The route matching `method` + `url`, or undefined. First match wins. */
|
|
41
81
|
export function matchRoute(method, url) {
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PublishOptions } from './publish/publish.js';
|
|
1
2
|
interface Args {
|
|
2
3
|
command: string;
|
|
3
4
|
files: string[];
|
|
@@ -37,6 +38,11 @@ export declare class UnknownFlagError extends Error {
|
|
|
37
38
|
export declare class BadFlagValueError extends Error {
|
|
38
39
|
constructor(flag: string, why: string);
|
|
39
40
|
}
|
|
41
|
+
/** Where `publish` compiles to and builds pages from. One object for both steps, so
|
|
42
|
+
* the pages are always made from the artifacts this run just wrote. `--out` moves the
|
|
43
|
+
* artifacts only: the pages and PNGs stay where `.gitignore`, the docs and the READMEs
|
|
44
|
+
* that embed them expect to find them. */
|
|
45
|
+
export declare function publishDirs(args: Pick<Args, 'out'>): Pick<PublishOptions, 'srcDir' | 'artifactsDir' | 'htmlDir' | 'staticDir' | 'assetsDir'>;
|
|
40
46
|
/** `A..B` or `A` (against the working tree). */
|
|
41
47
|
export declare function parseRange(range: string): {
|
|
42
48
|
from: string;
|
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ import { existsSync, statSync } from 'node:fs';
|
|
|
23
23
|
import path from 'node:path';
|
|
24
24
|
import { fileURLToPath } from 'node:url';
|
|
25
25
|
import fg from 'fast-glob';
|
|
26
|
-
import { errMessage } from '@diagc/core';
|
|
26
|
+
import { errMessage } from '@diagc/core/internal';
|
|
27
27
|
import { compileFile } from './compile.js';
|
|
28
28
|
import { compareDiagramSets, formatDiffSummary, loadDiagramSet, writeDiffPages } from './diff.js';
|
|
29
29
|
import { checkoutDiagrams } from './git-ref.js';
|
|
@@ -90,8 +90,14 @@ export function parseArgs(argv) {
|
|
|
90
90
|
for (let i = 0; i < argv.length; i++) {
|
|
91
91
|
const arg = argv[i];
|
|
92
92
|
if (arg === '--out') {
|
|
93
|
-
out
|
|
93
|
+
// No fallback to the default: a trailing --out would quietly write somewhere the
|
|
94
|
+
// user did not ask for, and a missing value would swallow the next flag as the dir.
|
|
95
|
+
const value = argv[i + 1];
|
|
96
|
+
if (value === undefined || value.startsWith('--'))
|
|
97
|
+
throw new BadFlagValueError('--out', 'needs a directory, e.g. --out build/artifacts');
|
|
98
|
+
out = value;
|
|
94
99
|
outGiven = true;
|
|
100
|
+
i++;
|
|
95
101
|
continue;
|
|
96
102
|
}
|
|
97
103
|
if (arg === '--no-images') {
|
|
@@ -134,8 +140,8 @@ export function parseArgs(argv) {
|
|
|
134
140
|
continue;
|
|
135
141
|
}
|
|
136
142
|
if (arg === '--link') {
|
|
137
|
-
// No fallback for a missing value
|
|
138
|
-
//
|
|
143
|
+
// No fallback for a missing value: there is no default address, and the URL
|
|
144
|
+
// check is also what stops the next flag being swallowed as one.
|
|
139
145
|
const value = argv[++i] ?? '';
|
|
140
146
|
try {
|
|
141
147
|
galleryLink(value);
|
|
@@ -204,6 +210,20 @@ const SOURCES = '.diagrams/src/**/*.diagram.{ts,json}';
|
|
|
204
210
|
function warnNoSources(dir = '.diagrams/src') {
|
|
205
211
|
console.error(`No diagrams under ${dir} — run 'diagc init' to create one.`);
|
|
206
212
|
}
|
|
213
|
+
/** Where `publish` compiles to and builds pages from. One object for both steps, so
|
|
214
|
+
* the pages are always made from the artifacts this run just wrote. `--out` moves the
|
|
215
|
+
* artifacts only: the pages and PNGs stay where `.gitignore`, the docs and the READMEs
|
|
216
|
+
* that embed them expect to find them. */
|
|
217
|
+
export function publishDirs(args) {
|
|
218
|
+
const srcDir = '.diagrams/src';
|
|
219
|
+
return {
|
|
220
|
+
srcDir,
|
|
221
|
+
artifactsDir: args.out,
|
|
222
|
+
htmlDir: '.diagrams/html',
|
|
223
|
+
staticDir: '.diagrams/static',
|
|
224
|
+
assetsDir: path.join(srcDir, 'assets'),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
207
227
|
async function main() {
|
|
208
228
|
let args;
|
|
209
229
|
try {
|
|
@@ -277,7 +297,9 @@ async function main() {
|
|
|
277
297
|
if (args.updateIncludes)
|
|
278
298
|
console.error('ignoring --update-includes: watch always runs locked');
|
|
279
299
|
const dir = args.files[0] ?? '.diagrams/src';
|
|
280
|
-
if (existsSync(dir) &&
|
|
300
|
+
if (existsSync(dir) &&
|
|
301
|
+
statSync(dir).isDirectory() &&
|
|
302
|
+
(await fg('**/*.diagram.{ts,json}', { cwd: dir })).length === 0)
|
|
281
303
|
warnNoSources(dir);
|
|
282
304
|
const watchSnap = snapshotSession(resolveInclude, '.diagrams', 'locked');
|
|
283
305
|
startWatch(dir, args.out, {
|
|
@@ -304,15 +326,18 @@ async function main() {
|
|
|
304
326
|
: `viewer shell missing from this install (${home.viewerShell}) — reinstall diagc.`);
|
|
305
327
|
process.exit(1);
|
|
306
328
|
}
|
|
307
|
-
const
|
|
308
|
-
const artifactsDir = '.diagrams/.artifacts';
|
|
329
|
+
const dirs = publishDirs(args);
|
|
309
330
|
// Compile first so artifacts reflect current sources (TS + include expansion).
|
|
310
|
-
const sources = await fg('**/*.diagram.{ts,json}', { cwd: srcDir, absolute: true });
|
|
331
|
+
const sources = await fg('**/*.diagram.{ts,json}', { cwd: dirs.srcDir, absolute: true });
|
|
311
332
|
if (sources.length === 0)
|
|
312
|
-
warnNoSources(srcDir);
|
|
333
|
+
warnNoSources(dirs.srcDir);
|
|
313
334
|
for (const f of sources) {
|
|
314
335
|
try {
|
|
315
|
-
await compileFile(f, artifactsDir, {
|
|
336
|
+
await compileFile(f, dirs.artifactsDir, {
|
|
337
|
+
rootDir: dirs.srcDir,
|
|
338
|
+
coreEntry: home.coreEntry,
|
|
339
|
+
resolver: snap.resolver,
|
|
340
|
+
});
|
|
316
341
|
}
|
|
317
342
|
catch (e) {
|
|
318
343
|
console.error(`✗ ${f}\n${errMessage(e)}`);
|
|
@@ -336,21 +361,17 @@ async function main() {
|
|
|
336
361
|
}
|
|
337
362
|
}
|
|
338
363
|
const res = await publishDiagrams({
|
|
339
|
-
|
|
340
|
-
artifactsDir,
|
|
341
|
-
htmlDir: '.diagrams/html',
|
|
342
|
-
staticDir: '.diagrams/static',
|
|
364
|
+
...dirs,
|
|
343
365
|
shellPath: home.viewerShell,
|
|
344
366
|
libraryDir: home.libraryDir,
|
|
345
|
-
assetsDir: path.join(srcDir, 'assets'),
|
|
346
367
|
images,
|
|
347
368
|
names: args.files,
|
|
348
369
|
...(renderPng !== undefined ? { renderPng } : {}),
|
|
349
370
|
...(args.link !== undefined ? { link: args.link } : {}),
|
|
350
371
|
});
|
|
351
|
-
console.log(`✓ ${res.pages.length} page(s) -> .
|
|
372
|
+
console.log(`✓ ${res.pages.length} page(s) -> ${dirs.htmlDir}`);
|
|
352
373
|
if (res.images.length > 0)
|
|
353
|
-
console.log(`✓ ${res.images.length} image(s) -> .
|
|
374
|
+
console.log(`✓ ${res.images.length} image(s) -> ${dirs.staticDir}`);
|
|
354
375
|
console.log(`✓ gallery -> ${res.gallery}`);
|
|
355
376
|
process.exit(0);
|
|
356
377
|
}
|
package/dist/compile.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DiagramModel, type IncludeResolver } from '@diagc/core';
|
|
1
|
+
import { type DiagramModel, type IncludeResolver } from '@diagc/core/internal';
|
|
2
2
|
/**
|
|
3
3
|
* A source that threw while running — a misspelled method, a builder call that
|
|
4
4
|
* refused — placed at the first stack frame inside that file. V8 writes the file
|
package/dist/compile.js
CHANGED
|
@@ -2,7 +2,7 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createJiti } from 'jiti';
|
|
5
|
-
import { composeIncludes, DiagramValidationError, diagramWarnings, errMessage, validate, } from '@diagc/core';
|
|
5
|
+
import { composeIncludes, DiagramValidationError, diagramWarnings, errMessage, validate, } from '@diagc/core/internal';
|
|
6
6
|
import { resolveInclude } from './includes.js';
|
|
7
7
|
import { snapshotSession } from './snapshots.js';
|
|
8
8
|
/**
|
package/dist/diff.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DiagramModel, type Drawings, type LayoutOverlay, type ModelDiff } from '@diagc/core';
|
|
1
|
+
import { type DiagramModel, type Drawings, type LayoutOverlay, type ModelDiff } from '@diagc/core/internal';
|
|
2
2
|
/** One diagram as a version of the repo had it: the compiled model plus the
|
|
3
3
|
* sidecars a picture of it needs. */
|
|
4
4
|
export interface DiagramVersion {
|
package/dist/diff.js
CHANGED
|
@@ -2,12 +2,21 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
|
-
import { diffMarks, diffModels, errMessage, isDrawings, isEmptyDiff, } from '@diagc/core';
|
|
5
|
+
import { diffMarks, diffModels, errMessage, isDrawings, isEmptyDiff, } from '@diagc/core/internal';
|
|
6
6
|
import { loadModel } from './compile.js';
|
|
7
7
|
import { inlineAssets } from './publish/publish.js';
|
|
8
8
|
import { stampHtml } from './publish/html.js';
|
|
9
9
|
import { THEME_HEAD_SCRIPT, THEME_SWITCH, themeCss } from './publish/pageTheme.js';
|
|
10
|
-
const EMPTY = {
|
|
10
|
+
const EMPTY = {
|
|
11
|
+
version: 1,
|
|
12
|
+
id: '',
|
|
13
|
+
name: '',
|
|
14
|
+
nodes: [],
|
|
15
|
+
containment: [],
|
|
16
|
+
relations: [],
|
|
17
|
+
layers: [],
|
|
18
|
+
planes: [],
|
|
19
|
+
};
|
|
11
20
|
async function readJson(file) {
|
|
12
21
|
return existsSync(file) ? JSON.parse(await readFile(file, 'utf8')) : undefined;
|
|
13
22
|
}
|
|
@@ -20,7 +29,10 @@ export async function loadDiagramSet(label, diagramsDir, coreEntry) {
|
|
|
20
29
|
for (const rel of files.sort()) {
|
|
21
30
|
const name = rel.replace(/\.diagram\.(ts|json)$/, '');
|
|
22
31
|
try {
|
|
23
|
-
const model = await loadModel(path.join(srcDir, rel), {
|
|
32
|
+
const model = await loadModel(path.join(srcDir, rel), {
|
|
33
|
+
rootDir: srcDir,
|
|
34
|
+
...(coreEntry !== undefined ? { coreEntry } : {}),
|
|
35
|
+
});
|
|
24
36
|
const layout = (await readJson(path.join(srcDir, `${name}.layout.json`)));
|
|
25
37
|
const drawings = await readJson(path.join(srcDir, `${name}.drawings.json`));
|
|
26
38
|
versions.set(name, {
|
|
@@ -37,7 +49,12 @@ export async function loadDiagramSet(label, diagramsDir, coreEntry) {
|
|
|
37
49
|
}
|
|
38
50
|
/** Pair the two sets by name. `names` narrows the result to those diagrams. */
|
|
39
51
|
export function compareDiagramSets(before, after, names = []) {
|
|
40
|
-
const all = new Set([
|
|
52
|
+
const all = new Set([
|
|
53
|
+
...before.versions.keys(),
|
|
54
|
+
...before.errors.keys(),
|
|
55
|
+
...after.versions.keys(),
|
|
56
|
+
...after.errors.keys(),
|
|
57
|
+
]);
|
|
41
58
|
const wanted = names.length > 0 ? names.filter((n) => all.has(n)) : [...all].sort();
|
|
42
59
|
return wanted.map((name) => {
|
|
43
60
|
const b = before.versions.get(name);
|
|
@@ -64,7 +81,9 @@ export function describeDiff(d) {
|
|
|
64
81
|
if (d.diff === undefined)
|
|
65
82
|
return [];
|
|
66
83
|
if (d.status === 'added')
|
|
67
|
-
return [
|
|
84
|
+
return [
|
|
85
|
+
`+ new diagram: ${d.after.model.name} (${d.diff.nodes.added.length} nodes, ${d.diff.relations.added.length} relations)`,
|
|
86
|
+
];
|
|
68
87
|
if (d.status === 'removed')
|
|
69
88
|
return [`- diagram removed: ${d.before.model.name}`];
|
|
70
89
|
const before = d.before?.model;
|
|
@@ -174,7 +193,9 @@ function indexHtml(shown, files, from, to) {
|
|
|
174
193
|
: `<div class="side"><h3><a href="${escapeHtml(rel)}.html">${escapeHtml(label)}</a></h3><iframe src="${escapeHtml(rel)}.html?export=1" title="${escapeHtml(label)}"></iframe></div>`;
|
|
175
194
|
const sections = shown.map((d) => {
|
|
176
195
|
const f = files.get(d.name) ?? {};
|
|
177
|
-
const list = describeDiff(d)
|
|
196
|
+
const list = describeDiff(d)
|
|
197
|
+
.map((l) => `<li class="${l[0] === '+' ? 'add' : l[0] === '-' ? 'del' : 'chg'}">${escapeHtml(l)}</li>`)
|
|
198
|
+
.join('');
|
|
178
199
|
return `<section><h2>${escapeHtml(d.name)}</h2><ul>${list}</ul><div class="pair">${side(f.before, `Before · ${from}`)}${side(f.after, `After · ${to}`)}</div></section>`;
|
|
179
200
|
});
|
|
180
201
|
return `<!doctype html>
|
package/dist/eject.d.ts
CHANGED
package/dist/eject.js
CHANGED
|
@@ -2,7 +2,7 @@ import { access, mkdtemp, readFile, rm, unlink, writeFile } from 'node:fs/promis
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
-
import { ejectSource, errMessage, validate } from '@diagc/core';
|
|
5
|
+
import { ejectSource, errMessage, validate } from '@diagc/core/internal';
|
|
6
6
|
import { compileFile, executeDiagramTs } from './compile.js';
|
|
7
7
|
import { resolveInclude } from './includes.js';
|
|
8
8
|
import { snapshotSession } from './snapshots.js';
|
package/dist/git-ref.js
CHANGED
|
@@ -48,7 +48,10 @@ export async function checkoutDiagrams(ref, cwd, diagramsDir = '.diagrams') {
|
|
|
48
48
|
/** `git archive <commit> -- <path> | tar -x -C <into>`, without a shell. */
|
|
49
49
|
function pipeArchive(commit, repoPath, cwd, into) {
|
|
50
50
|
return new Promise((resolve, reject) => {
|
|
51
|
-
const git = spawn('git', ['archive', '--format=tar', commit, '--', repoPath], {
|
|
51
|
+
const git = spawn('git', ['archive', '--format=tar', commit, '--', repoPath], {
|
|
52
|
+
cwd,
|
|
53
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
54
|
+
});
|
|
52
55
|
const tar = spawn('tar', ['-x', '-C', into], { stdio: ['pipe', 'ignore', 'pipe'] });
|
|
53
56
|
let err = '';
|
|
54
57
|
git.stderr.on('data', (d) => (err += d.toString()));
|
package/dist/guide.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { NODE_TYPES, NOTATION_NODE_TYPES, NOTATION_RELATION_KINDS, RELATION_KINDS } from '@diagc/core';
|
|
3
|
+
import { NODE_TYPES, NOTATION_NODE_TYPES, NOTATION_RELATION_KINDS, RELATION_KINDS } from '@diagc/core/internal';
|
|
4
4
|
import { UnknownStarterError, readStarter } from './starters.js';
|
|
5
5
|
const INDEX = 'index';
|
|
6
6
|
/** `diagc guide all`: the index, then every topic — for a reader who cannot ask
|
package/dist/includes.d.ts
CHANGED
package/dist/init.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IncludeResolver } from '@diagc/core';
|
|
1
|
+
import { type IncludeResolver } from '@diagc/core/internal';
|
|
2
2
|
/** What `diagc init` works with. `cwd` is the directory being set up — the
|
|
3
3
|
* current directory in the CLI, a temp dir in tests — and every path is built
|
|
4
4
|
* from it, so nothing here reads `process.cwd()`. */
|
package/dist/init.js
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, statSync } from 'node:fs';
|
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
|
-
import { errMessage } from '@diagc/core';
|
|
5
|
+
import { errMessage } from '@diagc/core/internal';
|
|
6
6
|
import { isSafeName } from './api/handlers.js';
|
|
7
7
|
import { compileFile } from './compile.js';
|
|
8
8
|
import { readStarter, UnknownStarterError } from './starters.js';
|
|
@@ -49,8 +49,12 @@ export function withBlock(existing, block) {
|
|
|
49
49
|
}
|
|
50
50
|
export const withAgentsBlock = (existing) => withBlock(existing, AGENTS_BLOCK);
|
|
51
51
|
const COL = 38;
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
/** A line of two columns: the right one starts COL in, and never less than two spaces after
|
|
53
|
+
* the left one. A path with a folder in its name is longer than the column, and padding
|
|
54
|
+
* alone would run it into the text beside it. */
|
|
55
|
+
const columns = (left, right) => `${left.padEnd(COL - 2)} ${right}`;
|
|
56
|
+
const done = (left, right) => `✓ ${columns(left, right)}`;
|
|
57
|
+
const skipped = (left, right) => `· ${columns(left, right)}`;
|
|
54
58
|
/** A one-line failure on stderr with exit 1. A refusal leaves the tree untouched;
|
|
55
59
|
* a compile failure comes after the writes, so the starter and `.gitignore` stay. */
|
|
56
60
|
export class InitError extends Error {
|
|
@@ -146,7 +150,8 @@ async function agentsStep(cwd, io) {
|
|
|
146
150
|
}
|
|
147
151
|
/** `.claude/` is Claude Code's own folder, not neutral ground like `AGENTS.md`, so
|
|
148
152
|
* the skill goes only where the repository already shows that tool in use. */
|
|
149
|
-
const usesClaudeCode = (cwd) => (statSync(path.join(cwd, '.claude'), { throwIfNoEntry: false })?.isDirectory() ?? false) ||
|
|
153
|
+
const usesClaudeCode = (cwd) => (statSync(path.join(cwd, '.claude'), { throwIfNoEntry: false })?.isDirectory() ?? false) ||
|
|
154
|
+
existsSync(path.join(cwd, 'CLAUDE.md'));
|
|
150
155
|
/** Everything step 4 has to read, read before the first write: an install that
|
|
151
156
|
* lost its skill is a refusal, and a refusal leaves the tree untouched. A new file
|
|
152
157
|
* is the shipped one, frontmatter and all; in a file that is already there only
|
|
@@ -205,7 +210,7 @@ function nextSteps(opts) {
|
|
|
205
210
|
lines.push(['diagc init --agents', 'point coding agents at the guide (AGENTS.md, Claude Code skill)']);
|
|
206
211
|
if (existsSync(path.join(opts.cwd, 'package.json')))
|
|
207
212
|
lines.push([`npm i -D @diagc/core@${opts.version}`, 'editor types for .diagram.ts']);
|
|
208
|
-
return `\nNext:\n${lines.map(([cmd, what]) => ` ${cmd
|
|
213
|
+
return `\nNext:\n${lines.map(([cmd, what]) => ` ${columns(cmd, what)}`).join('\n')}`;
|
|
209
214
|
}
|
|
210
215
|
const stdio = {
|
|
211
216
|
out: (text) => console.log(text),
|
package/dist/lint.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { diagramWarnings, errMessage } from '@diagc/core';
|
|
1
|
+
import { diagramWarnings, errMessage } from '@diagc/core/internal';
|
|
2
2
|
import { LoadError, loadModel } from './compile.js';
|
|
3
3
|
const report = (file, severity, i) => ({
|
|
4
4
|
file,
|
|
@@ -16,7 +16,9 @@ export async function lintFile(file, opts) {
|
|
|
16
16
|
}
|
|
17
17
|
catch (e) {
|
|
18
18
|
// By name, not instanceof: a builder diagram throws from jiti's own copy of core.
|
|
19
|
-
if (e instanceof Error &&
|
|
19
|
+
if (e instanceof Error &&
|
|
20
|
+
e.name === 'DiagramValidationError' &&
|
|
21
|
+
Array.isArray(e.issues)) {
|
|
20
22
|
return e.issues.map((i) => report(file, 'error', i));
|
|
21
23
|
}
|
|
22
24
|
if (e instanceof LoadError) {
|
package/dist/publish/assets.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DiagramModel } from '@diagc/core';
|
|
1
|
+
import type { DiagramModel } from '@diagc/core/internal';
|
|
2
2
|
export declare function dataUri(bytes: Buffer, ext: string): string;
|
|
3
3
|
/**
|
|
4
4
|
* Classify an asset ref so publish-time code knows whether/where to read it from disk.
|
package/dist/publish/assets.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
const MIME = {
|
|
3
|
-
svg: 'image/svg+xml',
|
|
3
|
+
svg: 'image/svg+xml',
|
|
4
|
+
png: 'image/png',
|
|
5
|
+
jpg: 'image/jpeg',
|
|
6
|
+
jpeg: 'image/jpeg',
|
|
7
|
+
webp: 'image/webp',
|
|
8
|
+
gif: 'image/gif',
|
|
4
9
|
};
|
|
5
10
|
export function dataUri(bytes, ext) {
|
|
6
11
|
const mime = MIME[ext.toLowerCase()] ?? 'application/octet-stream';
|
package/dist/publish/discover.js
CHANGED
|
@@ -17,7 +17,11 @@ export async function discoverDiagrams(artifactsDir, srcDir) {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
for (const modelPath of files) {
|
|
20
|
-
const name = path
|
|
20
|
+
const name = path
|
|
21
|
+
.relative(artifactsDir, modelPath)
|
|
22
|
+
.replace(/\.diagram\.json$/, '')
|
|
23
|
+
.split(path.sep)
|
|
24
|
+
.join('/');
|
|
21
25
|
const layoutPath = path.join(srcDir, `${name}.layout.json`);
|
|
22
26
|
const drawingsPath = path.join(srcDir, `${name}.drawings.json`);
|
|
23
27
|
out.push({
|
package/dist/publish/gallery.js
CHANGED
|
@@ -3,9 +3,7 @@ function esc(s) {
|
|
|
3
3
|
return s.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
|
4
4
|
}
|
|
5
5
|
function card(e) {
|
|
6
|
-
const thumb = e.hasImage
|
|
7
|
-
? `<img src="../static/${esc(e.name)}.png" alt="${esc(e.title)}" loading="lazy" />`
|
|
8
|
-
: '';
|
|
6
|
+
const thumb = e.hasImage ? `<img src="../static/${esc(e.name)}.png" alt="${esc(e.title)}" loading="lazy" />` : '';
|
|
9
7
|
// The path is what `diagc publish <name>` and the page URL use, so it stays on the
|
|
10
8
|
// card — unless the model has no name of its own and the two would just repeat.
|
|
11
9
|
const path = e.title === e.name ? '' : `<span class="path">${esc(e.name)}</span>`;
|
package/dist/publish/html.d.ts
CHANGED
package/dist/publish/html.js
CHANGED