Files
server_manager/scripts/package/build.bat
T
2026-05-22 00:16:08 +08:00

117 lines
4.0 KiB
Batchfile

@echo off
REM ASCII-only batch: reliable under cmd.exe from PowerShell/Python (no UTF-8 BOM issues).
chcp 65001 >nul 2>&1
setlocal EnableExtensions EnableDelayedExpansion
title Server Manager - build
for %%I in ("%~dp0..\..") do set "ROOT=%%~fI"
set "SRC=%ROOT%\src"
set "RESOURCE_CONFIG=%ROOT%\resources\config"
pushd "%SRC%" || (
echo [ERROR] src directory not found: %SRC%
exit /b 1
)
echo ============================================================
echo Server Manager - build EXE
echo ============================================================
echo.
python --version >nul 2>&1
if errorlevel 1 (
echo [ERROR] Python not found. Install Python 3.8+
pause
exit /b 1
)
echo [1/6] pip deps...
pip install PyQt6 pyinstaller -q 2>nul
pip install pymysql Pillow -q 2>nul
python -c "import PyQt6" 2>nul
if errorlevel 1 (
echo [ERROR] pip install PyQt6
pause
exit /b 1
)
python -c "import PyInstaller" 2>nul
if errorlevel 1 (
echo [ERROR] pip install pyinstaller
pause
exit /b 1
)
echo [2/6] icon...
python "%ROOT%\resources\icon\convert_icon.py"
if not exist "%ROOT%\resources\icon\icon.ico" (
echo [WARN] no icon.ico, using --icon NONE
set "ICON_PARAM=--icon NONE"
) else (
set "ICON_PARAM=--icon %ROOT%\resources\icon\icon.ico"
)
echo [3/6] clean dist\build...
if exist "dist" rd /s /q dist
if exist "build" rd /s /q build
if exist "*.spec" del /q *.spec 2>nul
REM Pre-create work dir for PyInstaller warn-main.txt on some Windows setups
if not exist "build\main" mkdir "build\main"
echo [4/6] PyInstaller main (onedir)...
REM Single line: no ^ line-continuation (avoids trailing-space / encoding breakage)
pyinstaller --noconfirm --onedir --console --name main !ICON_PARAM! --add-data "%ROOT%\resources\version.json;." --add-data "%ROOT%\resources\config.json;." --add-data "%ROOT%\resources\icon;icon" --hidden-import PyQt6.QtWidgets --hidden-import PyQt6.QtCore --hidden-import PyQt6.QtGui --hidden-import pymysql --hidden-import entrypoints.cli.main --hidden-import entrypoints.cli.extended --hidden-import entrypoints.gui.bootstrap --hidden-import mcp.server --hidden-import mcp.tools --hidden-import models.app_config --hidden-import services.commands --hidden-import services.server_creator --hidden-import services.hot_update --hidden-import services.rg_search --hidden-import bsdiff4 --collect-all PyQt6 --collect-all bsdiff4 --hidden-import requests entrypoints\main.py
if errorlevel 1 (
echo [ERROR] main PyInstaller failed
pause
exit /b 1
)
echo [4b/6] copy rg.exe...
if exist "%ROOT%\resources\bin\rg.exe" (
copy /y "%ROOT%\resources\bin\rg.exe" "dist\main\rg.exe" >nul
echo copied resources\bin\rg.exe to dist\main\rg.exe
) else (
echo [WARN] resources\bin\rg.exe missing, search will not use ripgrep
)
echo [4c/6] copy resources\config templates to dist\main\config ^(same as installer {app}\config^)...
if exist "%RESOURCE_CONFIG%" (
if not exist "dist\main\config" mkdir "dist\main\config"
xcopy "%RESOURCE_CONFIG%\*" "dist\main\config\" /E /I /Y /Q >nul
echo copied ..\resources\config to dist\main\config
) else (
echo [WARN] ..\resources\config missing, Inno install will fail if resources\config is absent at compile time
)
echo [5/6] PyInstaller mini_updater...
pyinstaller --noconfirm --onefile --windowed --name mini_updater --distpath dist --workpath build_mini --specpath build_mini "%ROOT%\scripts\update\mini_updater.py"
if errorlevel 1 (
echo [ERROR] mini_updater PyInstaller failed
pause
exit /b 1
)
echo [6/6] done.
if not exist "dist\main\config" mkdir "dist\main\config"
if exist "config\tool.config" copy /y "config\tool.config" "dist\main\config\tool.config" >nul
rd /s /q build 2>nul
rd /s /q build_mini 2>nul
del /q *.spec 2>nul
del /q build_mini\*.spec 2>nul
echo.
echo ============================================================
echo OK: dist\main\ dist\mini_updater.exe
echo ============================================================
echo.
if /i not "%~1"=="nopause" pause
popd
endlocal
exit /b 0