Files
Scoreboard/deploy/build.bat
T

77 lines
3.3 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
REM 在 Windows 构建机(Meowhome)上一键构建 Windows 产物。
REM 产物:
REM dist\scoreboard.exe 服务端(前端已 go:embed 内嵌)
REM dist\console\ScoreboardConsole\ 便携版 GUI 管理器(双击即用,免安装)
REM
REM 说明:不用 electron-builder 的 NSIS 打包,因为它会从 GitHub 下载签名工具,
REM 离线/受限网络下必失败。改为手动组装便携版:Electron 运行时 + resources\app。
setlocal
REM Electron 版本必须与 console\package.json 的 devDependencies.electron 一致(锁在 console\pnpm-lock.yaml)
set "ELECTRON_VERSION=38.8.6"
set "ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron"
set "CONSOLE_OUT=dist\console\ScoreboardConsole"
cd /d "%~dp0.."
echo === [1/5] git pull ===
git pull || exit /b 1
echo === [2/5] 前端依赖与构建 ===
cd web
call pnpm install --frozen-lockfile || exit /b 1
call pnpm build || exit /b 1
cd ..
echo === [3/5] 服务端构建 ===
cd server
if not exist ..\dist mkdir ..\dist
go build -o ..\dist\scoreboard.exe . || exit /b 1
cd ..
echo === [4/5] Console 依赖 + Electron 二进制 ===
cd console
call pnpm install --frozen-lockfile || exit /b 1
call :ensure_electron || exit /b 1
cd ..
echo === [5/5] 组装便携版 Console ===
REM 旧版本可能正在运行,且 Electron 解压出来的 .pak 带只读属性,普通 rmdir 删不掉
taskkill /im "Scoreboard Console.exe" /f >nul 2>&1
taskkill /im scoreboard.exe /f >nul 2>&1
powershell -NoProfile -Command "if (Test-Path '%CONSOLE_OUT%') { Remove-Item -Recurse -Force '%CONSOLE_OUT%' }" || exit /b 1
mkdir "%CONSOLE_OUT%" || exit /b 1
xcopy /e /i /y "console\node_modules\electron\dist" "%CONSOLE_OUT%" >nul || exit /b 1
mkdir "%CONSOLE_OUT%\resources\app" 2>nul
xcopy /e /i /y "console\main" "%CONSOLE_OUT%\resources\app\main" >nul || exit /b 1
xcopy /e /i /y "console\renderer" "%CONSOLE_OUT%\resources\app\renderer" >nul || exit /b 1
copy /y "console\package.json" "%CONSOLE_OUT%\resources\app\package.json" >nul || exit /b 1
REM config.json 必须放在 exe 同级(Console 按 exe 目录解析配置)
copy /y "console\config.json" "%CONSOLE_OUT%\config.json" >nul || exit /b 1
copy /y "dist\scoreboard.exe" "%CONSOLE_OUT%\scoreboard.exe" >nul || exit /b 1
copy /y "config.yaml" "%CONSOLE_OUT%\config.yaml" >nul || exit /b 1
ren "%CONSOLE_OUT%\electron.exe" "Scoreboard Console.exe" || exit /b 1
echo.
echo === 构建完成 ===
echo dist\scoreboard.exe 服务端
echo %CONSOLE_OUT%\Scoreboard Console.exe GUI 管理器(双击运行)
dir "%CONSOLE_OUT%"
endlocal
exit /b 0
REM ---- 确保 Electron 二进制就位(pnpm 默认跳过 postinstall) -------------------
:ensure_electron
if exist node_modules\electron\dist\electron.exe (
echo Electron 二进制已就绪
exit /b 0
)
echo 下载 Electron %ELECTRON_VERSION% ...
curl -L --fail --max-time 900 -o electron-dl.zip "%ELECTRON_MIRROR%/%ELECTRON_VERSION%/electron-v%ELECTRON_VERSION%-win32-x64.zip" || exit /b 1
powershell -NoProfile -Command "Expand-Archive -LiteralPath 'electron-dl.zip' -DestinationPath 'node_modules/electron/dist' -Force" || exit /b 1
del /q electron-dl.zip
echo electron.exe> node_modules\electron\path.txt
echo Electron 二进制已放置
exit /b 0