Files
ssh-manager/scripts/release/build-windows-installer.bat
2026-04-16 23:28:26 +08:00

147 lines
3.9 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
setlocal enabledelayedexpansion
set "ROOT=%~dp0..\.."
for %%I in ("%ROOT%") do set "ROOT=%%~fI"
set "STAGE_DIR=%ROOT%\release\windows-app"
set "OUT_DIR=%ROOT%\release\windows-installer"
set "JRE_DIR=%SSH_MANAGER_WINDOWS_JRE_DIR%"
set "VERSION_SCRIPT=%ROOT%\scripts\release\get-app-version.ps1"
cd /d "%ROOT%"
where powershell >nul 2>nul
if errorlevel 1 (
echo [ERROR] 未检测到 PowerShell无法解析版本号
pause
exit /b 1
)
for /f "usebackq delims=" %%V in (`powershell -NoProfile -ExecutionPolicy Bypass -File "%VERSION_SCRIPT%"`) do set "APP_VERSION=%%V"
if not defined APP_VERSION (
echo [ERROR] 无法从 backend\pom.xml 读取版本号
pause
exit /b 1
)
echo [INFO] 当前安装包版本: %APP_VERSION%
where npm >nul 2>nul
if errorlevel 1 (
echo [ERROR] 未检测到 npm请先安装 Node.js 18+
pause
exit /b 1
)
where mvn >nul 2>nul
if errorlevel 1 (
echo [ERROR] 未检测到 Maven请先安装 Maven 3.6+
pause
exit /b 1
)
if not defined JRE_DIR (
echo [ERROR] 请先设置环境变量 SSH_MANAGER_WINDOWS_JRE_DIR指向已解压的 Windows JRE 目录
pause
exit /b 1
)
if not exist "%JRE_DIR%\bin\javaw.exe" (
echo [ERROR] %JRE_DIR% 不是有效的 Windows JRE 目录,缺少 bin\javaw.exe
pause
exit /b 1
)
if exist "%STAGE_DIR%" rmdir /s /q "%STAGE_DIR%"
if exist "%OUT_DIR%" rmdir /s /q "%OUT_DIR%"
mkdir "%STAGE_DIR%"
mkdir "%OUT_DIR%"
echo [1/5] 构建前端...
cd /d "%ROOT%\frontend"
call npm run build
if errorlevel 1 (
echo [ERROR] 前端构建失败
pause
exit /b 1
)
echo [2/5] 打包后端(内嵌前端静态资源)...
cd /d "%ROOT%\backend"
call mvn -Pembed-frontend-dist -DskipTests package
if errorlevel 1 (
echo [ERROR] 后端打包失败
pause
exit /b 1
)
echo [3/5] 组装 Windows 应用目录...
copy /Y "%ROOT%\backend\target\*.jar" "%STAGE_DIR%\ssh-manager.jar" >nul
if errorlevel 1 (
echo [ERROR] 复制后端 jar 失败
pause
exit /b 1
)
xcopy "%JRE_DIR%" "%STAGE_DIR%\jre\" /E /I /Y >nul
if errorlevel 1 (
echo [ERROR] 复制 JRE 失败
pause
exit /b 1
)
copy /Y "%ROOT%\scripts\windows\start-installed.ps1" "%STAGE_DIR%\" >nul
copy /Y "%ROOT%\scripts\windows\start-installed.cmd" "%STAGE_DIR%\" >nul
copy /Y "%ROOT%\scripts\windows\start-installed.vbs" "%STAGE_DIR%\" >nul
copy /Y "%ROOT%\scripts\windows\stop-installed.ps1" "%STAGE_DIR%\" >nul
copy /Y "%ROOT%\scripts\windows\stop-installed.cmd" "%STAGE_DIR%\" >nul
copy /Y "%ROOT%\scripts\installer\assets\ssh-manager.ico" "%STAGE_DIR%\" >nul
copy /Y "%ROOT%\docs\windows-buyer-guide.md" "%STAGE_DIR%\BUYER-GUIDE.txt" >nul
copy /Y "%ROOT%\docs\windows-after-sales-faq.md" "%STAGE_DIR%\AFTER-SALES-FAQ.txt" >nul
(
echo SSH Manager Windows 成品版
echo.
echo 1. 运行安装包或直接双击 start-installed.vbs
echo 2. 程序会自动启动本地服务并打开浏览器
echo 3. 默认访问地址: http://127.0.0.1:48080
echo.
echo 数据目录:
echo %%LOCALAPPDATA%%\SSHManager\data
echo 日志目录:
echo %%LOCALAPPDATA%%\SSHManager\logs
echo.
echo 买家使用说明:
echo BUYER-GUIDE.txt
echo 售后排查 FAQ:
echo AFTER-SALES-FAQ.txt
echo.
echo 如需停止服务,可执行 stop-installed.cmd
) > "%STAGE_DIR%\README.txt"
echo [4/5] 检测 Inno Setup...
where ISCC.exe >nul 2>nul
if errorlevel 1 (
echo [WARN] 未检测到 ISCC.exe已生成 Windows 应用目录:
echo %STAGE_DIR%
echo [WARN] 安装 Inno Setup 后可手动执行:
echo ISCC.exe /DStageDir="%STAGE_DIR%" /DOutputDir="%OUT_DIR%" /DMyAppVersion="%APP_VERSION%" "%ROOT%\scripts\installer\ssh-manager.iss"
pause
exit /b 0
)
echo [5/5] 生成安装包...
ISCC.exe /DStageDir="%STAGE_DIR%" /DOutputDir="%OUT_DIR%" /DMyAppVersion="%APP_VERSION%" "%ROOT%\scripts\installer\ssh-manager.iss"
if errorlevel 1 (
echo [ERROR] Inno Setup 打包失败
pause
exit /b 1
)
echo.
echo Windows 安装包已生成:
echo %OUT_DIR%
pause
endlocal