reportist/plugins/diagnostics/render.sh

41 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Render a WinDiagnostics capture with the diagnostic plugin's Typst model.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
source "$root/../../tools/render-common.sh"
visual_root=$root/../../visual
usage() {
echo "Usage: $0 CAPTURE.json --output PDF [--author NAME] [--theme NAME] [--force]" >&2
exit 2
}
fail() {
echo "error: $*" >&2
exit 1
}
input=${1:-}
[[ -n "$input" ]] || usage
shift
reportist_parse_render_options diagnostic "$@" || usage
output=$RENDER_OUTPUT_OPTION author=$RENDER_AUTHOR theme=$RENDER_THEME force=$RENDER_FORCE
[[ -n "$author" ]] || fail "author is required"
[[ ! -L "$input" ]] || fail "input symlinks are not supported"
reportist_prepare_render_paths "$input" "$output" "$force" || exit 1
input=$RENDER_INPUT output=$RENDER_OUTPUT
[[ -f "$visual_root/elements.typ" && -f "$visual_root/themes.yaml" ]] || fail "shared visual module is missing"
reportist_make_render_stage diagnostic
stage=$RENDER_STAGE
mkdir -p "$stage/modules" "$stage/config" "$stage/assets" "$stage/diagnostics" "$stage/visual"
cp -- "$root/renderer/render.typ" "$stage/diagnostics.typ"
cp -- "$root/renderer/model.typ" "$stage/modules/diagnostics-model.typ"
cp -- "$root/renderer/normalize.typ" "$stage/modules/diagnostics-normalize.typ"
cp -- "$root/renderer/rules.yaml" "$stage/config/diagnostics-rules.yaml"
cp -- "$root/renderer/watchlist.yaml" "$stage/config/diagnostics-watchlist.yaml"
cp -- "$visual_root/themes.yaml" "$stage/config/themes.yaml"
cp -- "$visual_root/beffroi.png" "$stage/assets/beffroi.png"
cp -- "$visual_root/elements.typ" "$stage/visual/elements.typ"
cp -- "$input" "$stage/diagnostics/$(basename "$input")"
typst compile --root "$stage" --input "diagnostics=diagnostics/$(basename "$input")" \
--input "author=$author" --input "theme=$theme" "$stage/diagnostics.typ" "$stage/output.pdf" || fail "diagnostic rendering failed"
mv -f -- "$stage/output.pdf" "$output"
echo "Rendered PDF: $output"