Files
Scoreboard/deploy/build.bat
T

80 lines
3.2 KiB
Batchfile

@echo off
chcp 65001 >nul
REM Build Windows artifacts on the build machine (Meowhome).
REM Output:
REM dist\scoreboard.exe server (frontend embedded via go:embed)
REM dist\ScoreboardConsole\ portable GUI manager (double-click to run)
REM
REM We do NOT use electron-builder NSIS: it downloads signing tools from GitHub,
REM which fails on restricted networks. The portable app is assembled by extracting
REM the official electron zip straight into the output directory.
setlocal
REM Must match console\package.json devDependencies.electron (pinned in console\pnpm-lock.yaml)
set "ELECTRON_VERSION=38.8.6"
set "ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron"
set "CONSOLE_OUT=dist\ScoreboardConsole"
set "ELECTRON_ZIP=dist\cache\electron-v%ELECTRON_VERSION%-win32-x64.zip"
cd /d "%~dp0.."
echo === [1/5] git pull ===
git pull || exit /b 1
echo === [2/5] web deps + build ===
cd web
call pnpm install --frozen-lockfile || exit /b 1
call pnpm build || exit /b 1
cd ..
echo === [3/5] server build ===
cd server
if not exist ..\dist mkdir ..\dist
go build -o ..\dist\scoreboard.exe . || exit /b 1
cd ..
echo === [4/5] console deps ===
cd console
call pnpm install --frozen-lockfile || exit /b 1
cd ..
echo === [5/5] assemble portable console ===
REM Old build may still be running; electron runtime files are read-only,
REM so the runtime is extracted once and only our own resources\app is rebuilt.
taskkill /im "Scoreboard Console.exe" /f >nul 2>&1
taskkill /im scoreboard.exe /f >nul 2>&1
if not exist "%CONSOLE_OUT%\Scoreboard Console.exe" call :install_runtime || exit /b 1
if exist "%CONSOLE_OUT%\resources\app" rmdir /s /q "%CONSOLE_OUT%\resources\app"
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 must sit next to the exe: the console resolves it from the exe dir
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
echo.
echo === 构建完成 ===
echo dist\scoreboard.exe 服务端
echo %CONSOLE_OUT%\Scoreboard Console.exe GUI 管理器(双击运行)
dir "%CONSOLE_OUT%"
endlocal
exit /b 0
REM ---- install electron runtime from the official zip (cached) ------------------
:install_runtime
if not exist "dist\cache" mkdir "dist\cache" || exit /b 1
if not exist "%ELECTRON_ZIP%" (
echo downloading electron %ELECTRON_VERSION% ...
curl -L --fail --max-time 900 -o "%ELECTRON_ZIP%" "%ELECTRON_MIRROR%/%ELECTRON_VERSION%/electron-v%ELECTRON_VERSION%-win32-x64.zip" || exit /b 1
)
echo extracting electron runtime ...
powershell -NoProfile -Command "Expand-Archive -LiteralPath '%ELECTRON_ZIP%' -DestinationPath '%CONSOLE_OUT%' -Force" || exit /b 1
if exist "%CONSOLE_OUT%\electron.exe" ren "%CONSOLE_OUT%\electron.exe" "Scoreboard Console.exe"
if not exist "%CONSOLE_OUT%\Scoreboard Console.exe" (
echo [ERROR] electron runtime install failed
exit /b 1
)
exit /b 0