@echo off
setlocal
cd /d "%~dp0"
echo ============================================================
echo FLEXIFORGE 0.2 - SHiRE-GUIDED STL TO FIDGET ENGINE
echo ============================================================
where py >nul 2>nul
if %errorlevel%==0 (
  set PYTHON_CMD=py -3
) else (
  set PYTHON_CMD=python
)
if not exist .venv (
  %PYTHON_CMD% -m venv .venv
  if errorlevel 1 goto :error
)
call .venv\Scripts\activate.bat
python -m pip install --upgrade pip
if errorlevel 1 goto :error
pip install -r requirements.txt
if errorlevel 1 goto :error
if not exist frontend\dist\index.html (
  echo Prebuilt interface missing. Node.js is required to rebuild it.
  where npm >nul 2>nul || goto :nodeerror
  pushd frontend
  call npm install
  call npm run build
  popd
)
python run_flexiforge.py
goto :eof
:nodeerror
echo Please install Node.js 20+ to rebuild the missing frontend.
pause
exit /b 1
:error
echo FlexiForge could not start. Review the error above.
pause
exit /b 1
