nerdgram1337 1.1.5 → 1.2.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/README.md CHANGED
@@ -34,6 +34,10 @@ nerdgram search Atlanta
34
34
  nerdgram get Welcome.mmd -o Welcome.mmd
35
35
  nerdgram put Notes.mmd ./Notes.mmd
36
36
  nerdgram lint Welcome.mmd
37
+ nerdgram diff Welcome.mmd --from current --to current --format md
38
+ nerdgram baseline Welcome.mmd --name "Baseline"
39
+ nerdgram replace CORE-SW1 ATL-CORE-01 --dry-run
40
+ nerdgram replace CORE-SW1 ATL-CORE-01 --yes
37
41
  nerdgram render Welcome.mmd -o Welcome.svg
38
42
  ```
39
43
 
package/dist/cli.js CHANGED
@@ -12,6 +12,12 @@ var BOOL_FLAGS = /* @__PURE__ */ new Set([
12
12
  "h",
13
13
  "no-update-links",
14
14
  "dry-run",
15
+ "yes",
16
+ "match-case",
17
+ "whole-word",
18
+ "regex",
19
+ "front-matter",
20
+ "no-recursive",
15
21
  "apply",
16
22
  "copy-data",
17
23
  "share-data",
@@ -36,6 +42,10 @@ Usage
36
42
  nerdgram generate --path Diagram.mmd --data data.csv
37
43
  nerdgram generate --path Diagram.mmd --data neighbors.lldp --format lldp --local-device edge-sw
38
44
  nerdgram refresh <path> [--data data.csv]
45
+ nerdgram diff <path> --from <id|name|current> [--to <id|name|current>] [--format md|json|svg]
46
+ nerdgram baseline <path> --name "\u2026" [--note "\u2026"] [--id <revision>]
47
+ nerdgram replace <find> <replace> [--folder path] [--regex] [--whole-word] [--match-case] [--front-matter] [--no-recursive] [--dry-run] [--yes]
48
+ nerdgram replace --undo <id>
39
49
 
40
50
  A local .mmd file is rendered and linted in this process. Anything else uses
41
51
  NERDGRAM_URL (default http://127.0.0.1:8787) and NERDGRAM_TOKEN.
@@ -51,10 +61,23 @@ repair-links previews click repairs after a rename or move made outside the
51
61
  app. --dry-run is the default and writes nothing. --apply saves the previewed
52
62
  rewrites. If the data file moved with that diagram, the same confirmation
53
63
  updates nerdgram.source. An ambiguous match is listed and left unchanged.
64
+ diff compares two revisions, or a revision and the current diagram. --to
65
+ defaults to current. --from accepts a revision id, a baseline name, or
66
+ current. --format md prints a Markdown summary, json prints the diff, and
67
+ svg writes the read-only visual diff. svg needs -o file.svg. The diagram
68
+ file is not modified.
69
+ baseline saves the current diagram as a named baseline. --id names an
70
+ existing revision instead. Names are kept when the 20-revision limit drops
71
+ older saves.
72
+ replace prints a preview. --yes applies it and saves each diagram, so the
73
+ previous text is a revision. --dry-run is the default. --folder limits the
74
+ scope. --no-recursive stays in that folder. The diagram body is searched
75
+ unless --front-matter is set. Hidden files, .meta, trash, and templates are
76
+ not changed. --undo restores that replace and skips a file edited since.
54
77
  `;
55
78
  var renderModule = null;
56
79
  function loadRender() {
57
- renderModule ??= import("./chunk-ZH7YZLR3.js");
80
+ renderModule ??= import("./chunk-5EV3XFVE.js");
58
81
  return renderModule;
59
82
  }
