From a41ba1bb87ce91f47f5ca154e27a815f48954034 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 16 Sep 2026 01:35:42 +0200 Subject: [PATCH] feat: add batch report commands --- README.md | 8 ++++++++ tools/render-all.sh | 16 ++++++++++++++++ tools/validate-all.sh | 9 +++++++++ 3 files changed, 33 insertions(+) create mode 100755 tools/render-all.sh create mode 100755 tools/validate-all.sh diff --git a/README.md b/README.md index 1c94161..0233e89 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ and DejaVu Sans Mono. bash tools/render.sh report.yaml --output report.pdf ``` +Render every YAML and JSON report in a directory tree with: + +```bash +bash tools/render-all.sh reports --output-dir output +``` + The renderer validates input before invoking Typst. It stages the report and its branding asset in an isolated temporary project, then publishes the completed PDF atomically. Existing output is rejected unless `--force` is explicit. @@ -40,6 +46,8 @@ command name. bash tools/validate.sh examples/example-report.yaml ``` +Use `bash tools/validate-all.sh DIRECTORY` to validate a directory tree. + The version 1 format supports metadata, branding, summaries, timelines, findings, generic content sections, action plans, provenance, and appendices. See [docs/report-contract.md](docs/report-contract.md) and diff --git a/tools/render-all.sh b/tools/render-all.sh new file mode 100755 index 0000000..42ddaa2 --- /dev/null +++ b/tools/render-all.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) +usage(){ echo "Usage: $0 INPUT_DIR --output-dir DIR [--force] [--typst COMMAND]" >&2; exit 2; } +input_dir=${1:-}; [[ -n "$input_dir" ]]||usage; shift; output_dir= force=false; typst_command= +while (($#)); do case $1 in --output-dir) (($# >= 2))||usage; output_dir=$2; shift 2;; --force) force=true; shift;; --typst) (($# >= 2))||usage; typst_command=$2; shift 2;; *) usage;; esac; done +[[ -n "$output_dir" ]]||usage; input_dir=$(realpath "$input_dir"); mkdir -p "$output_dir"; output_dir=$(realpath "$output_dir") +[[ "$output_dir" != "$input_dir" && "$output_dir" != "$input_dir"/* ]]||{ echo "output directory must be outside the input tree" >&2; exit 1; } +count=0 +while IFS= read -r -d '' input; do + relative=${input#"$input_dir/"}; output="$output_dir/$relative.pdf"; mkdir -p "$(dirname "$output")" + arguments=(--output "$output"); [[ "$force" == false ]]||arguments+=(--force); [[ -z "$typst_command" ]]||arguments+=(--typst "$typst_command") + "$root/tools/render.sh" "$input" "${arguments[@]}"; ((count+=1)) +done < <(find "$input_dir" -type f \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -print0 | sort -z) +((count > 0))||{ echo "$input_dir: no YAML or JSON reports found" >&2; exit 1; } +echo "Rendered $count reports into $output_dir" diff --git a/tools/validate-all.sh b/tools/validate-all.sh new file mode 100755 index 0000000..28651c6 --- /dev/null +++ b/tools/validate-all.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) +input_dir=${1:-}; [[ -n "$input_dir" && $# -eq 1 ]]||{ echo "Usage: $0 INPUT_DIR" >&2; exit 2; } +count=0 +while IFS= read -r -d '' input; do "$root/tools/validate.sh" "$input"; ((count+=1)); done \ + < <(find "$input_dir" -type f \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -print0 | sort -z) +((count > 0))||{ echo "$input_dir: no YAML or JSON reports found" >&2; exit 1; } +echo "Validated $count reports"