@echo off
title ACE Manager
echo.
echo  ============================================
echo   ACE Manager - Windows
echo  ============================================
echo.
REM Go to script directory
cd /d "%~dp0"
REM ── Check Node.js ──────────────────────────────────────────────────────────
where node >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo [ERROR] Node.js not found. Download it from https://nodejs.org
    pause
    exit /b 1
)
for /f "tokens=*" %%v in ('node -e "process.stdout.write(process.version)"') do set NODE_VER=%%v
echo [INFO] Node.js %NODE_VER%
REM ── Install npm dependencies if needed ─────────────────────────────────────
if not exist "node_modules" (
    echo [INFO] Installing npm dependencies...
    call npm install
    if %ERRORLEVEL% NEQ 0 (
        echo [ERROR] npm install failed!
        pause
        exit /b 1
    )
)
REM ── Read port from config ──────────────────────────────────────────────────
for /f "tokens=*" %%p in ('node -e "try{const c=require('./config.json');process.stdout.write(String(c.webPort||3000))}catch(e){process.stdout.write('3000')}"') do set PORT=%%p
echo.
echo [INFO] Starting ACE Manager...
echo [INFO] Open your browser at: http://localhost:%PORT%
echo [INFO] Press Ctrl+C to stop.
echo.
node src/server.js
pause
