#!/usr/bin/env zsh
set -euo pipefail

campaign="${1:-}"
page="${2:-}"

if [[ -z "$campaign" || -z "$page" ]]; then
  echo "usage: scripts/build-one.v5.1.0.zsh <campaign> <page>"
  exit 1
fi

# Run generate-asset-names to build imageFills map and scan images/ for crop exports.
# Phase 2b: crops arrive with final names — script scans, no rename needed.
SCRIPT_DIR="${0:A:h}"
node "$SCRIPT_DIR/generate-asset-names.mjs" "$campaign" 2>/dev/null || true

# Use SG_GENERATOR_ENTRY when set (launcher), otherwise ~/Documents/SoloGen/generator/
GENERATOR="${SG_GENERATOR_ENTRY:-$HOME/Documents/SoloGen/generator/build-flow.mjs}"
node "$GENERATOR" "$campaign" "$page"
