-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-BlockPilot-ZH.bat
More file actions
153 lines (140 loc) · 6.24 KB
/
Copy pathStart-BlockPilot-ZH.bat
File metadata and controls
153 lines (140 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
@echo off
REM SPDX-License-Identifier: Apache-2.0
REM BlockPilot Minecraft Panel v1.0.5
REM 功能说明:检查 npm、安装依赖、构建项目,并将 WEB 与 API 控制台分开显示。
REM 维护原则:分离控制台的启动流程如有调整,必须同步更新公开文档。
setlocal EnableExtensions EnableDelayedExpansion
chcp 65001 >nul
title BlockPilotMC WEB - 中文简体
cd /d "%~dp0"
set "PANEL_PORT=8787"
call :PrintHeader
call :EnsureNpm
if errorlevel 1 goto :Failed
REM Install dependencies only when node_modules is missing or package-lock.json has changed.
set "NEED_INSTALL=0"
if not exist "node_modules\" set "NEED_INSTALL=1"
if not exist "package-lock.json" (
echo [错误] 找不到 package-lock.json,请确认源码已完整解压。
goto :Failed
)
for /f "usebackq delims=" %%H in (`powershell -NoProfile -ExecutionPolicy Bypass -Command "(Get-FileHash -Algorithm SHA256 'package-lock.json').Hash"`) do set "CURRENT_LOCK_HASH=%%H"
if not defined CURRENT_LOCK_HASH (
echo [警告] 无法计算 package-lock.json 哈希,将重新执行 npm ci。
set "NEED_INSTALL=1"
)
set "SAVED_LOCK_HASH="
if exist ".blockpilot-npm-lock.sha256" set /p SAVED_LOCK_HASH=<".blockpilot-npm-lock.sha256"
if /I not "!CURRENT_LOCK_HASH!"=="!SAVED_LOCK_HASH!" set "NEED_INSTALL=1"
REM Reinstall when a required runtime dependency is missing, even if the saved lock hash matches.
if "!NEED_INSTALL!"=="0" (
node -e "require.resolve('iconv-lite')" >nul 2>&1
if errorlevel 1 set "NEED_INSTALL=1"
)
if "!NEED_INSTALL!"=="1" (
echo [信息] 正在准备项目依赖...
powershell -NoProfile -ExecutionPolicy Bypass -File "scripts\windows\Install-Dependencies.ps1" -Locale "zh-CN"
if errorlevel 1 goto :Failed
if defined CURRENT_LOCK_HASH >".blockpilot-npm-lock.sha256" echo !CURRENT_LOCK_HASH!
) else (
echo [信息] npm 与项目依赖已就绪,跳过安装。
)
REM GitHub source archives do not include dist folders, so build the API and web interface before startup.
echo [信息] 正在构建 API 与 WEB 界面...
call npm run build
if errorlevel 1 (
echo [错误] BlockPilotMC 构建失败。
goto :Failed
)
call :ReadPanelPort
call :ApiIsReady
if not errorlevel 1 (
echo [信息] 检测到端口 !PANEL_PORT! 已有 BlockPilotMC API 正常运行。
goto :ApiReady
)
echo [信息] 正在打开独立的 BlockPilotMC API 控制台...
call :StartApiConsole
if errorlevel 1 goto :Failed
echo [信息] 正在等待 API 启动完成...
call :WaitForApi
if errorlevel 1 (
echo [错误] API 未能在规定时间内启动,请查看另一个 API 控制台的错误信息。
goto :Failed
)
:ApiReady
set "PANEL_URL=http://127.0.0.1:!PANEL_PORT!"
echo.
echo [信息] WEB 界面已就绪:
echo !PANEL_URL!
echo [信息] API 信息只会显示在独立的 API 控制台。
start "" "!PANEL_URL!" >nul 2>&1
echo [信息] 启动完成,WEB 启动控制台将自动关闭;API 控制台会继续运行。
REM Successful startup no longer leaves the WEB launcher console open.
REM EXIT (not EXIT /B) closes the launcher cmd.exe / Windows Terminal tab while
REM the independent API console keeps running.
endlocal
exit 0
:ReadPanelPort
REM Read PORT from .env without exposing any other environment values in the console.
for /f "usebackq delims=" %%P in (`powershell -NoProfile -ExecutionPolicy Bypass -Command "$p=8787; if(Test-Path '.env'){ $line=Get-Content '.env' ^| Where-Object { $_ -match '^\s*PORT\s*=' } ^| Select-Object -Last 1; if($line){ $candidate=($line -split '=',2)[1].Trim(); $number=0; if([int]::TryParse($candidate,[ref]$number) -and $number -ge 1 -and $number -le 65535){ $p=$number } } }; Write-Output $p"`) do set "PANEL_PORT=%%P"
exit /b 0
:ApiIsReady
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { $response=Invoke-WebRequest -UseBasicParsing -Uri 'http://127.0.0.1:!PANEL_PORT!/api/health' -TimeoutSec 2; if($response.StatusCode -eq 200){ exit 0 } } catch {}; exit 1" >nul 2>&1
exit /b %ERRORLEVEL%
:StartApiConsole
if not exist "scripts\windows\Start-BlockPilot-API.cmd" (
echo [错误] 找不到 scripts\windows\Start-BlockPilot-API.cmd。
exit /b 1
)
REM The previous API health check intentionally returns ERRORLEVEL 1 when no API is running.
REM START can preserve that old value even after opening the console successfully, so clear it first.
"%ComSpec%" /d /c exit 0
call "%CD%\scripts\windows\Start-BlockPilot-API.cmd" zh-CN
if errorlevel 1 (
echo [错误] 无法打开独立 API 控制台。
exit /b 1
)
exit /b 0
:WaitForApi
powershell -NoProfile -ExecutionPolicy Bypass -Command "$url='http://127.0.0.1:!PANEL_PORT!/api/health'; for($i=0; $i -lt 45; $i++){ try { $response=Invoke-WebRequest -UseBasicParsing -Uri $url -TimeoutSec 2; if($response.StatusCode -eq 200){ exit 0 } } catch {}; Start-Sleep -Milliseconds 750 }; exit 1" >nul 2>&1
exit /b %ERRORLEVEL%
:EnsureNpm
REM 优先使用系统现有的 npm;找不到时,再通过 winget 安装包含 npm 的 Node.js LTS。
where npm >nul 2>&1
if not errorlevel 1 (
for /f "usebackq delims=" %%V in (`npm --version`) do echo [信息] 已检测到 npm %%V。
exit /b 0
)
echo [警告] 未检测到 npm,将尝试通过 winget 安装 Node.js LTS(包含 npm)。
where winget >nul 2>&1
if errorlevel 1 (
echo [错误] 此电脑没有 npm,也无法使用 winget 自动安装 Node.js。
echo [信息] 请先从 Node.js 官方网站安装 Node.js 22 或更高版本,再重新运行本文件。
exit /b 1
)
winget install --id OpenJS.NodeJS.LTS --exact --accept-package-agreements --accept-source-agreements
if errorlevel 1 (
echo [错误] Node.js LTS 自动安装失败。
exit /b 1
)
REM Add the common Node.js installation path to this console session so Windows does not need to be restarted.
if exist "%ProgramFiles%\nodejs\npm.cmd" set "PATH=%ProgramFiles%\nodejs;%PATH%"
where npm >nul 2>&1
if errorlevel 1 (
echo [错误] Node.js 已安装,但当前控制台仍找不到 npm。
echo [信息] 请关闭此窗口后重新运行 Start-BlockPilot-ZH.bat。
exit /b 1
)
exit /b 0
:PrintHeader
echo ============================================================
echo BlockPilotMC v1.0.5
echo WEB 启动控制台 - 中文简体
echo ============================================================
echo.
exit /b 0
:Failed
echo.
echo [信息] 请根据上方信息检查启动问题。
pause
exit /b 1