@echo off
echo ========================================
echo GroupWare Frontend Build Script
echo ========================================

REM 현재 디렉토리 저장
set CURRENT_DIR=%CD%

REM frontend 폴더로 이동
cd /d "%~dp0"

echo.
echo [1/3] Installing dependencies...
call npm install
if %ERRORLEVEL% NEQ 0 (
    echo ERROR: npm install failed
    pause
    exit /b 1
)

echo.
echo [2/3] Building production...
call npm run build
if %ERRORLEVEL% NEQ 0 (
    echo ERROR: npm build failed
    pause
    exit /b 1
)

echo.
echo [3/3] Copying dist to wwwroot...
REM 기존 react 폴더 삭제 (있으면)
if exist "..\Web\wwwroot\react-app" rmdir /s /q "..\Web\wwwroot\react-app"

REM dist 폴더를 wwwroot\react-app으로 복사
xcopy /e /i /y "dist" "..\Web\wwwroot\react-app"

echo.
echo ========================================
echo Build completed successfully!
echo Output: Project\Web\wwwroot\react-app
echo ========================================
echo.
echo Access via: http://localhost:7979/react-app/
echo.

REM 원래 디렉토리로 복귀
cd /d "%CURRENT_DIR%"

pause
