16 lines
928 B
Bash
Executable File
16 lines
928 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# A plugin converts its input to a validated Reportist v1 report in a private stage.
|
|
set -euo pipefail
|
|
root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
|
|
usage(){ echo "Usage: $0 PLUGIN_DIR INPUT OUTPUT.pdf [plugin options]" >&2; exit 2; }
|
|
[[ $# -ge 3 ]] || usage
|
|
plugin=$(realpath "$1"); input=$(realpath "$2"); output=$3; shift 3
|
|
[[ -d "$plugin" && -x "$plugin/prepare.sh" && -f "$plugin/plugin.json" ]] || { echo "Invalid Reportist plugin: $plugin" >&2; exit 1; }
|
|
[[ -f "$input" ]] || { echo "Input does not exist: $input" >&2; exit 1; }
|
|
[[ ! -e "$output" ]] || { echo "Output exists: $output" >&2; exit 1; }
|
|
stage=$(mktemp -d "${TMPDIR:-/tmp}/reportist-plugin.XXXXXXXX")
|
|
trap 'rm -rf "$stage"' EXIT
|
|
"$plugin/prepare.sh" "$input" "$stage" "$root" "$@"
|
|
[[ -f "$stage/report.json" ]] || { echo "Plugin did not produce report.json" >&2; exit 1; }
|
|
"$root/render.sh" "$stage/report.json" --output "$output"
|