#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$0")"
echo "============================================================"
echo "FLEXIFORGE 0.2 - SHiRE-GUIDED STL TO FIDGET ENGINE"
echo "============================================================"
if [[ ! -d .venv ]]; then python3 -m venv .venv; fi
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
if [[ ! -f frontend/dist/index.html ]]; then
  command -v npm >/dev/null || { echo "Node.js 20+ is required to rebuild the missing frontend."; exit 1; }
  (
    cd frontend
    npm install
    npm run build
  )
fi
python run_flexiforge.py
