@rohal12/twee-ts 1.6.0 → 1.7.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/dist/index.cjs CHANGED
@@ -30,9 +30,11 @@ __export(src_exports, {
30
30
  discoverFormats: () => discoverFormats,
31
31
  fetchAndCacheFormat: () => fetchAndCacheFormat,
32
32
  fetchDirectFormat: () => fetchDirectFormat,
33
+ formatLintReport: () => formatLintReport,
33
34
  generateIFID: () => generateIFID,
34
35
  getCacheDir: () => getCacheDir,
35
36
  getFormatSearchDirs: () => getFormatSearchDirs,
37
+ lint: () => lint,
36
38
  loadConfig: () => loadConfig,
37
39
  loadConfigFile: () => loadConfigFile,
38
40
  parseFormatJSON: () => parseFormatJSON,
@@ -2437,6 +2439,69 @@ function storyInspect(story) {
2437
2439
  };
2438
2440
  }
2439
2441
 
2442
+ // src/lint.ts
2443
+ async function lint(options) {
2444
+ const result = await compile({ ...options, outputMode: "json" });
2445
+ const map = storyInspect(result.story);
2446
+ return {
2447
+ diagnostics: result.diagnostics,
2448
+ stats: result.stats,
2449
+ formatName: result.story.twine2.format,
2450
+ formatVersion: result.story.twine2.formatVersion,
2451
+ start: map.start,
2452
+ passages: map.passages.length,
2453
+ storyPassages: map.storyPassages.length,
2454
+ infoPassages: map.infoPassages.length,
2455
+ brokenLinks: map.brokenLinks,
2456
+ deadEnds: map.deadEnds,
2457
+ orphans: map.orphans
2458
+ };
2459
+ }
2460
+ function formatLintReport(result) {
2461
+ const lines = [];
2462
+ const formatStr = result.formatName ? `${result.formatName}${result.formatVersion ? " " + result.formatVersion : ""}` : "unknown";
2463
+ lines.push(`Format: ${formatStr}`);
2464
+ lines.push(
2465
+ `Passages: ${result.passages} total (${result.storyPassages} story, ${result.infoPassages} info), ${result.stats.words.toLocaleString()} words, ${result.stats.files.length} files`
2466
+ );
2467
+ lines.push(`Start: ${result.start}`);
2468
+ if (result.brokenLinks.length > 0) {
2469
+ lines.push("");
2470
+ lines.push(`Broken links (${result.brokenLinks.length}):`);
2471
+ for (const link of result.brokenLinks) {
2472
+ lines.push(` ${link.from} -> ${link.to} (passage "${link.to}" does not exist)`);
2473
+ }
2474
+ }
2475
+ if (result.deadEnds.length > 0) {
2476
+ lines.push("");
2477
+ lines.push(`Dead ends (${result.deadEnds.length}): ${result.deadEnds.join(", ")}`);
2478
+ }
2479
+ if (result.orphans.length > 0) {
2480
+ lines.push("");
2481
+ lines.push(`Orphans (${result.orphans.length}): ${result.orphans.join(", ")}`);
2482
+ }
2483
+ const errors = result.diagnostics.filter((d) => d.level === "error");
2484
+ const warnings = result.diagnostics.filter((d) => d.level === "warning");
2485
+ if (errors.length > 0 || warnings.length > 0) {
2486
+ lines.push("");
2487
+ lines.push(`Diagnostics: ${errors.length} error(s), ${warnings.length} warning(s)`);
2488
+ for (const d of errors) {
2489
+ lines.push(` error: ${d.message}`);
2490
+ }
2491
+ for (const d of warnings) {
2492
+ lines.push(` warning: ${d.message}`);
2493
+ }
2494
+ }
2495
+ lines.push("");
2496
+ const hasErrors = errors.length > 0 || result.brokenLinks.length > 0;
2497
+ if (hasErrors) {
2498
+ lines.push("Lint failed.");
2499
+ } else {
2500
+ lines.push("Lint passed.");
2501
+ }
2502
+ return lines.join("\n");
2503
+ }
2504
+
2440
2505
  // src/config.ts
2441
2506
  var import_node_fs8 = require("fs");
2442
2507
  var import_node_path8 = require("path");
@@ -2549,9 +2614,11 @@ function scaffoldConfig() {
2549
2614
  discoverFormats,
2550
2615
  fetchAndCacheFormat,
2551
2616
  fetchDirectFormat,
2617
+ formatLintReport,
2552
2618
  generateIFID,
2553
2619
  getCacheDir,
2554
2620
  getFormatSearchDirs,
2621
+ lint,
2555
2622
  loadConfig,
2556
2623
  loadConfigFile,
2557
2624
  parseFormatJSON,