zz_

app/cli/commands/ladder-dump.ts

zzmq.dev@gmail.com/zz / app / cli / commands / ladder-dump.ts @ 4a679371 Download
Ladder Summary
  • file The file implements the **`ladderDump`** CLI command, which loads a Ladder (stored in git notes) for a given repository slug, renders it in the requested format (text, JSON, or HTML), and either writes the result to a file or streams it to stdout. It also exports the supporting **`DumpFormat`** type and **`DumpOptions`** interface that define the allowed output formats and optional output path. The primary exported function is **`ladderDump(slug: string, options: DumpOptions): Promise<void>`**.
 // `zz ladder dump <owner/repo> [--format text|json|html] [--out <path>]`:
 // materializes a Ladder already written to git notes into something
 // readable, without touching the notes themselves.
 import { writeFileSync } from "node:fs";
 import { resolveRepo } from "../lib/repo.js";
 import { collectLadder, renderText } from "../../engine/ladderRender.js";
 import { renderHtml } from "../render/html.js";
 
 export type DumpFormat = "text" | "json" | "html";
 
 export interface DumpOptions {
  format?: DumpFormat;
  out?: string;
 }
 
 export async function ladderDump(slug: string, options: DumpOptions): Promise<void> {
  const repo = resolveRepo(slug);
  const format = options.format ?? "text";
  const { tree, stats } = await collectLadder(repo.repoDir, repo.stateDir);
 
  let output: string;
  if (format === "json") {
  output = JSON.stringify({ repo: repo.slug, generatedAt: new Date().toISOString(), stats, tree }, null, 2);
  } else if (format === "html") {
  output = renderHtml(tree, { repoSlug: repo.slug, generatedAt: new Date().toISOString(), stats });
  } else {
  output = renderText(tree);
  }
 
  if (options.out) {
  writeFileSync(options.out, output);
  console.error(`wrote ${stats.rungs} rungs (${stats.notes} notes read) to ${options.out}`);
  } else {
  process.stdout.write(output + "\n");
  }
 }