nerdgram1337 1.3.0 → 1.4.1
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 +1 -1
- package/dist/{chunk-5EV3XFVE.js → chunk-YNM3RGIQ.js} +5 -0
- package/dist/cli.js +62 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ nerdgram render Welcome.mmd -o Welcome.svg
|
|
|
45
45
|
|
|
46
46
|
The app still has to be reachable for every other command. NerdGram is a single-user app. The API is a tool port for programs you trust, not an always-on multi-user server. The browser routes have no token, so anyone who can reach the port can use them. The default URL is loopback. Point `NERDGRAM_URL` at another machine only when that machine has opened its Host setting to you.
|
|
47
47
|
|
|
48
|
-
The full command list
|
|
48
|
+
The full command list is in the [command-line tool](https://github.com/NetworkNerd1337/NerdGram1337/blob/main/docs/cli.md) page. Release notes are in the [changelog](https://github.com/NetworkNerd1337/NerdGram1337/blob/main/CHANGELOG.md).
|
|
49
49
|
|
|
50
50
|
## License
|
|
51
51
|
|
|
@@ -10,6 +10,11 @@ import puppeteer from "puppeteer";
|
|
|
10
10
|
// server/src/paths.ts
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
// server/src/instanceConfig.ts
|
|
15
|
+
var processStartDataDir = process.env.NERDGRAM_DATA_DIR?.trim() || null;
|
|
16
|
+
|
|
17
|
+
// server/src/paths.ts
|
|
13
18
|
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
19
|
var REPO_ROOT = path.resolve(__dirname, "../..");
|
|
15
20
|
|
package/dist/cli.js
CHANGED
|
@@ -22,7 +22,8 @@ var BOOL_FLAGS = /* @__PURE__ */ new Set([
|
|
|
22
22
|
"copy-data",
|
|
23
23
|
"share-data",
|
|
24
24
|
"with-data",
|
|
25
|
-
"keep-data"
|
|
25
|
+
"keep-data",
|
|
26
|
+
"include-down"
|
|
26
27
|
]);
|
|
27
28
|
var HELP = `nerdgram \u2014 automation client for NerdGram1337
|
|
28
29
|
|
|
@@ -41,6 +42,8 @@ Usage
|
|
|
41
42
|
nerdgram repair-links [--dry-run] [--apply]
|
|
42
43
|
nerdgram generate --path Diagram.mmd --data data.csv
|
|
43
44
|
nerdgram generate --path Diagram.mmd --data neighbors.lldp --format lldp --local-device edge-sw
|
|
45
|
+
nerdgram generate --path Campus-L3.mmd --data campus.network.json --format network --view l3
|
|
46
|
+
nerdgram generate --path Campus-L2.mmd --data campus.network.json --format network --view l2 --group-by site
|
|
44
47
|
nerdgram refresh <path> [--data data.csv]
|
|
45
48
|
nerdgram diff <path> --from <id|name|current> [--to <id|name|current>] [--format md|json|svg]
|
|
46
49
|
nerdgram baseline <path> --name "\u2026" [--note "\u2026"] [--id <revision>]
|
|
@@ -51,9 +54,10 @@ A local .mmd file is rendered and linted in this process. Anything else uses
|
|
|
51
54
|
NERDGRAM_URL (default http://127.0.0.1:8787) and NERDGRAM_TOKEN.
|
|
52
55
|
--url and --token override those. --json prints one JSON object.
|
|
53
56
|
--server forces render to use the API. Exit status is 1 on errors.
|
|
54
|
-
Rename and move also move a CSV, JSON, CDP, or LLDP file that
|
|
55
|
-
diagram and update nerdgram.source. duplicate --copy-data
|
|
56
|
-
own data file. duplicate --share-data keeps both diagrams
|
|
57
|
+
Rename and move also move a CSV, JSON, network JSON, CDP, or LLDP file that
|
|
58
|
+
sits next to the diagram and update nerdgram.source. duplicate --copy-data
|
|
59
|
+
gives the copy its own data file. duplicate --share-data keeps both diagrams
|
|
60
|
+
on the original file.
|
|
57
61
|
delete --with-data moves that file to the trash with the diagram.
|
|
58
62
|
delete --keep-data leaves it in the workspace. When a data file is present and
|
|
59
63
|
the flag is omitted, duplicate and delete stop and list the file.
|
|
@@ -77,7 +81,7 @@ not changed. --undo restores that replace and skips a file edited since.
|
|
|
77
81
|
`;
|
|
78
82
|
var renderModule = null;
|
|
79
83
|
function loadRender() {
|
|
80
|
-
renderModule ??= import("./chunk-
|
|
84
|
+
renderModule ??= import("./chunk-YNM3RGIQ.js");
|
|
81
85
|
return renderModule;
|
|
82
86
|
}
|
|
83
87
|
async function loadLint() {
|
|
@@ -90,11 +94,35 @@ async function shutdownCli() {
|
|
|
90
94
|
}
|
|
91
95
|
var CliError = class extends Error {
|
|
92
96
|
status;
|
|
93
|
-
|
|
97
|
+
details;
|
|
98
|
+
constructor(message, status, details) {
|
|
94
99
|
super(message);
|
|
95
100
|
this.status = status;
|
|
101
|
+
this.details = details;
|
|
96
102
|
}
|
|
97
103
|
};
|
|
104
|
+
function formatRowIssues(errors) {
|
|
105
|
+
if (!Array.isArray(errors)) return [];
|
|
106
|
+
const lines = [];
|
|
107
|
+
for (const item of errors) {
|
|
108
|
+
if (!item || typeof item !== "object") continue;
|
|
109
|
+
const issue = item;
|
|
110
|
+
if (typeof issue.message !== "string" || !issue.message.trim()) continue;
|
|
111
|
+
const message = issue.message.trim();
|
|
112
|
+
const field = typeof issue.path === "string" ? issue.path.trim() : "";
|
|
113
|
+
if (field && !message.includes(field)) {
|
|
114
|
+
lines.push(`${field}: ${message}`);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const row = typeof issue.row === "number" ? issue.row : 0;
|
|
118
|
+
if (row > 0 && !message.toLowerCase().includes(`row ${row}`)) {
|
|
119
|
+
lines.push(`row ${row}: ${message}`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
lines.push(message);
|
|
123
|
+
}
|
|
124
|
+
return lines;
|
|
125
|
+
}
|
|
98
126
|
function parseArgs(argv) {
|
|
99
127
|
const flags = /* @__PURE__ */ new Map();
|
|
100
128
|
const positionals = [];
|
|
@@ -184,8 +212,11 @@ async function callApi(base, token, method, apiPath, body) {
|
|
|
184
212
|
}
|
|
185
213
|
if (!response.ok) {
|
|
186
214
|
const record = json && typeof json === "object" ? json : {};
|
|
187
|
-
const
|
|
188
|
-
|
|
215
|
+
const summary = typeof record.error === "string" ? record.error : `Request failed (${response.status})`;
|
|
216
|
+
const rows = formatRowIssues(record.errors);
|
|
217
|
+
const message = rows.length > 0 ? `${summary}
|
|
218
|
+
${rows.join("\n")}` : summary;
|
|
219
|
+
throw new CliError(message, response.status, record);
|
|
189
220
|
}
|
|
190
221
|
return { status: response.status, json, bytes, contentType };
|
|
191
222
|
}
|
|
@@ -423,25 +454,36 @@ async function deleteCommand(parsed, io) {
|
|
|
423
454
|
...keepData ? { deleteData: false } : {}
|
|
424
455
|
});
|
|
425
456
|
const body = result.json;
|
|
426
|
-
|
|
457
|
+
const kept = body.message ? ` ${body.message}` : "";
|
|
458
|
+
writeOut(io, isJson(parsed.flags), body, `Moved ${body.path ?? itemPath} to the trash.${kept}`);
|
|
427
459
|
}
|
|
428
460
|
async function generateCommand(parsed, io) {
|
|
429
461
|
const diagramPath = flagString(parsed.flags, "path") ?? parsed.positionals[0];
|
|
430
462
|
const dataFile = flagString(parsed.flags, "data");
|
|
431
463
|
if (!diagramPath || !dataFile) {
|
|
432
|
-
throw new CliError("generate needs --path Diagram.mmd and --data file.csv, file.json, file.cdp, or file.lldp.");
|
|
464
|
+
throw new CliError("generate needs --path Diagram.mmd and --data file.csv, file.json, file.network.json, file.cdp, or file.lldp.");
|
|
465
|
+
}
|
|
466
|
+
const format = flagString(parsed.flags, "format");
|
|
467
|
+
const view = flagString(parsed.flags, "view");
|
|
468
|
+
if (format === "network" && view !== "l3" && view !== "l2") {
|
|
469
|
+
throw new CliError("generate --format network needs --view l3 or --view l2.");
|
|
433
470
|
}
|
|
471
|
+
const vlanText = flagString(parsed.flags, "vlan");
|
|
472
|
+
if (vlanText != null && !/^\d+$/.test(vlanText)) throw new CliError("vlan must be an integer from 1 to 4094.");
|
|
434
473
|
const text = await fs.readFile(dataFile, "utf8");
|
|
435
474
|
const { base, token } = configOf(parsed.flags, io.env);
|
|
436
475
|
const result = await callApi(base, requireToken(token), "POST", "/api/v1/generate", {
|
|
437
476
|
path: diagramPath,
|
|
438
477
|
text,
|
|
439
|
-
format
|
|
478
|
+
format,
|
|
440
479
|
shape: flagString(parsed.flags, "shape"),
|
|
441
480
|
direction: flagString(parsed.flags, "direction"),
|
|
442
481
|
title: flagString(parsed.flags, "title"),
|
|
443
482
|
localDevice: flagString(parsed.flags, "local-device"),
|
|
444
|
-
groupBy: flagString(parsed.flags, "group-by")
|
|
483
|
+
groupBy: flagString(parsed.flags, "group-by"),
|
|
484
|
+
view,
|
|
485
|
+
...parsed.flags.get("include-down") === true ? { includeDown: true } : {},
|
|
486
|
+
...vlanText != null ? { vlan: Number(vlanText) } : {}
|
|
445
487
|
});
|
|
446
488
|
const body = result.json;
|
|
447
489
|
writeOut(io, isJson(parsed.flags), body, `Created ${body.path}${body.dataPath ? ` from ${body.dataPath}` : ""}`);
|
|
@@ -693,9 +735,13 @@ async function main(argv, io = {}) {
|
|
|
693
735
|
} catch (err) {
|
|
694
736
|
const message = err instanceof Error ? err.message : String(err);
|
|
695
737
|
const status = err instanceof CliError ? err.status : void 0;
|
|
696
|
-
if (isJson(parsed.flags))
|
|
697
|
-
|
|
698
|
-
|
|
738
|
+
if (isJson(parsed.flags)) {
|
|
739
|
+
const errors = err instanceof CliError && Array.isArray(err.details?.errors) ? err.details.errors : void 0;
|
|
740
|
+
streams.stdout(
|
|
741
|
+
`${JSON.stringify({ ok: false, error: message, status: status ?? null, ...errors ? { errors } : {} })}
|
|
742
|
+
`
|
|
743
|
+
);
|
|
744
|
+
} else streams.stderr(`${message}
|
|
699
745
|
`);
|
|
700
746
|
return 1;
|
|
701
747
|
}
|
|
@@ -718,6 +764,7 @@ if (isDirectRun()) {
|
|
|
718
764
|
});
|
|
719
765
|
}
|
|
720
766
|
export {
|
|
767
|
+
formatRowIssues,
|
|
721
768
|
main,
|
|
722
769
|
shutdownCli
|
|
723
770
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nerdgram1337",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Command-line client for a local NerdGram1337 server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"url": "git+https://github.com/NetworkNerd1337/NerdGram1337.git",
|
|
24
24
|
"directory": "cli"
|
|
25
25
|
},
|
|
26
|
-
"homepage": "https://github.com/NetworkNerd1337/NerdGram1337
|
|
26
|
+
"homepage": "https://github.com/NetworkNerd1337/NerdGram1337/blob/main/docs/cli.md",
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/NetworkNerd1337/NerdGram1337/issues"
|
|
29
29
|
},
|