#!/usr/bin/env nu # Generate JSON from jj log and compile a Typst document # Usage: nu build/jj-log.nu [--revset '::@'] [--output build/jj-log.pdf] def main [ --revset (-r): string = "::@" # jj revset expression --output (-o): string = "build/jj-log.pdf" # output PDF path --json-only (-j) # only generate JSON, skip typst compile ] { let build_dir = ($env.FILE_PWD? | default ("build" | path expand)) let tmpl = (open ([$build_dir "jj-log.tmpl"] | path join)) let json_path = ($output | path parse | update extension "json" | path join) let trees_json = "trees/_data/jj-log.json" mkdir trees/_data print $"generating log for revset: ($revset)" let log_output = (jj log -r $revset --no-graph -T $tmpl) $log_output | save -f $json_path $log_output | save -f $trees_json let n = (open --raw $json_path | lines | where $it != "" | length) print $"wrote ($n) entries to ($json_path), ($trees_json)" if not $json_only { let typ_path = ([$build_dir "jj-log.typ"] | path join) let json_abs = ($json_path | path expand) let out_abs = ($output | path expand) print $"compiling ($output)..." typst compile $typ_path --root / --input $"data=($json_abs)" $out_abs print $"done → ($output)" } }