feat: 新增 devtools.bat Windows 启动脚本
与 devtools.sh 功能对等,纯 ASCII 编写避免编码问题。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,91 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
:: ========================================
|
||||||
|
:: Cyrene DevTools Launcher (Windows)
|
||||||
|
:: ========================================
|
||||||
|
|
||||||
|
set "SCRIPT_DIR=%~dp0"
|
||||||
|
set "DEVTOOLS_DIR=%SCRIPT_DIR%devtools"
|
||||||
|
if "%DEVTOOLS_PORT%"=="" (set PORT=9090) else (set PORT=%DEVTOOLS_PORT%)
|
||||||
|
set "LOG_DIR=%SCRIPT_DIR%logs"
|
||||||
|
set "LOG_FILE=%LOG_DIR%\sh.log"
|
||||||
|
|
||||||
|
echo ==========================================
|
||||||
|
echo Cyrene DevTools
|
||||||
|
echo ==========================================
|
||||||
|
|
||||||
|
cd /d "%DEVTOOLS_DIR%"
|
||||||
|
|
||||||
|
:: Node.js check
|
||||||
|
where node >nul 2>&1
|
||||||
|
if %ERRORLEVEL%==0 (
|
||||||
|
set NODE_CMD=node
|
||||||
|
) else if exist "C:\Program Files\nodejs\node.exe" (
|
||||||
|
set "NODE_CMD=C:\Program Files\nodejs\node.exe"
|
||||||
|
) else (
|
||||||
|
echo [ERROR] Node.js not found.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
for /f "tokens=*" %%i in ('!NODE_CMD! --version') do echo Node.js: %%i
|
||||||
|
|
||||||
|
:: Check and free port
|
||||||
|
set PID_FOUND=0
|
||||||
|
for /f "tokens=5" %%a in ('netstat -ano ^| findstr /R ":%PORT% " ^| findstr "LISTENING"') do (
|
||||||
|
set PID_FOUND=1
|
||||||
|
echo [WARN] Port %PORT% in use by PID %%a, releasing...
|
||||||
|
taskkill /PID %%a /F >nul 2>&1
|
||||||
|
timeout /t 1 /nobreak >nul
|
||||||
|
echo [OK] Port released
|
||||||
|
)
|
||||||
|
if %PID_FOUND%==1 timeout /t 1 /nobreak >nul
|
||||||
|
|
||||||
|
:: Install dependencies if needed
|
||||||
|
if not exist "node_modules\" (
|
||||||
|
echo [INFO] Installing dependencies...
|
||||||
|
call npm install
|
||||||
|
)
|
||||||
|
|
||||||
|
:: Ensure log directory exists
|
||||||
|
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo [INFO] Starting DevTools on port %PORT%
|
||||||
|
echo Web UI: http://localhost:%PORT%
|
||||||
|
echo API: http://localhost:%PORT%/api/health
|
||||||
|
|
||||||
|
:: Launch DevTools in background
|
||||||
|
start "Cyrene-DevTools" /B !NODE_CMD! src\index.js 1>>"%LOG_FILE%" 2>&1
|
||||||
|
|
||||||
|
:: Health check (up to 30s)
|
||||||
|
set MAX_WAIT=30
|
||||||
|
set WAITED=0
|
||||||
|
:health_loop
|
||||||
|
if %WAITED% geq %MAX_WAIT% goto :timeout
|
||||||
|
|
||||||
|
powershell -Command "try { (Invoke-WebRequest 'http://localhost:%PORT%/api/health' -TimeoutSec 2 -UseBasicParsing).StatusCode -eq 200 } catch { $false }" | findstr "True" >nul 2>&1
|
||||||
|
if %ERRORLEVEL%==0 (
|
||||||
|
echo.
|
||||||
|
echo [OK] DevTools is ready.
|
||||||
|
echo Log: %LOG_FILE%
|
||||||
|
echo.
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
|
||||||
|
timeout /t 1 /nobreak >nul
|
||||||
|
set /a WAITED+=1
|
||||||
|
goto :health_loop
|
||||||
|
|
||||||
|
:timeout
|
||||||
|
if exist "%LOG_FILE%" (
|
||||||
|
echo.
|
||||||
|
echo [WARN] Still starting - waited %MAX_WAIT%s
|
||||||
|
echo Check http://localhost:%PORT%/api/health
|
||||||
|
echo Log: %LOG_FILE%
|
||||||
|
) else (
|
||||||
|
echo.
|
||||||
|
echo [ERROR] Startup failed, see: %LOG_FILE%
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
endlocal
|
||||||
Reference in New Issue
Block a user