Files
pqs-9100_tool_client/build-portable.bat
hongawen 51d607d970 调整界面
调整脚本
增加功能:备份、恢复、清空
2026-04-03 14:05:18 +08:00

130 lines
2.6 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
cd /d "%~dp0"
set "ROOT_DIR=%CD%"
set "OUT_DIR=%ROOT_DIR%\out"
set "SOURCE_DIR=%OUT_DIR%\win-unpacked"
set "RELEASE_DIR=%OUT_DIR%\NPQS9100_tool"
set "APP_NAME=NPQS9100_tool.exe"
set "LOG_FILE=%ROOT_DIR%\build-portable.log"
if exist "%LOG_FILE%" del /q "%LOG_FILE%"
call :log "========================================"
call :log "Building folder app..."
call :log "Project: %ROOT_DIR%"
call :log "Source : %SOURCE_DIR%"
call :log "Target : %RELEASE_DIR%"
call :log "========================================"
where npm >nul 2>nul
if errorlevel 1 (
call :fail "npm not found. Please install Node.js first."
goto :end
)
call :run "Installing root dependencies" "npm install"
if errorlevel 1 goto :end
call :run "Installing frontend dependencies" "npm install --prefix frontend"
if errorlevel 1 goto :end
call :run "Building project" "npm run build"
if errorlevel 1 goto :end
call :run "Packaging folder app" "npm run build-wd"
if errorlevel 1 goto :end
call :log ""
call :log "[5/5] Renaming output folder..."
if not exist "%OUT_DIR%" (
call :fail "out folder does not exist."
goto :end
)
if exist "%RELEASE_DIR%" (
rd /s /q "%RELEASE_DIR%"
if errorlevel 1 (
call :fail "failed to delete existing target folder: %RELEASE_DIR%"
goto :end
)
)
if not exist "%SOURCE_DIR%" (
call :fail "folder output not found: %SOURCE_DIR%"
goto :end
)
ren "%SOURCE_DIR%" "NPQS9100_tool"
if errorlevel 1 (
call :fail "failed to rename win-unpacked to NPQS9100_tool"
goto :end
)
for %%F in ("%OUT_DIR%\*.exe") do (
if exist "%%~fF" del /q "%%~fF"
)
for %%F in ("%RELEASE_DIR%\*.exe") do (
if /i not "%%~nxF"=="%APP_NAME%" (
ren "%%~fF" "%APP_NAME%"
goto :renamed
)
)
:renamed
call :log ""
call :log "Folder app ready:"
call :log "Folder: %RELEASE_DIR%"
call :log "EXE : %RELEASE_DIR%\%APP_NAME%"
call :log "Runtime logs will be written beside the exe as:"
call :log "%RELEASE_DIR%\runtime.log"
call :log "Build log:"
call :log "%LOG_FILE%"
call :log "========================================"
goto :success
:run
set "STEP_NAME=%~1"
set "STEP_CMD=%~2"
call :log ""
call :log "==== %STEP_NAME% ===="
call :log "CMD: %STEP_CMD%"
cmd /c "%STEP_CMD%" >> "%LOG_FILE%" 2>&1
if errorlevel 1 (
call :fail "%STEP_NAME% failed."
exit /b 1
)
call :log "%STEP_NAME% completed."
exit /b 0
:log
if "%~1"=="" (
echo.
>> "%LOG_FILE%" echo.
exit /b 0
)
echo %~1
>> "%LOG_FILE%" echo %~1
exit /b 0
:fail
call :log "[ERROR] %~1"
call :log "Please check: %LOG_FILE%"
echo.
echo [ERROR] %~1
echo See log: %LOG_FILE%
exit /b 1
:success
echo.
echo Build finished successfully.
pause
:end
endlocal