reportist/render.sh

38 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Render a report with the report plugin's own Typst document model.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
source "$root/tools/render-common.sh"
usage() {
echo "Usage: $0 INPUT.yaml|json [--output PDF] [--typst COMMAND] [--force]" >&2
exit 2
}
fail() {
echo "error: $*" >&2
exit 1
}
input=${1:-}
[[ -n "$input" ]] || usage
shift
reportist_parse_render_options report "$@" || usage
output=$RENDER_OUTPUT_OPTION typst_command=$RENDER_TYPST force=$RENDER_FORCE
case $input in *.yaml | *.yml) format=yaml ;; *.json) format=json ;; *) fail "expected a YAML or JSON report" ;; esac
command -v "$typst_command" >/dev/null 2>&1 || fail "Typst executable not found: $typst_command"
if [[ -z "$output" ]]; then output=${input%.*}.pdf; fi
reportist_prepare_render_paths "$input" "$output" "$force" || exit 1
input=$RENDER_INPUT output=$RENDER_OUTPUT
reportist_make_render_stage report
stage=$RENDER_STAGE
mkdir -p "$stage/modules" "$stage/config" "$stage/assets" "$stage/reports" "$stage/visual"
cp -- "$root/plugins/report/render.typ" "$stage/report.typ"
cp -- "$root/plugins/report/model.typ" "$stage/modules/model.typ"
cp -- "$root/plugins/report/locales.json" "$stage/config/locales.json"
cp -- "$root/visual/themes.yaml" "$stage/config/themes.yaml"
cp -- "$root/visual/beffroi.png" "$stage/assets/beffroi.png"
cp -- "$root/visual/elements.typ" "$stage/visual/elements.typ"
cp -- "$input" "$stage/reports/input.$format"
"$typst_command" compile --root "$stage" --input "report=reports/input.$format" --input "format=$format" \
"$stage/report.typ" "$stage/report.pdf" || fail "report rendering failed"
mv -f -- "$stage/report.pdf" "$output"
echo "Rendered PDF: $output"