Files
Scoreboard/deploy/build.bat
T

129 lines
5.7 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
REM 内部署名从构建机本地文件注入(deploy\signature.local.txt 已 gitignore,不进公开仓库);
REM 文件不存在时二进制里也是空的,源码永远不含真实署名。
set "INTERNAL_SIGNATURE="
if exist "..\deploy\signature.local.txt" set /p INTERNAL_SIGNATURE=<"..\deploy\signature.local.txt"
if defined INTERNAL_SIGNATURE (
REM 单引号包裹整个 -X:署名里的空格不会被 ldflags 拆开(go 的 ldflags 解析器认单引号)
go build -ldflags "-X 'git.yeij.top/AskaEth/Scoreboard/server/internal/version.InternalSignature=%INTERNAL_SIGNATURE%'" -o ..\dist\scoreboard.exe . || exit /b 1
echo internal signature injected
) else (
go build -o ..\dist\scoreboard.exe . || exit /b 1
echo no internal signature
)
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
REM app icon: the console loads it from the exe directory for tray / window icon
copy /y "console\scoreboard.png" "%CONSOLE_OUT%\scoreboard.png" >nul || exit /b 1
call :apply_icon
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
REM ---- stamp the app icon / version info into the exe --------------------------
REM electron-builder 的 "win.icon" 内部也是调 rcedit 改 PE 资源;rcedit 打包在
REM winCodeSign 里(GitHub 下载不通),这里从国内镜像取,用本机 7z 解出。
:apply_icon
set "RCEDIT=deploy\tools\rcedit-x64.exe"
if exist "dist\cache\winCodeSign-2.6.0\rcedit-x64.exe" set "RCEDIT=dist\cache\winCodeSign-2.6.0\rcedit-x64.exe"
if not exist "%RCEDIT%" call :fetch_rcedit
if not exist "%RCEDIT%" (
echo [warn] rcedit unavailable, exe icon skipped
exit /b 0
)
"%RCEDIT%" "%CONSOLE_OUT%\Scoreboard Console.exe" ^
--set-icon "console\build\icon.ico" ^
--set-version-string "ProductName" "Scoreboard Console" ^
--set-version-string "FileDescription" "Scoreboard Console" ^
--set-version-string "CompanyName" "AskaEth" ^
--set-file-version "0.1.0" ^
--set-product-version "0.1.0" || exit /b 1
echo app icon stamped
exit /b 0
:fetch_rcedit
set "SEVEN_ZIP="
if exist "%ProgramFiles%\7-Zip\7z.exe" set "SEVEN_ZIP=%ProgramFiles%\7-Zip\7z.exe"
if not defined SEVEN_ZIP if exist "%USERPROFILE%\7z.exe" set "SEVEN_ZIP=%USERPROFILE%\7z.exe"
if not defined SEVEN_ZIP exit /b 0
if not exist "dist\cache" mkdir "dist\cache" 2>nul
if not exist "dist\cache\winCodeSign-2.6.0.7z" (
echo downloading winCodeSign (for rcedit) ...
curl -L --fail --max-time 600 -o "dist\cache\winCodeSign-2.6.0.7z" "https://npmmirror.com/mirrors/electron-builder-binaries/winCodeSign-2.6.0/winCodeSign-2.6.0.7z" || exit /b 0
)
"%SEVEN_ZIP%" x -y -o"dist\cache\winCodeSign-2.6.0" "dist\cache\winCodeSign-2.6.0.7z" rcedit-x64.exe >nul || exit /b 0
exit /b 0