nerdgram1337 1.7.5 → 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.
@@ -18,7 +18,6 @@ import {
18
18
  matchFrontMatter,
19
19
  parseDiagram
20
20
  } from "./chunk-6LCHDAAN.js";
21
- import "./chunk-MLKGABMK.js";
22
21
 
23
22
  // server/src/mermaidSyntax.ts
24
23
  import mermaid from "mermaid";
@@ -114,7 +113,7 @@ function normalizeLintRules(value) {
114
113
  }
115
114
  return out;
116
115
  }
117
- function lintDiagram(source, options = {}) {
116
+ function lintDiagramContent(source, options = {}) {
118
117
  const enabled = normalizeLintRules(options.rules);
119
118
  const diagnostics = [];
120
119
  if (enabled["front-matter"]) diagnostics.push(...lintFrontMatter(source));
@@ -124,9 +123,6 @@ function lintDiagram(source, options = {}) {
124
123
  if (enabled["unlabeled-endpoint"]) diagnostics.push(...unlabeledEndpoints(model));
125
124
  if (enabled["unused-class"]) diagnostics.push(...unusedClasses(model));
126
125
  if (enabled["undefined-class"]) diagnostics.push(...undefinedClasses(source, model));
127
- if (enabled["broken-click"] && options.diagramPaths) {
128
- diagnostics.push(...brokenClicks(model, options.diagramPaths, options.sourcePath ?? ""));
129
- }
130
126
  if (model.kind === "class" && (enabled["duplicate-class"] || enabled["undeclared-class"])) {
131
127
  const classDiagram = scanClassDiagram(source);
132
128
  if (enabled["duplicate-class"]) diagnostics.push(...duplicateClasses(classDiagram));
@@ -147,6 +143,17 @@ function lintDiagram(source, options = {}) {
147
143
  if (enabled["duplicate-sibling"]) diagnostics.push(...outline.duplicates);
148
144
  if (enabled["empty-node"]) diagnostics.push(...outline.empties);
149
145
  }
146
+ return { diagnostics, clicks: model.clicks };
147
+ }
148
+ function brokenClickFindings(clicks, paths, sourcePath) {
149
+ return brokenClicks(clicks, paths, sourcePath);
150
+ }
151
+ function lintDiagram(source, options = {}) {
152
+ const enabled = normalizeLintRules(options.rules);
153
+ const { diagnostics, clicks } = lintDiagramContent(source, options);
154
+ if (enabled["broken-click"] && options.diagramPaths) {
155
+ diagnostics.push(...brokenClickFindings(clicks, options.diagramPaths, options.sourcePath ?? ""));
156
+ }
150
157
  diagnostics.sort((a, b) => a.from - b.from || a.line - b.line || a.ruleId.localeCompare(b.ruleId));
151
158
  return diagnostics;
152
159
  }
@@ -401,9 +408,9 @@ function undefinedClasses(source, model) {
401
408
  }
402
409
  return diagnostics;
403
410
  }
404
- function brokenClicks(model, paths, sourcePath) {
411
+ function brokenClicks(clicks, paths, sourcePath) {
405
412
  const diagnostics = [];
406
- for (const click of model.clicks) {
413
+ for (const click of clicks) {
407
414
  if (diagramTargetExists(click.target, paths, sourcePath)) continue;
408
415
  const resolved = resolveDiagramTarget(click.target, sourcePath);
409
416
  const message = resolved.ok === false && resolved.reason === "escape" ? `The click link "${click.target}" leaves the workspace and does not match a diagram.` : `The click link "${click.target}" does not match a diagram in this workspace.`;
@@ -1977,7 +1984,12 @@ async function lintDiagramSource(source, options = {}) {
1977
1984
  );
1978
1985
  return omitMutedWarnings(source, combined);
1979
1986
  }
1987
+
1980
1988
  export {
1981
- lintDiagramSource,
1982
- mermaidSyntaxDiagnostic
1989
+ LINT_RULE_IDS,
1990
+ lintDiagramContent,
1991
+ brokenClickFindings,
1992
+ warningsMuted,
1993
+ mermaidSyntaxDiagnostic,
1994
+ lintDiagramSource
1983
1995
  };
@@ -0,0 +1,14 @@
1
+ // server/src/dataFiles.ts
2
+ var DATA_FILE_EXTENSIONS = [".network.json", ".csv", ".json", ".cdp", ".lldp"];
3
+ function dataFileExtension(name) {
4
+ const lower = name.toLowerCase();
5
+ return DATA_FILE_EXTENSIONS.find((ext) => lower.endsWith(ext)) ?? "";
6
+ }
7
+ function isDataFileName(name) {
8
+ return dataFileExtension(name) !== "";
9
+ }
10
+
11
+ export {
12
+ dataFileExtension,
13
+ isDataFileName
14
+ };
@@ -0,0 +1,196 @@
1
+ import {
2
+ reportUnreadable
3
+ } from "./chunk-GK3V52XM.js";
4
+ import {
5
+ LINT_RULE_IDS,
6
+ brokenClickFindings,
7
+ lintDiagramContent,
8
+ mermaidSyntaxDiagnostic,
9
+ warningsMuted
10
+ } from "./chunk-M4HT24R6.js";
11
+
12
+ // server/src/diagramLintCache.ts
13
+ import { createHash } from "node:crypto";
14
+ var CONCURRENCY = 4;
15
+ var entries = /* @__PURE__ */ new Map();
16
+ var pathSetHash = "";
17
+ var rulesKey = "";
18
+ var last = null;
19
+ var stale = false;
20
+ var inflight = null;
21
+ function invalidateDiagramLint(paths) {
22
+ if (!paths) {
23
+ entries.clear();
24
+ pathSetHash = "";
25
+ if (last) stale = true;
26
+ return;
27
+ }
28
+ let changed = false;
29
+ for (const item of paths) {
30
+ if (entries.delete(item)) changed = true;
31
+ }
32
+ if (changed && last) stale = true;
33
+ }
34
+ function clearDiagramLintCache() {
35
+ entries.clear();
36
+ pathSetHash = "";
37
+ rulesKey = "";
38
+ last = null;
39
+ stale = false;
40
+ }
41
+ function diagramLintSummary() {
42
+ if (!last) {
43
+ return {
44
+ status: "not-checked",
45
+ checkedAt: null,
46
+ stale: false,
47
+ checked: null,
48
+ errors: null,
49
+ warnings: null,
50
+ unreadable: null,
51
+ muted: null,
52
+ diagrams: null
53
+ };
54
+ }
55
+ let errors = 0;
56
+ let warnings = 0;
57
+ const diagrams = last.diagrams.map((diagram) => {
58
+ const diagramErrors = diagram.diagnostics.filter((item) => item.severity === "error").length;
59
+ const diagramWarnings = diagram.diagnostics.length - diagramErrors;
60
+ errors += diagramErrors;
61
+ warnings += diagramWarnings;
62
+ return { path: diagram.path, errors: diagramErrors, warnings: diagramWarnings };
63
+ });
64
+ return {
65
+ status: "ready",
66
+ checkedAt: last.cachedAt,
67
+ stale,
68
+ checked: last.checked,
69
+ errors,
70
+ warnings,
71
+ unreadable: last.unreadable.length,
72
+ muted: last.muted.length,
73
+ diagrams
74
+ };
75
+ }
76
+ function hashText(text) {
77
+ return createHash("sha256").update(text, "utf8").digest("hex");
78
+ }
79
+ function hashPaths(paths) {
80
+ return createHash("sha256").update(paths.join("\n"), "utf8").digest("hex");
81
+ }
82
+ async function pool(items, limit, run) {
83
+ let next = 0;
84
+ const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
85
+ while (next < items.length) {
86
+ const index = next;
87
+ next += 1;
88
+ const item = items[index];
89
+ if (item !== void 0) await run(item);
90
+ }
91
+ });
92
+ await Promise.all(workers);
93
+ }
94
+ function visibleDiagnostics(entry, paths, sourcePath) {
95
+ const links = brokenClickFindings(entry.clicks, paths, sourcePath);
96
+ const combined = [...entry.diagnostics, ...links];
97
+ const kept = entry.muted ? combined.filter((item) => item.severity !== "warning") : combined;
98
+ kept.sort((a, b) => a.from - b.from || a.line - b.line || a.ruleId.localeCompare(b.ruleId));
99
+ return kept;
100
+ }
101
+ async function execute(input) {
102
+ const started = Date.now();
103
+ const signature = LINT_RULE_IDS.join(",");
104
+ if (rulesKey && rulesKey !== signature) {
105
+ entries.clear();
106
+ pathSetHash = "";
107
+ }
108
+ rulesKey = signature;
109
+ const paths = input.files.map((file) => file.path);
110
+ const nextHash = hashPaths(paths);
111
+ let relinted = 0;
112
+ const unreadable = [];
113
+ const seen = new Set(paths);
114
+ await pool(input.files, CONCURRENCY, async (file) => {
115
+ let stat;
116
+ try {
117
+ stat = await input.stat(file.path);
118
+ } catch (err) {
119
+ unreadable.push(reportUnreadable(file.path, err));
120
+ entries.delete(file.path);
121
+ return;
122
+ }
123
+ if (!stat) {
124
+ unreadable.push(reportUnreadable(file.path, Object.assign(new Error("missing"), { code: "ENOENT" })));
125
+ entries.delete(file.path);
126
+ return;
127
+ }
128
+ const cached = entries.get(file.path);
129
+ if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) return;
130
+ let content;
131
+ try {
132
+ content = (await input.read(file.path)).content;
133
+ } catch (err) {
134
+ unreadable.push(reportUnreadable(file.path, err));
135
+ entries.delete(file.path);
136
+ return;
137
+ }
138
+ const digest = hashText(content);
139
+ if (cached && cached.hash === digest) {
140
+ entries.set(file.path, { ...cached, size: stat.size, mtimeMs: stat.mtimeMs });
141
+ return;
142
+ }
143
+ const parsed = lintDiagramContent(content);
144
+ const syntax = await mermaidSyntaxDiagnostic(content);
145
+ const diagnostics = syntax ? [...parsed.diagnostics, syntax] : parsed.diagnostics;
146
+ entries.set(file.path, {
147
+ size: stat.size,
148
+ mtimeMs: stat.mtimeMs,
149
+ hash: digest,
150
+ diagnostics,
151
+ clicks: parsed.clicks,
152
+ muted: warningsMuted(content)
153
+ });
154
+ relinted += 1;
155
+ });
156
+ for (const key of [...entries.keys()]) {
157
+ if (!seen.has(key)) entries.delete(key);
158
+ }
159
+ const muted = [];
160
+ const diagrams = [];
161
+ for (const filePath of paths) {
162
+ const entry = entries.get(filePath);
163
+ if (!entry) continue;
164
+ if (entry.muted) muted.push(filePath);
165
+ const diagnostics = visibleDiagnostics(entry, paths, filePath);
166
+ if (diagnostics.length > 0) diagrams.push({ path: filePath, diagnostics });
167
+ }
168
+ pathSetHash = nextHash;
169
+ const result = {
170
+ checked: paths.length,
171
+ relinted,
172
+ durationMs: Date.now() - started,
173
+ cachedAt: (/* @__PURE__ */ new Date()).toISOString(),
174
+ diagrams,
175
+ unreadable,
176
+ muted
177
+ };
178
+ last = result;
179
+ stale = false;
180
+ return result;
181
+ }
182
+ function lintWorkspaceCached(input) {
183
+ if (!inflight) {
184
+ inflight = execute(input).finally(() => {
185
+ inflight = null;
186
+ });
187
+ }
188
+ return inflight;
189
+ }
190
+
191
+ export {
192
+ invalidateDiagramLint,
193
+ clearDiagramLintCache,
194
+ diagramLintSummary,
195
+ lintWorkspaceCached
196
+ };
@@ -0,0 +1,21 @@
1
+ import {
2
+ labelFromPath,
3
+ parseNetworkDocument,
4
+ readDiagramNetwork,
5
+ readMappingFile,
6
+ readNetworkFile,
7
+ siblingNetworkPath
8
+ } from "./chunk-WYQ4QDCF.js";
9
+ import "./chunk-ARL7TA3D.js";
10
+ import "./chunk-M63FV47T.js";
11
+ import "./chunk-BW6ANOTX.js";
12
+ import "./chunk-6LCHDAAN.js";
13
+ import "./chunk-MLKGABMK.js";
14
+ export {
15
+ labelFromPath,
16
+ parseNetworkDocument,
17
+ readDiagramNetwork,
18
+ readMappingFile,
19
+ readNetworkFile,
20
+ siblingNetworkPath
21
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dataFail
3
- } from "./chunk-6ELR2KYA.js";
3
+ } from "./chunk-ARL7TA3D.js";
4
4
 
5
5
  // server/src/diagramDataFiles.ts
6
6
  function importInputFromBody(body) {
@@ -0,0 +1,85 @@
1
+ import {
2
+ assertExportInputSize,
3
+ exporterFail,
4
+ parseMappingText,
5
+ readDataSource,
6
+ validateNetwork
7
+ } from "./chunk-ARL7TA3D.js";
8
+
9
+ // server/src/exporters/resolve.ts
10
+ import fs from "node:fs/promises";
11
+ import path from "node:path";
12
+ function labelFromPath(filePath) {
13
+ const base = path.basename(filePath);
14
+ return base.replace(/\.network\.json$/i, "").replace(/\.mmd$/i, "") || "nerdgram";
15
+ }
16
+ function parseNetworkDocument(text) {
17
+ assertExportInputSize(Buffer.byteLength(text));
18
+ const trimmed = text.replace(/^\uFEFF/, "").trim();
19
+ if (!trimmed) throw exporterFail(400, "The network document is empty.");
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(trimmed);
23
+ } catch {
24
+ throw exporterFail(400, "The network document is not valid JSON.");
25
+ }
26
+ const validated = validateNetwork(parsed);
27
+ if (!validated.document) {
28
+ const first = validated.issues[0];
29
+ const where = first?.path ? `${first.path}: ` : "";
30
+ throw exporterFail(400, `${where}${first?.message ?? "The network document does not match the schema."}`);
31
+ }
32
+ return validated.document;
33
+ }
34
+ function siblingNetworkPath(diagramPath, content) {
35
+ const source = readDataSource(content);
36
+ if (source?.file && source.file.toLowerCase().endsWith(".network.json")) {
37
+ return { kind: "recorded", path: source.file };
38
+ }
39
+ const stem = labelFromPath(diagramPath);
40
+ const dir = path.posix.dirname(diagramPath.split(path.sep).join("/"));
41
+ const name = `${stem}.network.json`;
42
+ const next = !dir || dir === "." ? name : `${dir}/${name}`;
43
+ return { kind: "stem", path: next };
44
+ }
45
+ async function readNetworkFile(filePath) {
46
+ let text;
47
+ try {
48
+ text = await fs.readFile(filePath, "utf8");
49
+ } catch {
50
+ throw exporterFail(400, `Could not read ${filePath}.`);
51
+ }
52
+ return { document: parseNetworkDocument(text), label: labelFromPath(filePath) };
53
+ }
54
+ async function readDiagramNetwork(diagramPath, readText) {
55
+ let content;
56
+ try {
57
+ content = await readText(diagramPath);
58
+ } catch {
59
+ throw exporterFail(400, `Could not read ${diagramPath}.`);
60
+ }
61
+ const sibling = siblingNetworkPath(diagramPath, content);
62
+ let text;
63
+ try {
64
+ text = await readText(sibling.path);
65
+ } catch {
66
+ if (sibling.kind === "recorded") {
67
+ throw exporterFail(400, `The diagram records network JSON at ${sibling.path}, and that file is not there.`);
68
+ }
69
+ throw exporterFail(400, "This diagram has no network JSON.");
70
+ }
71
+ return { document: parseNetworkDocument(text), label: labelFromPath(diagramPath) };
72
+ }
73
+ async function readMappingFile(filePath) {
74
+ const text = await fs.readFile(filePath, "utf8");
75
+ return parseMappingText(text);
76
+ }
77
+
78
+ export {
79
+ labelFromPath,
80
+ parseNetworkDocument,
81
+ siblingNetworkPath,
82
+ readNetworkFile,
83
+ readDiagramNetwork,
84
+ readMappingFile
85
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ installedExporters,
3
+ outputDirectory,
4
+ runExport
5
+ } from "./chunk-KIK3WXJL.js";
6
+ import "./chunk-ARL7TA3D.js";
7
+ import "./chunk-M63FV47T.js";
8
+ import "./chunk-BW6ANOTX.js";
9
+ import "./chunk-6LCHDAAN.js";
10
+ import "./chunk-MLKGABMK.js";
11
+ export {
12
+ installedExporters,
13
+ outputDirectory,
14
+ runExport
15
+ };
package/dist/cli.js CHANGED
@@ -38,6 +38,7 @@ Usage
38
38
  nerdgram search <query>
39
39
  nerdgram get <path> [-o file]
40
40
  nerdgram put <path> <file>
41
+ nerdgram export <target> <diagram|network.json> [-o file]
41
42
  nerdgram export <folder> -o dir/
42
43
  nerdgram lint [path|file] [--strict]
43
44
  nerdgram rename <from> <to>
@@ -57,7 +58,9 @@ Usage
57
58
  nerdgram replace --undo <id>
58
59
 
59
60
  A local .mmd file is rendered and linted in this process. convert reads a
60
- saved export and writes canonical network JSON in this process. Anything else uses
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
61
64
  NERDGRAM_URL (default http://127.0.0.1:8787) and NERDGRAM_TOKEN.
62
65
  --url and --token override those. --server forces render to use a workspace
63
66
  path on the API, not a file on this computer. Exit status is 1 on errors.
@@ -115,16 +118,16 @@ not changed. --undo restores that replace and skips a file edited since.
115
118
  `;
116
119
  var renderModule = null;
117
120
  function loadRender() {
118
- renderModule ??= import("./chunk-P666JXDB.js");
121
+ renderModule ??= import("./chunk-7NPZMMPE.js");
119
122
  return renderModule;
120
123
  }
121
124
  async function loadLint() {
122
- return import("./chunk-RB3SBRHP.js");
125
+ return import("./chunk-DWP7W42J.js");
123
126
  }
124
127
  async function templateCommand(parsed, io) {
125
128
  const sub = parsed.positionals[0] ?? "";
126
129
  const target = parsed.positionals[1] ?? "";
127
- const templates = await import("./chunk-53YCVNDJ.js");
130
+ const templates = await import("./chunk-2WFLIMQG.js");
128
131
  try {
129
132
  if (sub === "save") {
130
133
  if (!target) throw new CliError("Usage: nerdgram template save <diagram> [--name name] [--replace]");
@@ -397,7 +400,25 @@ async function putCommand(parsed, io) {
397
400
  writeOut(io, isJson(parsed.flags), { path: body.path, hash: body.hash ?? null }, `Wrote ${body.path}`);
398
401
  }
399
402
  async function exportCommand(parsed, io) {
400
- const folder = parsed.positionals[0] ?? "";
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;
401
422
  const output = flagString(parsed.flags, "output");
402
423
  if (!output) throw new CliError("export needs -o directory.");
403
424
  const { base, token } = configOf(parsed.flags, io.env);
@@ -416,6 +437,114 @@ async function exportCommand(parsed, io) {
416
437
  }
417
438
  writeOut(io, isJson(parsed.flags), { path: folder, output, count }, `Exported ${count} diagram${count === 1 ? "" : "s"} to ${output}`);
418
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
+ }
419
548
  async function lintCommand(parsed, io) {
420
549
  const target = parsed.positionals[0] ?? flagString(parsed.flags, "source");
421
550
  const strict = parsed.flags.get("strict") === true;
@@ -782,7 +911,7 @@ async function readStdin() {
782
911
  return Buffer.concat(chunks).toString("utf8");
783
912
  }
784
913
  async function convertCommand(parsed, io) {
785
- const translators = await import("./chunk-GDPSIPXV.js");
914
+ const translators = await import("./chunk-7O4HSURR.js");
786
915
  const source = parsed.positionals[0] ?? "";
787
916
  if (!source) {
788
917
  const installed = await translators.installedTranslators();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nerdgram1337",
3
- "version": "1.7.5",
3
+ "version": "1.8.5",
4
4
  "description": "Command-line client for a local NerdGram1337 server",
5
5
  "type": "module",
6
6
  "license": "MIT",