90 lines
3.9 KiB
Batchfile
90 lines
3.9 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\console\ Scoreboard Console installer + portable dir
|
||
setlocal
|
||
|
||
REM electron / electron-builder 的下载走国内镜像 + gh 代理,避免 GitHub 直连超时
|
||
set "ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/"
|
||
set "ELECTRON_BUILDER_BINARIES_MIRROR=https://gh-proxy.com/https://github.com/electron-userland/electron-builder-binaries/releases/download/"
|
||
set "CSC_IDENTITY_AUTO_DISCOVERY=false"
|
||
|
||
cd /d "%~dp0.."
|
||
|
||
echo === [1/4] git pull ===
|
||
git pull || exit /b 1
|
||
|
||
echo === [2/4] web deps + build ===
|
||
cd web
|
||
call pnpm install --frozen-lockfile || exit /b 1
|
||
call pnpm build || exit /b 1
|
||
cd ..
|
||
|
||
echo === [3/4] server build ===
|
||
cd server
|
||
if not exist ..\dist mkdir ..\dist
|
||
REM 版本号注入 /api/health:优先取最近的 git tag,没有 tag 时退到短哈希
|
||
set "APP_VERSION=dev"
|
||
for /f "delims=" %%I in ('git describe --tags --always 2^>nul') do set "APP_VERSION=%%I"
|
||
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%' -X main.version=%APP_VERSION%" -o ..\dist\scoreboard.exe . || exit /b 1
|
||
echo internal signature injected
|
||
) else (
|
||
go build -ldflags "-X main.version=%APP_VERSION%" -o ..\dist\scoreboard.exe . || exit /b 1
|
||
echo no internal signature
|
||
)
|
||
cd ..
|
||
|
||
echo === [4/4] console package (electron-builder) ===
|
||
REM 安装器许可页顶部文案由本机署名生成(.nsh 是生成物,已 gitignore)
|
||
set "SIGNATURE_TEXT="
|
||
if exist "deploy\signature.local.txt" set /p SIGNATURE_TEXT=<"deploy\signature.local.txt"
|
||
> "console\resources\installer-signature.nsh" echo !macro customHeader
|
||
if defined SIGNATURE_TEXT (
|
||
>> "console\resources\installer-signature.nsh" echo !define MUI_LICENSEPAGE_TEXT_TOP "内部署名:%SIGNATURE_TEXT%"
|
||
) else (
|
||
>> "console\resources\installer-signature.nsh" echo !define MUI_LICENSEPAGE_TEXT_TOP "请阅读并接受许可协议"
|
||
)
|
||
>> "console\resources\installer-signature.nsh" echo !macroend
|
||
REM win.icon 由 electron-builder 内部调 rcedit 写进 PE 资源;
|
||
REM 它需要的 winCodeSign / nsis 从 gh-proxy 取,签名关闭。
|
||
taskkill /im "Scoreboard Console.exe" /f >nul 2>&1
|
||
taskkill /im scoreboard.exe /f >nul 2>&1
|
||
REM 部署包根目录要带 rules\ 与使用说明;rules\ 由 package.json 的 extraFiles 拷入。
|
||
REM 注意:cmd 对 UTF-8 中文放进 if(...) 块会解析错乱,所以块内一律用 ASCII,
|
||
REM 中文只出现在顶层命令的路径字面量里。
|
||
if not exist "rules" echo [warn] rules\ missing
|
||
if not exist "console\extra" mkdir "console\extra"
|
||
if exist "console\extra\使用说明.txt" del /q "console\extra\使用说明.txt"
|
||
if exist "docs\使用说明.txt" goto :usage_from_txt
|
||
if exist "docs\使用手册.md" goto :usage_from_md
|
||
echo [docs] no usage doc, skip
|
||
goto :usage_done
|
||
:usage_from_txt
|
||
copy /y "docs\使用说明.txt" "console\extra\使用说明.txt" >nul
|
||
echo usage doc added
|
||
goto :usage_done
|
||
:usage_from_md
|
||
copy /y "docs\使用手册.md" "console\extra\使用说明.txt" >nul
|
||
echo usage doc added (from manual)
|
||
:usage_done
|
||
cd console
|
||
call pnpm install --frozen-lockfile || exit /b 1
|
||
call pnpm run dist || exit /b 1
|
||
cd ..
|
||
|
||
echo.
|
||
echo === 构建完成 ===
|
||
echo dist\scoreboard.exe 服务端
|
||
echo dist\console\ Console 安装包 + 免安装目录
|
||
dir /b dist\console
|
||
endlocal
|
||
exit /b 0
|