diff options
Diffstat (limited to 'build/jj-log.nu')
| -rw-r--r-- | build/jj-log.nu | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/build/jj-log.nu b/build/jj-log.nu new file mode 100644 index 0000000..7d2aa92 --- /dev/null +++ b/build/jj-log.nu @@ -0,0 +1,34 @@ +#!/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)" + } +} |
