run_react.bat 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. @echo off
  2. chcp 65001 >nul
  3. title Android Remote Controller - Development
  4. REM Use nodejs/node for node/npm/npx
  5. cd /d "%~dp0"
  6. set "NODE_DIR=%~dp0nodejs\node"
  7. if exist "%NODE_DIR%\node.exe" set "PATH=%NODE_DIR%;%NODE_DIR%\node_modules\.bin;%PATH%"
  8. REM Junction node_modules to NODE_DIR (NTFS). exFAT cannot create junctions — install real node_modules at repo root.
  9. if not exist "node_modules" mklink /J "node_modules" "%NODE_DIR%\node_modules" >nul 2>&1
  10. echo Checking environment and installing dependencies...
  11. REM enviroment-check.ps1 restores npm from nodejs\backup\npm if needed, then root npm install (e.g. vite).
  12. powershell -ExecutionPolicy Bypass -File enviroment-check.ps1
  13. if %ERRORLEVEL% EQU 0 (
  14. echo.
  15. echo Starting project...
  16. echo Starting Vite dev server...
  17. start /B "" "%NODE_DIR%\npm.cmd" run dev
  18. echo Waiting for Vite server to be ready...
  19. timeout /t 3 /nobreak >nul
  20. :wait_loop
  21. powershell -Command "try { $response = Invoke-WebRequest -Uri 'http://localhost:9527' -TimeoutSec 1 -UseBasicParsing; exit 0 } catch { exit 1 }" >nul 2>&1
  22. if %ERRORLEVEL% NEQ 0 (
  23. timeout /t 1 /nobreak >nul
  24. goto wait_loop
  25. )
  26. echo Vite server is ready!
  27. echo Starting Electron...
  28. "%NODE_DIR%\npx.cmd" electron .
  29. ) else (
  30. echo.
  31. echo Environment check failed. Please fix the errors above.
  32. pause
  33. exit /b 1
  34. )