60
83
  async function loadLint() {
@@ -423,6 +446,161 @@ async function generateCommand(parsed, io) {
423
446
  const body = result.json;
424
447
  writeOut(io, isJson(parsed.flags), body, `Created ${body.path}${body.dataPath ? ` from ${body.dataPath}` : ""}`);
425
448
  }
449
+ async function diffCommand(parsed, io) {
450
+ const itemPath = parsed.positionals[0];
451
+ const from = flagString(parsed.flags, "from");
452
+ if (!itemPath || !from) throw new CliError("diff needs a path and --from <id|name|current>.");
453
+ const to = flagString(parsed.flags, "to") ?? "current";
454
+ const format = (flagString(parsed.flags, "format") ?? (isJson(parsed.flags) ? "json" : "md")).toLowerCase();
455
+ if (format !== "md" && format !== "json" && format !== "svg") {
456
+ throw new CliError("format must be md, json, or svg.");
457
+ }
458
+ const { base, token } = configOf(parsed.flags, io.env);
459
+ const apiPath = `/api/v1/history/diff?path=${encodeURIComponent(itemPath)}&from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
460
+ const result = await callApi(base, requireToken(token), "GET", apiPath);
461
+ const body = result.json;
462
+ if (format === "svg") {
463
+ const output2 = flagString(parsed.flags, "output");
464
+ if (!output2) throw new CliError("diff --format svg needs -o file.svg.");
465
+ if (!output2.toLowerCase().endsWith(".svg")) throw new CliError("The output file must end in .svg.");
466
+ if (!body.visualSource) {
467
+ throw new CliError(body.note ?? "This diagram has no visual diff. Use --format md or json.");
468
+ }
469
+ const { renderDiagram } = await loadRender();
470
+ const rendered = await renderDiagram({ source: body.visualSource, format: "svg" });
471
+ await fs.mkdir(path.dirname(path.resolve(output2)), { recursive: true });
472
+ await fs.writeFile(output2, rendered.body);
473
+ writeOut(
474
+ io,
475
+ isJson(parsed.flags),
476
+ { path: itemPath, from, to, output: output2, format, summary: body.summary ?? [] },
477
+ `Wrote ${output2}`
478
+ );
479
+ return;
480
+ }
481
+ if (format === "json") {
482
+ writeOut(io, true, body ?? {}, "");
483
+ return;
484
+ }
485
+ const markdown = body.markdown ?? (body.summary ?? []).map((line) => `- ${line}`).join("\n");
486
+ const output = flagString(parsed.flags, "output");
487
+ if (output) {
488
+ await fs.mkdir(path.dirname(path.resolve(output)), { recursive: true });
489
+ await fs.writeFile(output, markdown.endsWith("\n") ? markdown : `${markdown}
490
+ `, "utf8");
491
+ writeOut(io, isJson(parsed.flags), { path: itemPath, from, to, output, format, summary: body.summary ?? [] }, `Wrote ${output}`);
492
+ return;
493
+ }
494
+ writeOut(io, isJson(parsed.flags), { path: itemPath, from, to, format, markdown, summary: body.summary ?? [] }, markdown);
495
+ }
496
+ async function baselineCommand(parsed, io) {
497
+ const itemPath = parsed.positionals[0];
498
+ const name = flagString(parsed.flags, "name");
499
+ if (!itemPath || !name) throw new CliError('baseline needs a path and --name "\u2026".');
500
+ const note = flagString(parsed.flags, "note");
501
+ const id = flagString(parsed.flags, "id");
502
+ const { base, token } = configOf(parsed.flags, io.env);
503
+ const result = await callApi(base, requireToken(token), "POST", "/api/v1/history/baseline", {
504
+ path: itemPath,
505
+ name,
506
+ ...id ? { id } : {},
507
+ ...note != null ? { note } : {}
508
+ });
509
+ const body = result.json;
510
+ writeOut(
511
+ io,
512
+ isJson(parsed.flags),
513
+ body && typeof body === "object" ? body : {},
514
+ `Saved baseline ${body.name ?? name}${body.id ? ` (${body.id})` : ""}.`
515
+ );
516
+ }
517
+ function skipLabel(reason) {
518
+ switch (reason) {
519
+ case "locked":
520
+ return "open in an editor";
521
+ case "changed":
522
+ return "changed since the preview";
523
+ case "edited":
524
+ return "edited since the replace";
525
+ case "hidden":
526
+ case "meta":
527
+ case "not-diagram":
528
+ return "not a workspace diagram";
529
+ default:
530
+ return reason;
531
+ }
532
+ }
533
+ async function replaceCommand(parsed, io) {
534
+ const { base, token } = configOf(parsed.flags, io.env);
535
+ const undo = flagString(parsed.flags, "undo");
536
+ if (undo) {
537
+ const result2 = await callApi(base, requireToken(token), "POST", "/api/v1/replace/undo", { id: undo });
538
+ const body2 = result2.json;
539
+ const restored = body2.restored ?? [];
540
+ const skipped = (body2.skipped ?? []).filter((item) => item.reason !== "none");
541
+ const lines2 = [`Restored ${restored.length} diagram${restored.length === 1 ? "" : "s"}.`];
542
+ for (const item of skipped) lines2.push(`Skipped ${item.path} (${skipLabel(item.reason)}).`);
543
+ for (const item of body2.errors ?? []) lines2.push(`${item.path}: ${item.message}`);
544
+ writeOut(io, isJson(parsed.flags), body2 ?? {}, lines2.join("\n"));
545
+ return;
546
+ }
547
+ if (parsed.flags.get("dry-run") === true && parsed.flags.get("yes") === true) {
548
+ throw new CliError("Use either --dry-run or --yes.");
549
+ }
550
+ const find = parsed.positionals[0];
551
+ const replace = parsed.positionals[1];
552
+ if (find == null || replace == null) throw new CliError("replace needs the text to find and the replacement.");
553
+ const folder = flagString(parsed.flags, "folder");
554
+ const request = {
555
+ find,
556
+ replace,
557
+ matchCase: parsed.flags.get("match-case") === true,
558
+ wholeWord: parsed.flags.get("whole-word") === true,
559
+ regex: parsed.flags.get("regex") === true,
560
+ includeFrontMatter: parsed.flags.get("front-matter") === true,
561
+ scope: {
562
+ ...folder ? { folder } : {},
563
+ ...parsed.flags.get("no-recursive") === true ? { recursive: false } : {}
564
+ }
565
+ };
566
+ const preview = await callApi(base, requireToken(token), "POST", "/api/v1/replace/preview", request);
567
+ const body = preview.json;
568
+ const files = body.files ?? [];
569
+ const totals = body.totals ?? { replacements: 0, diagrams: 0, shown: 0 };
570
+ if (parsed.flags.get("yes") !== true) {
571
+ const lines2 = [`${totals.replacements} replacement${totals.replacements === 1 ? "" : "s"} in ${totals.diagrams} diagram${totals.diagrams === 1 ? "" : "s"}.`];
572
+ if (body.message) lines2.push(body.message);
573
+ for (const file of files) {
574
+ const notes = [file.selected ? "" : "left unchecked"];
575
+ if (file.lint.invalid) notes.push("would not parse");
576
+ if (file.generatedWarning) notes.push(file.generatedWarning);
577
+ const suffix = notes.filter(Boolean).join("; ");
578
+ lines2.push(`${file.path} (${file.matchCount})${suffix ? ` \u2014 ${suffix}` : ""}`);
579
+ for (const match of file.matches) {
580
+ const warn = match.warnings.length ? ` [${match.warnings.join(", ")}]` : "";
581
+ lines2.push(` ${match.line}: ${match.before} \u2192 ${match.after}${warn}`);
582
+ }
583
+ }
584
+ lines2.push("Nothing was written. Pass --yes to apply.");
585
+ writeOut(io, isJson(parsed.flags), preview.json ?? {}, lines2.join("\n"));
586
+ return;
587
+ }
588
+ const selected = files.filter((file) => file.selected).map((file) => ({ path: file.path, hash: file.hash }));
589
+ const applied = await callApi(base, requireToken(token), "POST", "/api/v1/replace/apply", { ...request, files: selected });
590
+ const result = applied.json;
591
+ const changed = result.totals ?? { diagrams: 0, replacements: 0 };
592
+ const lines = [`Replaced ${changed.replacements} in ${changed.diagrams} diagram${changed.diagrams === 1 ? "" : "s"}.`];
593
+ for (const item of (result.skipped ?? []).filter((entry) => entry.reason !== "none")) {
594
+ lines.push(`Skipped ${item.path} (${skipLabel(item.reason)}).`);
595
+ }
596
+ for (const item of result.errors ?? []) lines.push(`${item.path}: ${item.message}`);
597
+ const leftOut = files.filter((file) => !file.selected);
598
+ if (leftOut.length > 0) {
599
+ lines.push(`Left out ${leftOut.length} diagram${leftOut.length === 1 ? "" : "s"} that would not parse.`);
600
+ }
601
+ if (result.operationId) lines.push(`Undo with nerdgram replace --undo ${result.operationId}`);
602
+ writeOut(io, isJson(parsed.flags), applied.json ?? {}, lines.join("\n"));
603
+ }
426
604
  async function refreshCommand(parsed, io) {
427
605
  const diagramPath = parsed.positionals[0] ?? flagString(parsed.flags, "path");
428
606
  if (!diagramPath) throw new CliError("refresh needs a diagram path.");
@@ -500,6 +678,15 @@ async function main(argv, io = {}) {
500
678
  case "refresh":
501
679
  await refreshCommand(parsed, streams);
502
680
  return 0;
681
+ case "diff":
682
+ await diffCommand(parsed, streams);
683
+ return 0;
684
+ case "baseline":
685
+ await baselineCommand(parsed, streams);
686
+ return 0;
687
+ case "replace":
688
+ await replaceCommand(parsed, streams);
689
+ return 0;
503
690
  default:
504
691
  throw new CliError(`Unknown command ${parsed.command}. Run nerdgram --help.`);
505
692
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nerdgram1337",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "Command-line client for a local NerdGram1337 server",
5
5
  "type": "module",
6
6
  "license": "MIT",
File without changes