nerdgram1337 0.0.0-stage → 1.1.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/dist/cli.js ADDED
@@ -0,0 +1,536 @@
1
+ #!/usr/bin/env node
2
+
3
+ // server/src/cli.ts
4
+ import fs from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ var BOOL_FLAGS = /* @__PURE__ */ new Set([
8
+ "json",
9
+ "server",
10
+ "strict",
11
+ "help",
12
+ "h",
13
+ "no-update-links",
14
+ "dry-run",
15
+ "apply",
16
+ "copy-data",
17
+ "share-data",
18
+ "with-data",
19
+ "keep-data"
20
+ ]);
21
+ var HELP = `nerdgram \u2014 automation client for NerdGram1337
22
+
23
+ Usage
24
+ nerdgram render <file|path> -o out.svg|png
25
+ nerdgram list [folder]
26
+ nerdgram search <query>
27
+ nerdgram get <path> [-o file]
28
+ nerdgram put <path> <file>
29
+ nerdgram export <folder> -o dir/
30
+ nerdgram lint [path|file] [--strict]
31
+ nerdgram rename <from> <to>
32
+ nerdgram move <from> [folder]
33
+ nerdgram duplicate <path> (--copy-data | --share-data)
34
+ nerdgram delete <path> (--with-data | --keep-data)
35
+ nerdgram repair-links [--dry-run] [--apply]
36
+ nerdgram generate --path Diagram.mmd --data data.csv
37
+ nerdgram generate --path Diagram.mmd --data neighbors.lldp --format lldp --local-device edge-sw
38
+ nerdgram refresh <path> [--data data.csv]
39
+
40
+ A local .mmd file is rendered and linted in this process. Anything else uses
41
+ NERDGRAM_URL (default http://127.0.0.1:8787) and NERDGRAM_TOKEN.
42
+ --url and --token override those. --json prints one JSON object.
43
+ --server forces render to use the API. Exit status is 1 on errors.
44
+ Rename and move also move a CSV, JSON, CDP, or LLDP file that sits next to the
45
+ diagram and update nerdgram.source. duplicate --copy-data gives the copy its
46
+ own data file. duplicate --share-data keeps both diagrams on the original file.
47
+ delete --with-data moves that file to the trash with the diagram.
48
+ delete --keep-data leaves it in the workspace. When a data file is present and
49
+ the flag is omitted, duplicate and delete stop and list the file.
50
+ repair-links previews click repairs after a rename or move made outside the
51
+ app. --dry-run is the default and writes nothing. --apply saves the previewed
52
+ rewrites. If the data file moved with that diagram, the same confirmation
53
+ updates nerdgram.source. An ambiguous match is listed and left unchanged.
54
+ `;
55
+ var renderModule = null;
56
+ function loadRender() {
57
+ renderModule ??= import("./chunk-ZH7YZLR3.js");
58
+ return renderModule;
59
+ }
60
+ async function loadLint() {
61
+ return import("./chunk-EGA2UGTF.js");
62
+ }
63
+ async function shutdownCli() {
64
+ if (!renderModule) return;
65
+ const { closeRenderer } = await renderModule;
66
+ await closeRenderer();
67
+ }
68
+ var CliError = class extends Error {
69
+ status;
70
+ constructor(message, status) {
71
+ super(message);
72
+ this.status = status;
73
+ }
74
+ };
75
+ function parseArgs(argv) {
76
+ const flags = /* @__PURE__ */ new Map();
77
+ const positionals = [];
78
+ let command = "";
79
+ for (let index = 0; index < argv.length; index += 1) {
80
+ const arg = argv[index] ?? "";
81
+ if (arg === "--") {
82
+ positionals.push(...argv.slice(index + 1));
83
+ break;
84
+ }
85
+ if (arg.startsWith("--")) {
86
+ const eq = arg.indexOf("=");
87
+ const rawName = eq === -1 ? arg.slice(2) : arg.slice(2, eq);
88
+ const name = rawName === "o" ? "output" : rawName;
89
+ if (BOOL_FLAGS.has(rawName) && eq === -1) {
90
+ flags.set(name, true);
91
+ continue;
92
+ }
93
+ const value = eq === -1 ? argv[index + 1] : arg.slice(eq + 1);
94
+ if (eq === -1) index += 1;
95
+ if (value == null || value.startsWith("-")) throw new CliError(`Missing value for --${rawName}`);
96
+ flags.set(name, BOOL_FLAGS.has(rawName) ? value !== "false" : value);
97
+ continue;
98
+ }
99
+ if (arg === "-h") {
100
+ flags.set("help", true);
101
+ continue;
102
+ }
103
+ if (arg === "-o") {
104
+ const value = argv[index + 1];
105
+ index += 1;
106
+ if (value == null || value.startsWith("-")) throw new CliError("Missing value for -o");
107
+ flags.set("output", value);
108
+ continue;
109
+ }
110
+ if (!command) command = arg;
111
+ else positionals.push(arg);
112
+ }
113
+ return { command, positionals, flags };
114
+ }
115
+ function flagString(flags, name) {
116
+ const value = flags.get(name);
117
+ return typeof value === "string" ? value : void 0;
118
+ }
119
+ function isJson(flags) {
120
+ return flags.get("json") === true;
121
+ }
122
+ function writeOut(io, json, payload, human) {
123
+ if (json) io.stdout(`${JSON.stringify({ ok: true, ...payload })}
124
+ `);
125
+ else io.stdout(human.endsWith("\n") ? human : `${human}
126
+ `);
127
+ }
128
+ function configOf(flags, env) {
129
+ const base = (flagString(flags, "url") ?? env.NERDGRAM_URL ?? "http://127.0.0.1:8787").replace(/\/+$/, "");
130
+ const token = flagString(flags, "token") ?? env.NERDGRAM_TOKEN ?? "";
131
+ return { base, token };
132
+ }
133
+ function requireToken(token) {
134
+ if (!token.trim()) throw new CliError("Set NERDGRAM_TOKEN or pass --token.");
135
+ return token.trim();
136
+ }
137
+ async function callApi(base, token, method, apiPath, body) {
138
+ const headers = {};
139
+ if (token) headers.Authorization = `Bearer ${token}`;
140
+ if (body !== void 0 || method !== "GET") headers["Content-Type"] = "application/json";
141
+ let response;
142
+ try {
143
+ response = await fetch(`${base}${apiPath}`, {
144
+ method,
145
+ headers,
146
+ body: body === void 0 ? method === "GET" ? void 0 : "{}" : JSON.stringify(body)
147
+ });
148
+ } catch (err) {
149
+ const message = err instanceof Error ? err.message : String(err);
150
+ throw new CliError(`Could not reach ${base}. ${message}`);
151
+ }
152
+ const bytes = Buffer.from(await response.arrayBuffer());
153
+ const contentType = response.headers.get("content-type") ?? "";
154
+ let json = void 0;
155
+ if (contentType.includes("json") || !contentType.includes("image/") && bytes.length > 0 && bytes[0] === 123) {
156
+ try {
157
+ json = JSON.parse(bytes.toString("utf8"));
158
+ } catch {
159
+ json = void 0;
160
+ }
161
+ }
162
+ if (!response.ok) {
163
+ const record = json && typeof json === "object" ? json : {};
164
+ const message = typeof record.error === "string" ? record.error : `Request failed (${response.status})`;
165
+ throw new CliError(message, response.status);
166
+ }
167
+ return { status: response.status, json, bytes, contentType };
168
+ }
169
+ function formatOf(output) {
170
+ const lower = output.toLowerCase();
171
+ if (lower.endsWith(".svg")) return "svg";
172
+ if (lower.endsWith(".png")) return "png";
173
+ throw new CliError("The output file must end in .svg or .png.");
174
+ }
175
+ async function pathExists(file) {
176
+ try {
177
+ const stat = await fs.stat(file);
178
+ return stat.isFile();
179
+ } catch {
180
+ return false;
181
+ }
182
+ }
183
+ async function renderCommand(parsed, io) {
184
+ const target = parsed.positionals[0];
185
+ const output = flagString(parsed.flags, "output");
186
+ if (!target) throw new CliError("render needs a file or a workspace path.");
187
+ if (!output) throw new CliError("render needs -o out.svg or -o out.png.");
188
+ const format = formatOf(output);
189
+ const local = !parsed.flags.get("server") && await pathExists(target);
190
+ let bytes;
191
+ if (local) {
192
+ const source = await fs.readFile(target, "utf8");
193
+ const { renderDiagram } = await loadRender();
194
+ const rendered = await renderDiagram({ source, format });
195
+ bytes = rendered.body;
196
+ } else {
197
+ const { base, token } = configOf(parsed.flags, io.env);
198
+ const result = await callApi(base, requireToken(token), "POST", "/api/v1/render", { path: target, format });
199
+ bytes = result.bytes;
200
+ }
201
+ await fs.mkdir(path.dirname(path.resolve(output)), { recursive: true });
202
+ await fs.writeFile(output, bytes);
203
+ writeOut(io, isJson(parsed.flags), { output, format, bytes: bytes.length, offline: local }, `Wrote ${output}`);
204
+ }
205
+ async function listCommand(parsed, io) {
206
+ const { base, token } = configOf(parsed.flags, io.env);
207
+ const folder = parsed.positionals[0] ?? "";
208
+ const result = await callApi(base, requireToken(token), "GET", `/api/v1/diagrams?path=${encodeURIComponent(folder)}`);
209
+ const body = result.json;
210
+ const lines = [
211
+ ...(body.folders ?? []).map((item) => `${item.path}/`),
212
+ ...(body.files ?? []).map((item) => item.path)
213
+ ];
214
+ writeOut(io, isJson(parsed.flags), { path: body.path ?? folder, folders: body.folders ?? [], files: body.files ?? [] }, lines.join("\n") || "(empty)");
215
+ }
216
+ async function searchCommand(parsed, io) {
217
+ const query = parsed.positionals.join(" ").trim();
218
+ if (!query) throw new CliError("search needs a query.");
219
+ const { base, token } = configOf(parsed.flags, io.env);
220
+ const result = await callApi(base, requireToken(token), "GET", `/api/v1/search?q=${encodeURIComponent(query)}`);
221
+ const body = result.json;
222
+ const lines = (body.hits ?? []).map((hit) => `${hit.path}:${hit.line ?? 1}: ${hit.snippet}`);
223
+ writeOut(io, isJson(parsed.flags), { query, hits: body.hits ?? [] }, lines.join("\n") || "(no matches)");
224
+ }
225
+ async function getCommand(parsed, io) {
226
+ const itemPath = parsed.positionals[0];
227
+ if (!itemPath) throw new CliError("get needs a workspace path.");
228
+ const { base, token } = configOf(parsed.flags, io.env);
229
+ const result = await callApi(base, requireToken(token), "GET", `/api/v1/diagrams/content?path=${encodeURIComponent(itemPath)}`);
230
+ const body = result.json;
231
+ const output = flagString(parsed.flags, "output");
232
+ if (output) {
233
+ await fs.mkdir(path.dirname(path.resolve(output)), { recursive: true });
234
+ await fs.writeFile(output, body.content, "utf8");
235
+ }
236
+ writeOut(
237
+ io,
238
+ isJson(parsed.flags),
239
+ { path: body.path, hash: body.hash, mtimeMs: body.mtimeMs, content: body.content, output: output ?? null },
240
+ output ? `Wrote ${output}` : body.content
241
+ );
242
+ }
243
+ async function putCommand(parsed, io) {
244
+ const itemPath = parsed.positionals[0];
245
+ const file = parsed.positionals[1];
246
+ if (!itemPath || !file) throw new CliError("put needs a workspace path and a local file.");
247
+ const content = await fs.readFile(file, "utf8");
248
+ const { base, token } = configOf(parsed.flags, io.env);
249
+ const result = await callApi(base, requireToken(token), "PUT", "/api/v1/diagrams", { path: itemPath, content, force: true });
250
+ const body = result.json;
251
+ writeOut(io, isJson(parsed.flags), { path: body.path, hash: body.hash ?? null }, `Wrote ${body.path}`);
252
+ }
253
+ async function exportCommand(parsed, io) {
254
+ const folder = parsed.positionals[0] ?? "";
255
+ const output = flagString(parsed.flags, "output");
256
+ if (!output) throw new CliError("export needs -o directory.");
257
+ const { base, token } = configOf(parsed.flags, io.env);
258
+ const result = await callApi(base, requireToken(token), "GET", `/api/v1/export?path=${encodeURIComponent(folder)}`);
259
+ const body = result.json;
260
+ const root = path.resolve(output);
261
+ await fs.mkdir(root, { recursive: true });
262
+ let count = 0;
263
+ for (const file of body.files ?? []) {
264
+ const destination = path.resolve(root, file.path);
265
+ const relative = path.relative(root, destination);
266
+ if (relative.startsWith("..") || path.isAbsolute(relative)) throw new CliError(`Refusing to write ${file.path}`);
267
+ await fs.mkdir(path.dirname(destination), { recursive: true });
268
+ await fs.writeFile(destination, file.content, "utf8");
269
+ count += 1;
270
+ }
271
+ writeOut(io, isJson(parsed.flags), { path: folder, output, count }, `Exported ${count} diagram${count === 1 ? "" : "s"} to ${output}`);
272
+ }
273
+ async function lintCommand(parsed, io) {
274
+ const target = parsed.positionals[0] ?? flagString(parsed.flags, "source");
275
+ const strict = parsed.flags.get("strict") === true;
276
+ let diagnostics;
277
+ let label = target ?? "(workspace)";
278
+ if (target && (flagString(parsed.flags, "source") || await pathExists(target))) {
279
+ const source = await fs.readFile(target, "utf8");
280
+ const { lintDiagramSource } = await loadLint();
281
+ diagnostics = await lintDiagramSource(source, { sourcePath: target });
282
+ label = target;
283
+ } else {
284
+ const { base, token } = configOf(parsed.flags, io.env);
285
+ const apiPath = target ? `/api/v1/lint?path=${encodeURIComponent(target)}` : "/api/v1/lint";
286
+ const result = await callApi(base, requireToken(token), "GET", apiPath);
287
+ const body = result.json;
288
+ if (body.diagrams) {
289
+ diagnostics = body.diagrams.flatMap(
290
+ (diagram) => diagram.diagnostics.map((item) => ({ ...item, message: `${diagram.path}: ${item.message}` }))
291
+ );
292
+ writeOut(
293
+ io,
294
+ isJson(parsed.flags),
295
+ { checked: body.checked ?? 0, diagrams: body.diagrams },
296
+ diagnostics.map((item) => `${item.ruleId}: ${item.message}`).join("\n") || `Checked ${body.checked ?? 0} diagrams.`
297
+ );
298
+ const failed2 = body.diagrams.some(
299
+ (diagram) => diagram.diagnostics.some((item) => item.severity === "error" || strict && diagram.diagnostics.length > 0)
300
+ );
301
+ return failed2 ? 1 : 0;
302
+ }
303
+ diagnostics = body.diagnostics ?? [];
304
+ }
305
+ const lines = diagnostics.map((item) => `${label}:${item.line}: ${item.severity}: ${item.ruleId}: ${item.message}`);
306
+ writeOut(io, isJson(parsed.flags), { path: label, diagnostics }, lines.join("\n") || "No problems.");
307
+ const failed = diagnostics.some((item) => item.severity === "error" || strict && diagnostics.length > 0);
308
+ return failed ? 1 : 0;
309
+ }
310
+ async function repairLinksCommand(parsed, io) {
311
+ const apply = parsed.flags.get("apply") === true && parsed.flags.get("dry-run") !== true;
312
+ const { base, token } = configOf(parsed.flags, io.env);
313
+ const result = apply ? await callApi(base, requireToken(token), "POST", "/api/v1/link-repairs", { dryRun: false, confirm: true }) : await callApi(base, requireToken(token), "GET", "/api/v1/link-repairs");
314
+ const body = result.json;
315
+ const lines = [];
316
+ for (const change of body.changes ?? []) {
317
+ lines.push(change.path);
318
+ for (const link of change.links) lines.push(` line ${link.line}: ${link.target} -> ${link.next}`);
319
+ }
320
+ const ambiguous = (body.suggestions ?? []).filter((item) => item.to == null || item.match === "ambiguous");
321
+ for (const dataFile of body.dataFiles ?? []) {
322
+ lines.push(`${dataFile.diagram}: ${dataFile.from} -> ${dataFile.to}`);
323
+ }
324
+ if (ambiguous.length > 0) {
325
+ lines.push("Ambiguous, not changed:");
326
+ for (const item of ambiguous) lines.push(` ${item.from} matches ${item.candidates.join(", ")}`);
327
+ }
328
+ if (lines.length === 0) lines.push("No link repairs.");
329
+ else if (!apply) lines.push("Nothing was written. Run nerdgram repair-links --apply to update these files.");
330
+ else if ((body.saved ?? []).length > 0) lines.push(`Updated ${(body.saved ?? []).join(", ")}`);
331
+ else lines.push("No files needed a rewrite.");
332
+ writeOut(
333
+ io,
334
+ isJson(parsed.flags),
335
+ {
336
+ applied: body.applied === true,
337
+ saved: body.saved ?? [],
338
+ suggestions: body.suggestions ?? [],
339
+ changes: body.changes ?? [],
340
+ dataFiles: body.dataFiles ?? []
341
+ },
342
+ lines.join("\n")
343
+ );
344
+ }
345
+ async function renameCommand(parsed, io) {
346
+ const from = parsed.positionals[0];
347
+ const to = parsed.positionals[1];
348
+ if (!from || !to) throw new CliError("rename needs the current path and the new path.");
349
+ const { base, token } = configOf(parsed.flags, io.env);
350
+ const result = await callApi(base, requireToken(token), "POST", "/api/v1/diagrams/rename", {
351
+ from,
352
+ to,
353
+ updateLinks: parsed.flags.get("no-update-links") !== true
354
+ });
355
+ const body = result.json;
356
+ const moved = (body.dataFiles ?? []).map((item) => item.to).join(", ");
357
+ writeOut(io, isJson(parsed.flags), body, moved ? `Renamed ${body.path}. Data file ${moved}.` : `Renamed ${body.path}`);
358
+ }
359
+ async function moveCommand(parsed, io) {
360
+ const from = parsed.positionals[0];
361
+ if (!from) throw new CliError("move needs the diagram or folder to move.");
362
+ const { base, token } = configOf(parsed.flags, io.env);
363
+ const result = await callApi(base, requireToken(token), "POST", "/api/v1/diagrams/move", {
364
+ from,
365
+ toFolder: parsed.positionals[1] ?? "",
366
+ updateLinks: parsed.flags.get("no-update-links") !== true
367
+ });
368
+ const body = result.json;
369
+ const moved = (body.dataFiles ?? []).map((item) => item.to).join(", ");
370
+ writeOut(io, isJson(parsed.flags), body, moved ? `Moved to ${body.path}. Data file ${moved}.` : `Moved to ${body.path}`);
371
+ }
372
+ async function duplicateCommand(parsed, io) {
373
+ const itemPath = parsed.positionals[0];
374
+ if (!itemPath) throw new CliError("duplicate needs a diagram or folder path.");
375
+ const copyData = parsed.flags.get("copy-data") === true;
376
+ const shareData = parsed.flags.get("share-data") === true;
377
+ if (copyData && shareData) throw new CliError("Pass either --copy-data or --share-data.");
378
+ const { base, token } = configOf(parsed.flags, io.env);
379
+ const result = await callApi(base, requireToken(token), "POST", "/api/v1/diagrams/duplicate", {
380
+ path: itemPath,
381
+ ...copyData ? { copyData: true } : {},
382
+ ...shareData ? { copyData: false } : {}
383
+ });
384
+ const body = result.json;
385
+ const copied = (body.dataFiles ?? []).map((item) => item.to).join(", ");
386
+ const human = copied ? `Duplicated as ${body.path}. Data file ${copied}.` : shareData ? `Duplicated as ${body.path}. It shares the original data file.` : `Duplicated as ${body.path}`;
387
+ writeOut(io, isJson(parsed.flags), body, human);
388
+ }
389
+ async function deleteCommand(parsed, io) {
390
+ const itemPath = parsed.positionals[0];
391
+ if (!itemPath) throw new CliError("delete needs a diagram or folder path.");
392
+ const withData = parsed.flags.get("with-data") === true;
393
+ const keepData = parsed.flags.get("keep-data") === true;
394
+ if (withData && keepData) throw new CliError("Pass either --with-data or --keep-data.");
395
+ const { base, token } = configOf(parsed.flags, io.env);
396
+ const result = await callApi(base, requireToken(token), "DELETE", "/api/v1/diagrams", {
397
+ path: itemPath,
398
+ confirmLinks: true,
399
+ ...withData ? { deleteData: true } : {},
400
+ ...keepData ? { deleteData: false } : {}
401
+ });
402
+ const body = result.json;
403
+ writeOut(io, isJson(parsed.flags), body, `Moved ${body.path ?? itemPath} to the trash.`);
404
+ }
405
+ async function generateCommand(parsed, io) {
406
+ const diagramPath = flagString(parsed.flags, "path") ?? parsed.positionals[0];
407
+ const dataFile = flagString(parsed.flags, "data");
408
+ if (!diagramPath || !dataFile) {
409
+ throw new CliError("generate needs --path Diagram.mmd and --data file.csv, file.json, file.cdp, or file.lldp.");
410
+ }
411
+ const text = await fs.readFile(dataFile, "utf8");
412
+ const { base, token } = configOf(parsed.flags, io.env);
413
+ const result = await callApi(base, requireToken(token), "POST", "/api/v1/generate", {
414
+ path: diagramPath,
415
+ text,
416
+ format: flagString(parsed.flags, "format"),
417
+ shape: flagString(parsed.flags, "shape"),
418
+ direction: flagString(parsed.flags, "direction"),
419
+ title: flagString(parsed.flags, "title"),
420
+ localDevice: flagString(parsed.flags, "local-device"),
421
+ groupBy: flagString(parsed.flags, "group-by")
422
+ });
423
+ const body = result.json;
424
+ writeOut(io, isJson(parsed.flags), body, `Created ${body.path}${body.dataPath ? ` from ${body.dataPath}` : ""}`);
425
+ }
426
+ async function refreshCommand(parsed, io) {
427
+ const diagramPath = parsed.positionals[0] ?? flagString(parsed.flags, "path");
428
+ if (!diagramPath) throw new CliError("refresh needs a diagram path.");
429
+ const dataFile = flagString(parsed.flags, "data");
430
+ const text = dataFile ? await fs.readFile(dataFile, "utf8") : void 0;
431
+ const { base, token } = configOf(parsed.flags, io.env);
432
+ const result = await callApi(base, requireToken(token), "POST", "/api/v1/generate/refresh", {
433
+ path: diagramPath,
434
+ text,
435
+ save: true,
436
+ writeData: text != null
437
+ });
438
+ const body = result.json;
439
+ writeOut(io, isJson(parsed.flags), body, `Refreshed ${body.path}`);
440
+ }
441
+ async function main(argv, io = {}) {
442
+ const streams = {
443
+ stdout: io.stdout ?? ((chunk) => process.stdout.write(chunk)),
444
+ stderr: io.stderr ?? ((chunk) => process.stderr.write(chunk)),
445
+ env: io.env ?? process.env
446
+ };
447
+ let parsed;
448
+ try {
449
+ parsed = parseArgs(argv);
450
+ } catch (err) {
451
+ const message = err instanceof Error ? err.message : String(err);
452
+ streams.stderr(`${message}
453
+ `);
454
+ return 1;
455
+ }
456
+ if (parsed.flags.get("help") === true || parsed.command === "help" || parsed.command === "") {
457
+ streams.stdout(HELP);
458
+ return parsed.command === "" && parsed.flags.get("help") !== true && parsed.positionals.length === 0 ? 0 : 0;
459
+ }
460
+ try {
461
+ switch (parsed.command) {
462
+ case "render":
463
+ await renderCommand(parsed, streams);
464
+ return 0;
465
+ case "list":
466
+ await listCommand(parsed, streams);
467
+ return 0;
468
+ case "search":
469
+ await searchCommand(parsed, streams);
470
+ return 0;
471
+ case "get":
472
+ await getCommand(parsed, streams);
473
+ return 0;
474
+ case "put":
475
+ await putCommand(parsed, streams);
476
+ return 0;
477
+ case "export":
478
+ await exportCommand(parsed, streams);
479
+ return 0;
480
+ case "lint":
481
+ return await lintCommand(parsed, streams);
482
+ case "repair-links":
483
+ await repairLinksCommand(parsed, streams);
484
+ return 0;
485
+ case "rename":
486
+ await renameCommand(parsed, streams);
487
+ return 0;
488
+ case "move":
489
+ await moveCommand(parsed, streams);
490
+ return 0;
491
+ case "duplicate":
492
+ await duplicateCommand(parsed, streams);
493
+ return 0;
494
+ case "delete":
495
+ await deleteCommand(parsed, streams);
496
+ return 0;
497
+ case "generate":
498
+ await generateCommand(parsed, streams);
499
+ return 0;
500
+ case "refresh":
501
+ await refreshCommand(parsed, streams);
502
+ return 0;
503
+ default:
504
+ throw new CliError(`Unknown command ${parsed.command}. Run nerdgram --help.`);
505
+ }
506
+ } catch (err) {
507
+ const message = err instanceof Error ? err.message : String(err);
508
+ const status = err instanceof CliError ? err.status : void 0;
509
+ if (isJson(parsed.flags)) streams.stdout(`${JSON.stringify({ ok: false, error: message, status: status ?? null })}
510
+ `);
511
+ else streams.stderr(`${message}
512
+ `);
513
+ return 1;
514
+ }
515
+ }
516
+ function isDirectRun() {
517
+ const entry = process.argv[1];
518
+ if (!entry) return false;
519
+ const invoked = path.resolve(entry);
520
+ const self = fileURLToPath(import.meta.url);
521
+ return invoked === self || invoked.endsWith(`${path.sep}cli.ts`) || invoked.endsWith(`${path.sep}cli.js`);
522
+ }
523
+ if (isDirectRun()) {
524
+ main(process.argv.slice(2)).then(async (code) => {
525
+ await shutdownCli();
526
+ process.exit(code);
527
+ }).catch(async (err) => {
528
+ console.error(err instanceof Error ? err.message : String(err));
529
+ await shutdownCli().catch(() => void 0);
530
+ process.exit(1);
531
+ });
532
+ }
533
+ export {
534
+ main,
535
+ shutdownCli
536
+ };
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "nerdgram1337",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.5",
4
+ "description": "Command-line client for a local NerdGram1337 server",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Ryan Thomas Huff",
8
+ "bin": {
9
+ "nerdgram": "./bin/nerdgram.js"
10
+ },
11
+ "files": [
12
+ "bin",
13
+ "dist",
14
+ "LICENSE",
15
+ "README.md"
16
+ ],
17
+ "engines": {
18
+ "node": ">=20",
19
+ "npm": ">=10"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/NetworkNerd1337/NerdGram1337.git",
24
+ "directory": "cli"
25
+ },
26
+ "homepage": "https://github.com/NetworkNerd1337/NerdGram1337#command-line-tool",
27
+ "bugs": {
28
+ "url": "https://github.com/NetworkNerd1337/NerdGram1337/issues"
29
+ },
30
+ "keywords": [
31
+ "mermaid",
32
+ "diagram",
33
+ "cli",
34
+ "nerdgram"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "provenance": true
39
+ },
40
+ "scripts": {
41
+ "prepack": "node ../scripts/build-cli-package.mjs"
42
+ },
43
+ "dependencies": {
44
+ "cheerio": "^1.2.0",
45
+ "mermaid": "^12.3.0",
46
+ "puppeteer": "^24.43.1",
47
+ "yaml": "^2.9.1"
48
+ },
49
+ "private": false
50
+ }