72 lines
2.1 KiB
Batchfile
72 lines
2.1 KiB
Batchfile
@echo off
|
||
chcp 65001 >nul
|
||
setlocal
|
||
|
||
set "PROJECT_DIR=%~dp0"
|
||
set "RUN_DIR=%PROJECT_DIR%.run"
|
||
set "PID_FILE=%RUN_DIR%\spine-particle-windows.pid"
|
||
set "OUT_LOG=%RUN_DIR%\spine-particle-windows.log"
|
||
set "ERROR_LOG=%RUN_DIR%\spine-particle-windows-error.log"
|
||
set "PROJECT_URL=http://127.0.0.1:5173/"
|
||
|
||
if not exist "%RUN_DIR%" mkdir "%RUN_DIR%"
|
||
cd /d "%PROJECT_DIR%"
|
||
|
||
if exist "%PID_FILE%" (
|
||
set /p SERVER_PID=<"%PID_FILE%"
|
||
powershell -NoProfile -Command "if (Get-Process -Id $env:SERVER_PID -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"
|
||
if not errorlevel 1 (
|
||
echo Spine粒子编辑器已经在运行,正在打开页面:
|
||
echo %PROJECT_URL%
|
||
start "" "%PROJECT_URL%"
|
||
exit /b 0
|
||
)
|
||
del /q "%PID_FILE%" >nul 2>&1
|
||
)
|
||
|
||
where npm >nul 2>&1
|
||
if errorlevel 1 (
|
||
echo 未找到 npm,请先安装 Node.js:
|
||
echo https://nodejs.org/
|
||
pause
|
||
exit /b 1
|
||
)
|
||
|
||
if not exist "%PROJECT_DIR%node_modules\vite\bin\vite.js" (
|
||
echo 首次运行,正在安装项目依赖...
|
||
call npm install
|
||
if errorlevel 1 (
|
||
echo 依赖安装失败,请检查网络或 npm 配置。
|
||
pause
|
||
exit /b 1
|
||
)
|
||
)
|
||
|
||
echo 正在启动 Spine粒子编辑器...
|
||
powershell -NoProfile -Command ^
|
||
"$node=(Get-Command node).Source; $vite=Join-Path $env:PROJECT_DIR 'node_modules\vite\bin\vite.js';" ^
|
||
"$arguments=@($vite,'--host','127.0.0.1','--port','5173','--strictPort');" ^
|
||
"$process=Start-Process -FilePath $node -ArgumentList $arguments -WorkingDirectory $env:PROJECT_DIR -RedirectStandardOutput $env:OUT_LOG -RedirectStandardError $env:ERROR_LOG -WindowStyle Hidden -PassThru;" ^
|
||
"Set-Content -Path $env:PID_FILE -Value $process.Id -Encoding ascii"
|
||
|
||
if errorlevel 1 (
|
||
echo 项目启动失败。
|
||
pause
|
||
exit /b 1
|
||
)
|
||
|
||
set /p SERVER_PID=<"%PID_FILE%"
|
||
timeout /t 2 /nobreak >nul
|
||
powershell -NoProfile -Command "if (Get-Process -Id $env:SERVER_PID -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"
|
||
if errorlevel 1 (
|
||
echo 项目启动失败,错误日志如下:
|
||
if exist "%ERROR_LOG%" type "%ERROR_LOG%"
|
||
del /q "%PID_FILE%" >nul 2>&1
|
||
pause
|
||
exit /b 1
|
||
)
|
||
|
||
echo 启动成功:%PROJECT_URL%
|
||
start "" "%PROJECT_URL%"
|
||
exit /b 0
|