#!/bin/sh
# Rebuild what this package can rebuild, in the order that ends consistent.
#
# The manuscript itself is typeset from markdown sources and JavaScript builders
# that are editorial rather than scientific and are not deposited, so this
# script does not attempt them. The full chain used to produce the submission,
# for the record, is:
#
#   build_jme.js -> build_equations.py -> build_esm1.py -> freeze.py
#
# Order matters and nothing is allowed to fail quietly. audit_numbers.py runs
# first, on the files as they stand, so that a changed result is caught before
# anything regenerates its hashes. freeze.py then writes and verifies the
# manifest, and final_audit.py runs last because it re-runs verify_package.py
# and so needs the manifest to be current.
set -e
HERE=$(dirname "$0")
ROOT=$(dirname "$HERE")

# build_esm1.py is one of those editorial builders and is not deposited, so it
# runs only when present — in the authors' workspace, not in the public package.
if [ -f "$HERE/build_esm1.py" ]; then
    python3 "$HERE/build_esm1.py" "$ROOT/esm1.txt"
fi
python3 "$HERE/audit_numbers.py"
python3 "$HERE/freeze.py"
python3 "$HERE/final_audit.py"
