nerdgram1337 1.6.1 → 1.8.5
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/README.md +2 -1
- package/dist/{chunk-AWVTRON2.js → chunk-2WFLIMQG.js} +11 -3
- package/dist/chunk-3WBI2WV6.js +18 -0
- package/dist/{chunk-LYMG57VV.js → chunk-46CLFN4M.js} +24 -5
- package/dist/{chunk-BCO66AYP.js → chunk-7NPZMMPE.js} +7 -4
- package/dist/chunk-7O4HSURR.js +3396 -0
- package/dist/{chunk-KA5X3YY6.js → chunk-7XBDBMFZ.js} +9 -60
- package/dist/{chunk-JL7RYIQE.js → chunk-ARL7TA3D.js} +902 -440
- package/dist/{chunk-5C6VO4LC.js → chunk-BW6ANOTX.js} +38 -0
- package/dist/chunk-DHVVDJDI.js +470 -0
- package/dist/chunk-DWP7W42J.js +12 -0
- package/dist/{chunk-LXSDAIF4.js → chunk-GD2NZSZO.js} +42 -18
- package/dist/chunk-GI4QATKE.js +87 -0
- package/dist/chunk-GK3V52XM.js +70 -0
- package/dist/chunk-KIK3WXJL.js +959 -0
- package/dist/{chunk-7YIBJCTH.js → chunk-M4HT24R6.js} +22 -9
- package/dist/chunk-M63FV47T.js +14 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-TDN24VZZ.js +196 -0
- package/dist/chunk-TFNQIO7Z.js +21 -0
- package/dist/chunk-TVIG7AQK.js +78 -0
- package/dist/chunk-WYQ4QDCF.js +85 -0
- package/dist/chunk-XC6UP46Q.js +15 -0
- package/dist/cli.js +185 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "./chunk-MLKGABMK.js";
|
|
2
3
|
|
|
3
4
|
// server/src/cli.ts
|
|
4
5
|
import { readFileSync } from "node:fs";
|
|
@@ -37,6 +38,7 @@ Usage
|
|
|
37
38
|
nerdgram search <query>
|
|
38
39
|
nerdgram get <path> [-o file]
|
|
39
40
|
nerdgram put <path> <file>
|
|
41
|
+
nerdgram export <target> <diagram|network.json> [-o file]
|
|
40
42
|
nerdgram export <folder> -o dir/
|
|
41
43
|
nerdgram lint [path|file] [--strict]
|
|
42
44
|
nerdgram rename <from> <to>
|
|
@@ -48,13 +50,17 @@ Usage
|
|
|
48
50
|
nerdgram generate --path Diagram.mmd --data neighbors.lldp --format lldp --local-device edge-sw
|
|
49
51
|
nerdgram generate --path Campus-L3.mmd --data campus.network.json --format network --view l3
|
|
50
52
|
nerdgram generate --path Campus-L2.mmd --data campus.network.json --format network --view l2 --group-by site
|
|
53
|
+
nerdgram convert <source> [file] [-o out.network.json]
|
|
51
54
|
nerdgram refresh <path> [--data data.csv]
|
|
52
55
|
nerdgram diff <path> --from <id|name|current> [--to <id|name|current>] [--format md|json|svg]
|
|
53
56
|
nerdgram baseline <path> --name "\u2026" [--note "\u2026"] [--id <revision>]
|
|
54
57
|
nerdgram replace <find> <replace> [--folder path] [--regex] [--whole-word] [--match-case] [--front-matter] [--no-recursive] [--dry-run] [--yes]
|
|
55
58
|
nerdgram replace --undo <id>
|
|
56
59
|
|
|
57
|
-
A local .mmd file is rendered and linted in this process.
|
|
60
|
+
A local .mmd file is rendered and linted in this process. convert reads a
|
|
61
|
+
saved export and writes canonical network JSON in this process. export of a
|
|
62
|
+
registered target reads network JSON in this process. export of a folder
|
|
63
|
+
talks to the server. Anything else uses
|
|
58
64
|
NERDGRAM_URL (default http://127.0.0.1:8787) and NERDGRAM_TOKEN.
|
|
59
65
|
--url and --token override those. --server forces render to use a workspace
|
|
60
66
|
path on the API, not a file on this computer. Exit status is 1 on errors.
|
|
@@ -112,16 +118,16 @@ not changed. --undo restores that replace and skips a file edited since.
|
|
|
112
118
|
`;
|
|
113
119
|
var renderModule = null;
|
|
114
120
|
function loadRender() {
|
|
115
|
-
renderModule ??= import("./chunk-
|
|
121
|
+
renderModule ??= import("./chunk-7NPZMMPE.js");
|
|
116
122
|
return renderModule;
|
|
117
123
|
}
|
|
118
124
|
async function loadLint() {
|
|
119
|
-
return import("./chunk-
|
|
125
|
+
return import("./chunk-DWP7W42J.js");
|
|
120
126
|
}
|
|
121
127
|
async function templateCommand(parsed, io) {
|
|
122
128
|
const sub = parsed.positionals[0] ?? "";
|
|
123
129
|
const target = parsed.positionals[1] ?? "";
|
|
124
|
-
const templates = await import("./chunk-
|
|
130
|
+
const templates = await import("./chunk-2WFLIMQG.js");
|
|
125
131
|
try {
|
|
126
132
|
if (sub === "save") {
|
|
127
133
|
if (!target) throw new CliError("Usage: nerdgram template save <diagram> [--name name] [--replace]");
|
|
@@ -394,7 +400,25 @@ async function putCommand(parsed, io) {
|
|
|
394
400
|
writeOut(io, isJson(parsed.flags), { path: body.path, hash: body.hash ?? null }, `Wrote ${body.path}`);
|
|
395
401
|
}
|
|
396
402
|
async function exportCommand(parsed, io) {
|
|
397
|
-
const
|
|
403
|
+
const exporters = await import("./chunk-GI4QATKE.js");
|
|
404
|
+
const first = parsed.positionals[0] ?? "";
|
|
405
|
+
const installed = await exporters.installedExporters();
|
|
406
|
+
const ids = installed.map((item) => item.id).join(", ") || "(none)";
|
|
407
|
+
const usage = [
|
|
408
|
+
"Usage:",
|
|
409
|
+
" nerdgram export <target> <diagram|network.json> [-o file]",
|
|
410
|
+
" nerdgram export <folder> -o dir/",
|
|
411
|
+
`Installed exporters: ${ids}`
|
|
412
|
+
].join("\n");
|
|
413
|
+
if (parsed.positionals.length === 0) throw new CliError(usage);
|
|
414
|
+
const known = installed.find((item) => item.id === first.trim().toLowerCase());
|
|
415
|
+
if (known) {
|
|
416
|
+
await designExportCommand(parsed, io, known.id);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (parsed.positionals.length > 1) throw new CliError(`Unknown exporter "${first}".
|
|
420
|
+
${usage}`);
|
|
421
|
+
const folder = first;
|
|
398
422
|
const output = flagString(parsed.flags, "output");
|
|
399
423
|
if (!output) throw new CliError("export needs -o directory.");
|
|
400
424
|
const { base, token } = configOf(parsed.flags, io.env);
|
|
@@ -413,6 +437,114 @@ async function exportCommand(parsed, io) {
|
|
|
413
437
|
}
|
|
414
438
|
writeOut(io, isJson(parsed.flags), { path: folder, output, count }, `Exported ${count} diagram${count === 1 ? "" : "s"} to ${output}`);
|
|
415
439
|
}
|
|
440
|
+
async function designExportCommand(parsed, io, target) {
|
|
441
|
+
const { readMappingFile, siblingNetworkPath, readNetworkFile, parseNetworkDocument, labelFromPath } = await import("./chunk-TFNQIO7Z.js");
|
|
442
|
+
const { runExport } = await import("./chunk-XC6UP46Q.js");
|
|
443
|
+
const file = parsed.positionals[1];
|
|
444
|
+
let document;
|
|
445
|
+
let label = "nerdgram";
|
|
446
|
+
let mapBeside = null;
|
|
447
|
+
if (file && file !== "-") {
|
|
448
|
+
const resolved = path.resolve(file);
|
|
449
|
+
mapBeside = path.join(path.dirname(resolved), "nerdgram-export-map.yml");
|
|
450
|
+
if (file.toLowerCase().endsWith(".mmd")) {
|
|
451
|
+
const content = await fs.readFile(resolved, "utf8");
|
|
452
|
+
const sibling = siblingNetworkPath(resolved, content);
|
|
453
|
+
const candidates = path.isAbsolute(sibling.path) ? [sibling.path] : [path.resolve(path.dirname(resolved), sibling.path), path.resolve(sibling.path)];
|
|
454
|
+
let text2 = null;
|
|
455
|
+
for (const candidate of candidates) {
|
|
456
|
+
try {
|
|
457
|
+
text2 = await fs.readFile(candidate, "utf8");
|
|
458
|
+
break;
|
|
459
|
+
} catch {
|
|
460
|
+
text2 = null;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (text2 == null) {
|
|
464
|
+
throw new CliError(
|
|
465
|
+
sibling.kind === "recorded" ? `The diagram records network JSON at ${sibling.path}, and that file is not there.` : "This diagram has no network JSON."
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
document = parseNetworkDocument(text2);
|
|
469
|
+
label = labelFromPath(resolved);
|
|
470
|
+
} else if (file.toLowerCase().endsWith(".network.json")) {
|
|
471
|
+
const loaded = await readNetworkFile(resolved);
|
|
472
|
+
document = loaded.document;
|
|
473
|
+
label = loaded.label;
|
|
474
|
+
} else {
|
|
475
|
+
throw new CliError("The design export needs a .mmd diagram or a .network.json file.");
|
|
476
|
+
}
|
|
477
|
+
} else if (io.stdin != null) {
|
|
478
|
+
document = parseNetworkDocument(io.stdin);
|
|
479
|
+
label = "nerdgram";
|
|
480
|
+
} else if (process.stdin.isTTY) {
|
|
481
|
+
throw new CliError("export needs a file or stdin.");
|
|
482
|
+
} else {
|
|
483
|
+
document = parseNetworkDocument(await readStdin());
|
|
484
|
+
}
|
|
485
|
+
const mapFlag = flagString(parsed.flags, "map");
|
|
486
|
+
let mappingDocument = null;
|
|
487
|
+
if (mapFlag) mappingDocument = await readMappingFile(mapFlag);
|
|
488
|
+
else {
|
|
489
|
+
for (const candidate of [mapBeside, path.resolve("nerdgram-export-map.yml")]) {
|
|
490
|
+
if (!candidate) continue;
|
|
491
|
+
try {
|
|
492
|
+
mappingDocument = await readMappingFile(candidate);
|
|
493
|
+
break;
|
|
494
|
+
} catch {
|
|
495
|
+
mappingDocument = null;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const exported = await runExport(target, document, { label, mapping: null }, mappingDocument);
|
|
500
|
+
const output = flagString(parsed.flags, "output");
|
|
501
|
+
const warningLines = exported.warnings.map((item) => item.path ? `${item.path}: ${item.message}` : item.message);
|
|
502
|
+
if (!isJson(parsed.flags) && warningLines.length > 0) io.stderr(`${warningLines.join("\n")}
|
|
503
|
+
`);
|
|
504
|
+
if (exported.files.length > 1) {
|
|
505
|
+
if (!output) throw new CliError("This export writes multiple files. Pass -o directory.");
|
|
506
|
+
if (output.toLowerCase().endsWith(".zip")) {
|
|
507
|
+
const bytes = Buffer.from(exported.archive?.base64 ?? "", "base64");
|
|
508
|
+
await fs.mkdir(path.dirname(path.resolve(output)), { recursive: true });
|
|
509
|
+
await fs.writeFile(output, bytes);
|
|
510
|
+
writeOut(io, isJson(parsed.flags), { target, output, warnings: exported.warnings, bytes: bytes.length }, `Wrote ${output}`);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const root = path.resolve(output);
|
|
514
|
+
await fs.mkdir(root, { recursive: true });
|
|
515
|
+
for (const item of exported.files) {
|
|
516
|
+
const destination = path.resolve(root, item.name);
|
|
517
|
+
const relative = path.relative(root, destination);
|
|
518
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) throw new CliError(`Refusing to write ${item.name}`);
|
|
519
|
+
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
520
|
+
await fs.writeFile(destination, item.text, "utf8");
|
|
521
|
+
}
|
|
522
|
+
writeOut(
|
|
523
|
+
io,
|
|
524
|
+
isJson(parsed.flags),
|
|
525
|
+
{ target, output, warnings: exported.warnings, bytes: exported.bytes, files: exported.files.map((item) => ({ name: item.name, bytes: Buffer.byteLength(item.text) })) },
|
|
526
|
+
`Wrote ${exported.files.length} files to ${output}`
|
|
527
|
+
);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const text = exported.text.endsWith("\n") ? exported.text : `${exported.text}
|
|
531
|
+
`;
|
|
532
|
+
if (output) {
|
|
533
|
+
await fs.mkdir(path.dirname(path.resolve(output)), { recursive: true });
|
|
534
|
+
await fs.writeFile(output, text, "utf8");
|
|
535
|
+
}
|
|
536
|
+
if (isJson(parsed.flags)) {
|
|
537
|
+
const payload = output ? { target, output, warnings: exported.warnings, bytes: Buffer.byteLength(text) } : { target, text, warnings: exported.warnings, bytes: Buffer.byteLength(text) };
|
|
538
|
+
writeOut(io, true, payload, "");
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (output) {
|
|
542
|
+
io.stdout(`Wrote ${output}
|
|
543
|
+
`);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
io.stdout(text);
|
|
547
|
+
}
|
|
416
548
|
async function lintCommand(parsed, io) {
|
|
417
549
|
const target = parsed.positionals[0] ?? flagString(parsed.flags, "source");
|
|
418
550
|
const strict = parsed.flags.get("strict") === true;
|
|
@@ -771,11 +903,55 @@ async function refreshCommand(parsed, io) {
|
|
|
771
903
|
const body = result.json;
|
|
772
904
|
writeOut(io, isJson(parsed.flags), body, `Refreshed ${body.path}`);
|
|
773
905
|
}
|
|
906
|
+
async function readStdin() {
|
|
907
|
+
const chunks = [];
|
|
908
|
+
for await (const chunk of process.stdin) {
|
|
909
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
910
|
+
}
|
|
911
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
912
|
+
}
|
|
913
|
+
async function convertCommand(parsed, io) {
|
|
914
|
+
const translators = await import("./chunk-7O4HSURR.js");
|
|
915
|
+
const source = parsed.positionals[0] ?? "";
|
|
916
|
+
if (!source) {
|
|
917
|
+
const installed = await translators.installedTranslators();
|
|
918
|
+
const ids = installed.map((item) => item.id).join(", ") || "(none)";
|
|
919
|
+
throw new CliError(`Usage: nerdgram convert <source> [file] [-o out.network.json]
|
|
920
|
+
Installed translators: ${ids}`);
|
|
921
|
+
}
|
|
922
|
+
const file = parsed.positionals[1];
|
|
923
|
+
let text;
|
|
924
|
+
if (file && file !== "-") text = await fs.readFile(file, "utf8");
|
|
925
|
+
else if (io.stdin != null) text = io.stdin;
|
|
926
|
+
else if (process.stdin.isTTY) throw new CliError("convert needs a file or stdin.");
|
|
927
|
+
else text = await readStdin();
|
|
928
|
+
translators.assertConvertInputSize(Buffer.byteLength(text));
|
|
929
|
+
const converted = await translators.convertExport(source, translators.parseExport(text));
|
|
930
|
+
const pretty = `${JSON.stringify(converted.document, null, 2)}
|
|
931
|
+
`;
|
|
932
|
+
const output = flagString(parsed.flags, "output");
|
|
933
|
+
if (output) await fs.writeFile(output, pretty, "utf8");
|
|
934
|
+
const warningLines = converted.warnings.map((item) => item.path ? `${item.path}: ${item.message}` : item.message);
|
|
935
|
+
if (!isJson(parsed.flags) && warningLines.length > 0) io.stderr(`${warningLines.join("\n")}
|
|
936
|
+
`);
|
|
937
|
+
if (isJson(parsed.flags)) {
|
|
938
|
+
const payload = output ? { source: converted.source, output, warnings: converted.warnings, bytes: Buffer.byteLength(pretty) } : { source: converted.source, document: converted.document, warnings: converted.warnings };
|
|
939
|
+
writeOut(io, true, payload, "");
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (output) {
|
|
943
|
+
io.stdout(`Wrote ${output}
|
|
944
|
+
`);
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
io.stdout(pretty);
|
|
948
|
+
}
|
|
774
949
|
async function main(argv, io = {}) {
|
|
775
950
|
const streams = {
|
|
776
951
|
stdout: io.stdout ?? ((chunk) => process.stdout.write(chunk)),
|
|
777
952
|
stderr: io.stderr ?? ((chunk) => process.stderr.write(chunk)),
|
|
778
|
-
env: io.env ?? process.env
|
|
953
|
+
env: io.env ?? process.env,
|
|
954
|
+
stdin: io.stdin
|
|
779
955
|
};
|
|
780
956
|
let parsed;
|
|
781
957
|
try {
|
|
@@ -835,6 +1011,9 @@ async function main(argv, io = {}) {
|
|
|
835
1011
|
case "generate":
|
|
836
1012
|
await generateCommand(parsed, streams);
|
|
837
1013
|
return 0;
|
|
1014
|
+
case "convert":
|
|
1015
|
+
await convertCommand(parsed, streams);
|
|
1016
|
+
return 0;
|
|
838
1017
|
case "refresh":
|
|
839
1018
|
await refreshCommand(parsed, streams);
|
|
840
1019
|
return 0;
|