feat: Add --api-url parameter to build-client.bat
Now you can specify the backend API URL when building: build-client.bat build --api-url "http://192.168.1.100:8000/api" This updates client/config.json before packaging so the exe connects to the specified backend server. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,7 @@ set "BUILD_DIR=%PROJECT_DIR%\build"
|
|||||||
REM 預設配置
|
REM 預設配置
|
||||||
set "SKIP_SIDECAR=false"
|
set "SKIP_SIDECAR=false"
|
||||||
set "CLEAN_BUILD=false"
|
set "CLEAN_BUILD=false"
|
||||||
|
set "API_URL="
|
||||||
|
|
||||||
REM 解析參數
|
REM 解析參數
|
||||||
set "COMMAND=help"
|
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"=="help" (set "COMMAND=help" & shift & goto :parse_args)
|
||||||
if /i "%~1"=="--skip-sidecar" (set "SKIP_SIDECAR=true" & 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"=="--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
|
echo %RED%[ERROR]%NC% 未知參數: %~1
|
||||||
goto :show_help
|
goto :show_help
|
||||||
|
|
||||||
@@ -93,6 +95,28 @@ if %errorlevel% equ 0 (
|
|||||||
echo %RED%[ERROR]%NC% 需要 Python 3.10 或更高版本
|
echo %RED%[ERROR]%NC% 需要 Python 3.10 或更高版本
|
||||||
exit /b 1
|
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
|
:do_clean
|
||||||
echo %BLUE%[STEP]%NC% 清理建置目錄...
|
echo %BLUE%[STEP]%NC% 清理建置目錄...
|
||||||
|
|
||||||
@@ -276,6 +300,9 @@ if errorlevel 1 exit /b 1
|
|||||||
|
|
||||||
if "%CLEAN_BUILD%"=="true" call :do_clean
|
if "%CLEAN_BUILD%"=="true" call :do_clean
|
||||||
|
|
||||||
|
REM 更新 API URL(如果有指定)
|
||||||
|
call :update_config
|
||||||
|
|
||||||
if "%SKIP_SIDECAR%"=="false" (
|
if "%SKIP_SIDECAR%"=="false" (
|
||||||
call :setup_sidecar_venv
|
call :setup_sidecar_venv
|
||||||
call :build_sidecar
|
call :build_sidecar
|
||||||
@@ -337,11 +364,14 @@ echo clean 清理建置目錄
|
|||||||
echo help 顯示此幫助訊息
|
echo help 顯示此幫助訊息
|
||||||
echo.
|
echo.
|
||||||
echo 選項:
|
echo 選項:
|
||||||
|
echo --api-url URL 後端 API URL (預設: http://localhost:8000/api)
|
||||||
echo --skip-sidecar 跳過 Sidecar 打包
|
echo --skip-sidecar 跳過 Sidecar 打包
|
||||||
echo --clean 建置前先清理
|
echo --clean 建置前先清理
|
||||||
echo.
|
echo.
|
||||||
echo 範例:
|
echo 範例:
|
||||||
echo %~nx0 build 完整建置
|
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 sidecar 僅打包 Sidecar
|
||||||
echo %~nx0 electron --skip-sidecar 僅打包 Electron
|
echo %~nx0 electron --skip-sidecar 僅打包 Electron
|
||||||
echo.
|
echo.
|
||||||
|
|||||||
Reference in New Issue
Block a user