Files
Meshray-Manager/build.bat
T
2026-06-30 15:14:37 +08:00

94 lines
2.7 KiB
Batchfile

@echo off
chcp 65001 >nul
REM MeshRay Windows GUI 构建脚本 - 无控制台窗口版本
echo ============================================
echo MeshRay 编译工具 v2.0.0
echo ============================================
echo.
cd /d "%~dp0"
REM 步骤 1: 检查前端资源
echo [1/5] 检查前端资源...
if not exist "web\dist\index.html" (
echo [!] 前端资源不存在,正在编译...
cd web
call npm run build
if errorlevel 1 (
echo [ERROR] 前端编译失败!
exit /b 1
)
cd ..
) else (
echo [+] 前端资源已存在
)
REM 步骤 2: 清理缓存
echo.
echo [2/5] 清理 Go 构建缓存...
go clean -cache
echo [+] 缓存清理完成
REM 步骤 3: 获取版本信息
echo.
echo [3/5] 收集版本信息...
for /f "tokens=*" %%i in ('git rev-parse --short HEAD 2^>nul') do set GIT_COMMIT=%%i
if "%GIT_COMMIT%"=="" set GIT_COMMIT=unknown
set BUILD_TIME=%date% %time%
set VERSION=2.0.0
echo 版本:%VERSION%
echo Git Commit: %GIT_COMMIT%
echo 编译时间:%BUILD_TIME%
REM 步骤 4: 编译 Windows 程序
echo.
echo [4/5] 编译 Windows 程序 (带服务支持)...
REM 移除了 -s -w -H=windowsgui 过度混淆导致杀毒软件误报的问题
set LDFLAGS=-X main.Version=%VERSION% -X main.BuildTime="%BUILD_TIME%" -X main.GitCommit=%GIT_COMMIT%
go build -o meshray.exe -ldflags "%LDFLAGS%" ./cmd/meshray
if errorlevel 1 (
echo.
echo [ERROR] 编译失败!
exit /b 1
)
REM 步骤 5: 嵌入图标和版本信息
echo.
echo [5/5] 嵌入 Windows 资源 (图标 + 版本信息)...
where go-winres >nul 2>&1
if errorlevel 1 (
echo [!] go-winres 未安装,跳过资源嵌入
echo 安装命令: go install github.com/tc-hib/go-winres@latest
) else (
go-winres patch --in build\winres.json meshray.exe
if errorlevel 1 (
echo [WARN] 资源嵌入失败,但程序仍可运行
) else (
echo [+] 图标和版本信息嵌入成功
)
)
REM 显示结果
echo.
echo ============================================
echo 编译成功!
echo ============================================
echo 输出文件:meshray.exe
for %%I in ("meshray.exe") do echo 文件大小:%%~zI 字节
echo 配置参数:已移除混淆标志,增加对 Windows 服务的原生支持
echo 服务支持命令:
echo meshray install - 安装为系统服务
echo meshray start - 启动服务
echo meshray stop - 停止服务
echo meshray uninstall - 卸载服务
echo ============================================
echo.
echo 提示:
echo 直接双击 meshray.exe 将在桌面显示图标托盘。
echo 如果想后台挂机免打扰,推荐管理员打开命令行执行: meshray install
echo.