diff --git a/scripts/build-client.bat b/scripts/build-client.bat index 6f3e068..fcba6ca 100644 --- a/scripts/build-client.bat +++ b/scripts/build-client.bat @@ -23,6 +23,7 @@ set "BUILD_DIR=%PROJECT_DIR%\build" REM 預設配置 set "SKIP_SIDECAR=false" set "CLEAN_BUILD=false" +set "API_URL=" REM 解析參數 set "COMMAND=help" @@ -35,6 +36,7 @@ if /i "%~1"=="clean" (set "COMMAND=clean" & shift & goto :parse_args) if /i "%~1"=="help" (set "COMMAND=help" & shift & goto :parse_args) if /i "%~1"=="--skip-sidecar" (set "SKIP_SIDECAR=true" & shift & goto :parse_args) if /i "%~1"=="--clean" (set "CLEAN_BUILD=true" & shift & goto :parse_args) +if /i "%~1"=="--api-url" (set "API_URL=%~2" & shift & shift & goto :parse_args) echo %RED%[ERROR]%NC% 未知參數: %~1 goto :show_help @@ -93,6 +95,28 @@ if %errorlevel% equ 0 ( echo %RED%[ERROR]%NC% 需要 Python 3.10 或更高版本 exit /b 1 +:update_config +if "%API_URL%"=="" goto :eof + +echo %BLUE%[STEP]%NC% 更新 API URL 設定... + +set "CONFIG_FILE=%CLIENT_DIR%\config.json" +if not exist "%CONFIG_FILE%" ( + echo %YELLOW%[WARN]%NC% 找不到 config.json,跳過 API URL 設定 + goto :eof +) + +REM 使用 PowerShell 更新 JSON +powershell -Command "$config = Get-Content '%CONFIG_FILE%' -Raw | ConvertFrom-Json; $config.apiBaseUrl = '%API_URL%'; $config | ConvertTo-Json -Depth 10 | Set-Content '%CONFIG_FILE%' -Encoding UTF8" + +if errorlevel 1 ( + echo %RED%[ERROR]%NC% 更新 config.json 失敗 + exit /b 1 +) + +echo %GREEN%[OK]%NC% API URL 已設定為: %API_URL% +goto :eof + :do_clean echo %BLUE%[STEP]%NC% 清理建置目錄... @@ -276,6 +300,9 @@ if errorlevel 1 exit /b 1 if "%CLEAN_BUILD%"=="true" call :do_clean +REM 更新 API URL(如果有指定) +call :update_config + if "%SKIP_SIDECAR%"=="false" ( call :setup_sidecar_venv call :build_sidecar @@ -337,13 +364,16 @@ echo clean 清理建置目錄 echo help 顯示此幫助訊息 echo. echo 選項: +echo --api-url URL 後端 API URL (預設: http://localhost:8000/api) echo --skip-sidecar 跳過 Sidecar 打包 echo --clean 建置前先清理 echo. echo 範例: -echo %~nx0 build 完整建置 -echo %~nx0 sidecar 僅打包 Sidecar -echo %~nx0 electron --skip-sidecar 僅打包 Electron +echo %~nx0 build 完整建置 (使用預設 localhost) +echo %~nx0 build --api-url "http://192.168.1.100:8000/api" 指定後端 URL +echo %~nx0 build --api-url "https://api.company.com/api" 使用公司伺服器 +echo %~nx0 sidecar 僅打包 Sidecar +echo %~nx0 electron --skip-sidecar 僅打包 Electron echo. echo 注意: echo - 首次打包 Sidecar 需下載 Whisper 模型,可能需要較長時間