#!/usr/bin/env bash
# Builds the self-hosted TeX Live file tree from the official TeX Live Docker image (scheme-full),
# pinned by digest in scripts/tree/texlive-image.txt. Output: public/texlive/ (see pack-tree.mjs).
# Needs Docker, Node >= 22.18, and public/engine/ from scripts/build-wasm.sh (for the format build).
#   scripts/build-tree.sh
# To move to a newer TeX Live: docker pull texlive/texlive:latest, put its digest in texlive-image.txt.
set -euo pipefail
HERE="$(cd "$(dirname "$0")/.." && pwd)"
IMAGE="$(cat "$HERE/scripts/tree/texlive-image.txt")"
EXPORT="$HERE/.texlive-cache/texlive-export"
rm -rf "$EXPORT"
mkdir -p "$EXPORT"
docker run --rm -v "$HERE/scripts/tree:/scripts:ro" -v "$EXPORT:/out" "$IMAGE" bash /scripts/export-in-container.sh
node "$HERE/scripts/tree/pack-tree.mjs" "$EXPORT" "$HERE/public"
node "$HERE/scripts/build-fmt.ts" "$HERE/public"
