@emeryld/rrroutes-export 1.0.13 → 1.0.15

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.d.ts CHANGED
@@ -5,5 +5,6 @@ export * from './exportFinalizedLeaves';
5
5
  export * from './exportFinalizedLeaves.cli';
6
6
  export * from './exportFinalizedLeaves.changelog';
7
7
  export * from './exportFinalizedLeaves.changelog.cli';
8
+ export * from './exportFinalizedLeaves.bundle';
8
9
  export * from './defaultViewerTemplate';
9
10
  export * from './extractLeafSourceByAst';
package/dist/index.mjs CHANGED
@@ -296,46 +296,46 @@ function normalizeType(schema) {
296
296
  return "unknown";
297
297
  }
298
298
  }
299
- function isNonEmptyPath(path6) {
300
- return typeof path6 === "string" && path6.length > 0;
299
+ function isNonEmptyPath(path7) {
300
+ return typeof path7 === "string" && path7.length > 0;
301
301
  }
302
- function setNode(out, path6, schema, inherited) {
303
- if (!isNonEmptyPath(path6)) return;
304
- out[path6] = {
302
+ function setNode(out, path7, schema, inherited) {
303
+ if (!isNonEmptyPath(path7)) return;
304
+ out[path7] = {
305
305
  type: normalizeType(schema),
306
306
  nullable: inherited.nullable || Boolean(schema.nullable),
307
307
  optional: inherited.optional || Boolean(schema.optional),
308
308
  literal: schema.kind === "literal" ? schema.literal : void 0
309
309
  };
310
310
  }
311
- function flattenInto(out, schema, path6, inherited) {
312
- if (!schema || !isNonEmptyPath(path6)) return;
311
+ function flattenInto(out, schema, path7, inherited) {
312
+ if (!schema || !isNonEmptyPath(path7)) return;
313
313
  const nextInherited = {
314
314
  optional: inherited.optional || Boolean(schema.optional),
315
315
  nullable: inherited.nullable || Boolean(schema.nullable)
316
316
  };
317
317
  if (schema.kind === "union" && Array.isArray(schema.union) && schema.union.length > 0) {
318
318
  schema.union.forEach((option, index) => {
319
- const optionPath = `${path6}-${index + 1}`;
319
+ const optionPath = `${path7}-${index + 1}`;
320
320
  flattenInto(out, option, optionPath, inherited);
321
321
  });
322
322
  return;
323
323
  }
324
- setNode(out, path6, schema, inherited);
324
+ setNode(out, path7, schema, inherited);
325
325
  if (schema.kind === "object" && schema.properties) {
326
326
  for (const [key, child] of Object.entries(schema.properties)) {
327
- const childPath = `${path6}.${key}`;
327
+ const childPath = `${path7}.${key}`;
328
328
  flattenInto(out, child, childPath, nextInherited);
329
329
  }
330
330
  return;
331
331
  }
332
332
  if (schema.kind === "array" && schema.element) {
333
- flattenInto(out, schema.element, `${path6}[]`, nextInherited);
333
+ flattenInto(out, schema.element, `${path7}[]`, nextInherited);
334
334
  }
335
335
  }
336
- function flattenSerializableSchema(schema, path6) {
336
+ function flattenSerializableSchema(schema, path7) {
337
337
  const out = {};
338
- flattenInto(out, schema, path6, { optional: false, nullable: false });
338
+ flattenInto(out, schema, path7, { optional: false, nullable: false });
339
339
  return out;
340
340
  }
341
341
  function isSerializedLeaf(value) {
@@ -365,7 +365,7 @@ var DEFAULT_VIEWER_TEMPLATE = `<!doctype html>
365
365
  <head>
366
366
  <meta charset="UTF-8" />
367
367
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
368
- <title>Finalized Leaves Viewer</title>
368
+ <title>RRRoutes Export Viewer</title>
369
369
  <style>
370
370
  :root {
371
371
  --bg: #212121;
@@ -394,7 +394,7 @@ var DEFAULT_VIEWER_TEMPLATE = `<!doctype html>
394
394
  </head>
395
395
  <body>
396
396
  <div class="wrap">
397
- <h1>Finalized Leaves Viewer (Baked)</h1>
397
+ <h1>RRRoutes Export Viewer (Baked)</h1>
398
398
  <div class="card">
399
399
  <div id="status" class="meta">Waiting for baked payload...</div>
400
400
  </div>
@@ -429,7 +429,7 @@ var DEFAULT_VIEWER_TEMPLATE = `<!doctype html>
429
429
  wrapSection('By Source Object', payload.bySourceObject || {}),
430
430
  )
431
431
  } else if (!payload || !Array.isArray(payload.leaves)) {
432
- statusEl.textContent = 'No baked payload found in this HTML file.'
432
+ statusEl.textContent = 'No baked leaves/changelog/bundle payload found in this HTML file.'
433
433
  } else {
434
434
  statusEl.textContent = 'Loaded baked payload with ' + payload.leaves.length + ' routes.'
435
435
 
@@ -2566,9 +2566,123 @@ async function runExportFinalizedLeavesChangelogCli(argv) {
2566
2566
  htmlFile: args.htmlFile ? path5.resolve(args.htmlFile) : void 0
2567
2567
  };
2568
2568
  }
2569
+
2570
+ // src/exportFinalizedLeaves.bundle.ts
2571
+ import fs3 from "fs/promises";
2572
+ import path6 from "path";
2573
+ import { spawn as spawn3 } from "child_process";
2574
+ var BAKED_PAYLOAD_MARKER3 = "<!--__FINALIZED_LEAVES_BAKED_PAYLOAD__-->";
2575
+ function escapePayloadForInlineScript3(payload) {
2576
+ return JSON.stringify(payload).replace(/<\//g, "<\\/").replace(/<!--/g, "<\\!--");
2577
+ }
2578
+ function injectPayloadIntoViewerHtml3(htmlTemplate, payload) {
2579
+ const payloadScript = `${BAKED_PAYLOAD_MARKER3}
2580
+ <script id="finalized-leaves-baked-payload">window.__FINALIZED_LEAVES_PAYLOAD = ${escapePayloadForInlineScript3(
2581
+ payload
2582
+ )};</script>`;
2583
+ if (htmlTemplate.includes(BAKED_PAYLOAD_MARKER3)) {
2584
+ return htmlTemplate.replace(BAKED_PAYLOAD_MARKER3, payloadScript);
2585
+ }
2586
+ if (htmlTemplate.includes("</body>")) {
2587
+ return htmlTemplate.replace("</body>", `${payloadScript}
2588
+ </body>`);
2589
+ }
2590
+ return `${payloadScript}
2591
+ ${htmlTemplate}`;
2592
+ }
2593
+ async function resolveViewerTemplatePath3(viewerTemplateFile) {
2594
+ if (viewerTemplateFile) {
2595
+ const resolved = path6.resolve(viewerTemplateFile);
2596
+ await fs3.access(resolved);
2597
+ return resolved;
2598
+ }
2599
+ const candidates = [
2600
+ path6.resolve(
2601
+ process.cwd(),
2602
+ "node_modules/@emeryld/rrroutes-export/tools/finalized-leaves-viewer.html"
2603
+ ),
2604
+ path6.resolve(process.cwd(), "tools/finalized-leaves-viewer.html"),
2605
+ path6.resolve(process.cwd(), "packages/export/tools/finalized-leaves-viewer.html")
2606
+ ];
2607
+ for (const candidate of candidates) {
2608
+ try {
2609
+ await fs3.access(candidate);
2610
+ return candidate;
2611
+ } catch {
2612
+ }
2613
+ }
2614
+ return void 0;
2615
+ }
2616
+ async function writeJsonExport3(payload, outFile) {
2617
+ const resolved = path6.resolve(outFile);
2618
+ await fs3.mkdir(path6.dirname(resolved), { recursive: true });
2619
+ await fs3.writeFile(resolved, `${JSON.stringify(payload, null, 2)}
2620
+ `, "utf8");
2621
+ return resolved;
2622
+ }
2623
+ async function writeBakedHtmlExport3(payload, htmlFile, viewerTemplateFile) {
2624
+ const templatePath = await resolveViewerTemplatePath3(viewerTemplateFile);
2625
+ const template = templatePath ? await fs3.readFile(templatePath, "utf8") : DEFAULT_VIEWER_TEMPLATE;
2626
+ const baked = injectPayloadIntoViewerHtml3(template, payload);
2627
+ const resolved = path6.resolve(htmlFile);
2628
+ await fs3.mkdir(path6.dirname(resolved), { recursive: true });
2629
+ await fs3.writeFile(resolved, baked, "utf8");
2630
+ return resolved;
2631
+ }
2632
+ async function openHtmlInBrowser3(filePath) {
2633
+ const resolved = path6.resolve(filePath);
2634
+ const platform = process.platform;
2635
+ if (platform === "darwin") {
2636
+ spawn3("open", [resolved], { detached: true, stdio: "ignore" }).unref();
2637
+ return;
2638
+ }
2639
+ if (platform === "win32") {
2640
+ spawn3("cmd", ["/c", "start", "", resolved], {
2641
+ detached: true,
2642
+ stdio: "ignore"
2643
+ }).unref();
2644
+ return;
2645
+ }
2646
+ spawn3("xdg-open", [resolved], { detached: true, stdio: "ignore" }).unref();
2647
+ }
2648
+ function buildFinalizedLeavesViewerBundle(input) {
2649
+ return {
2650
+ kind: "finalized-leaves-bundle",
2651
+ _meta: {
2652
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2653
+ description: "Unified viewer bundle including finalized leaves snapshot and changelog timeline payloads."
2654
+ },
2655
+ leavesPayload: input.leavesPayload,
2656
+ changelogPayload: input.changelogPayload
2657
+ };
2658
+ }
2659
+ async function writeFinalizedLeavesViewerBundle(payload, outFileOrOptions) {
2660
+ const options = typeof outFileOrOptions === "string" ? { outFile: outFileOrOptions } : outFileOrOptions;
2661
+ const written = {};
2662
+ if (options.outFile) {
2663
+ written.outFile = await writeJsonExport3(payload, options.outFile);
2664
+ }
2665
+ if (options.htmlFile) {
2666
+ written.htmlFile = await writeBakedHtmlExport3(
2667
+ payload,
2668
+ options.htmlFile,
2669
+ options.viewerTemplateFile
2670
+ );
2671
+ }
2672
+ if (options.openOnFinish) {
2673
+ if (!written.htmlFile) {
2674
+ throw new Error(
2675
+ "openOnFinish requires htmlFile. Provide htmlFile to open the baked viewer."
2676
+ );
2677
+ }
2678
+ await openHtmlInBrowser3(written.htmlFile);
2679
+ }
2680
+ return written;
2681
+ }
2569
2682
  export {
2570
2683
  DEFAULT_VIEWER_TEMPLATE,
2571
2684
  __private,
2685
+ buildFinalizedLeavesViewerBundle,
2572
2686
  clearSchemaIntrospectionHandlers,
2573
2687
  createSchemaIntrospector,
2574
2688
  exportFinalizedLeaves,
@@ -2587,6 +2701,7 @@ export {
2587
2701
  serializeLeafContract,
2588
2702
  serializeLeavesContract,
2589
2703
  writeFinalizedLeavesChangelogExport,
2590
- writeFinalizedLeavesExport
2704
+ writeFinalizedLeavesExport,
2705
+ writeFinalizedLeavesViewerBundle
2591
2706
  };
2592
2707
  //# sourceMappingURL=index.mjs.map