95 lines
2.8 KiB
Batchfile
95 lines
2.8 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions
|
|
|
|
set "ROOT_DIR=%~dp0"
|
|
set "BACKEND_HOST=%BACKEND_HOST%"
|
|
set "BACKEND_PORT=%BACKEND_PORT%"
|
|
set "FRONTEND_HOST=%FRONTEND_HOST%"
|
|
set "FRONTEND_PORT=%FRONTEND_PORT%"
|
|
|
|
if not defined BACKEND_HOST set "BACKEND_HOST=127.0.0.1"
|
|
if not defined BACKEND_PORT set "BACKEND_PORT=8000"
|
|
if not defined FRONTEND_HOST set "FRONTEND_HOST=127.0.0.1"
|
|
if not defined FRONTEND_PORT set "FRONTEND_PORT=5173"
|
|
if not defined PYTHON_BIN set "PYTHON_BIN=python"
|
|
|
|
call "%PYTHON_BIN%" --version >nul 2>&1
|
|
if errorlevel 1 (
|
|
if /i "%PYTHON_BIN%"=="python" (
|
|
call py --version >nul 2>&1
|
|
if not errorlevel 1 set "PYTHON_BIN=py"
|
|
)
|
|
)
|
|
set "BACKEND_VENV=%ROOT_DIR%backend\.venv"
|
|
set "BACKEND_PYTHON=%BACKEND_VENV%\Scripts\python.exe"
|
|
|
|
if not exist "%ROOT_DIR%backend\app\main.py" (
|
|
echo Backend entrypoint not found: backend\app\main.py
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%ROOT_DIR%frontend\package.json" (
|
|
echo Frontend package manifest not found: frontend\package.json
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%ROOT_DIR%backend\requirements.txt" (
|
|
echo Backend requirements not found: backend\requirements.txt
|
|
exit /b 1
|
|
)
|
|
|
|
call "%PYTHON_BIN%" --version >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo Python executable not found: %PYTHON_BIN%
|
|
echo Set PYTHON_BIN to the Python executable path and run this script again.
|
|
exit /b 1
|
|
)
|
|
|
|
where npm >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo npm is required to start the frontend.
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%BACKEND_PYTHON%" (
|
|
echo Creating backend virtual environment...
|
|
call "%PYTHON_BIN%" -m venv "%BACKEND_VENV%"
|
|
if errorlevel 1 exit /b 1
|
|
)
|
|
|
|
call "%BACKEND_PYTHON%" -c "import build123d, dotenv, fastapi, httpx, jsonschema, multipart, uvicorn" >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo Installing backend dependencies...
|
|
call "%BACKEND_PYTHON%" -m pip install -r "%ROOT_DIR%backend\requirements.txt"
|
|
if errorlevel 1 exit /b 1
|
|
)
|
|
|
|
if not exist "%ROOT_DIR%frontend\node_modules\next" (
|
|
echo Installing frontend dependencies...
|
|
pushd "%ROOT_DIR%frontend"
|
|
if exist package-lock.json (
|
|
call npm ci
|
|
) else (
|
|
call npm install
|
|
)
|
|
if errorlevel 1 (
|
|
popd
|
|
exit /b 1
|
|
)
|
|
popd
|
|
)
|
|
|
|
echo Starting backend on %BACKEND_HOST%:%BACKEND_PORT%
|
|
start "CAD CDSL Backend" /D "%ROOT_DIR%backend" cmd /k call "%BACKEND_PYTHON%" -m uvicorn app.main:app --host %BACKEND_HOST% --port %BACKEND_PORT% --reload
|
|
|
|
echo Starting frontend on %FRONTEND_HOST%:%FRONTEND_PORT%
|
|
start "CAD CDSL Frontend" /D "%ROOT_DIR%frontend" cmd /k call npm run dev -- -H %FRONTEND_HOST% -p %FRONTEND_PORT%
|
|
|
|
echo.
|
|
echo Frontend: http://%FRONTEND_HOST%:%FRONTEND_PORT%
|
|
echo Backend: http://%BACKEND_HOST%:%BACKEND_PORT%
|
|
echo The backend and frontend are running in separate command windows.
|
|
echo Close those windows to stop the services.
|
|
|
|
endlocal
|