From c19b4e82923ffe5db174b88c43153925dd1b7e63 Mon Sep 17 00:00:00 2001 From: egg Date: Tue, 16 Dec 2025 20:40:52 +0800 Subject: [PATCH] fix: Improve Windows build scripts to properly execute electron-builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - build-client.bat: Use node_modules\.bin\electron-builder.cmd directly - build-all.ps1: Use direct path to electron-builder instead of npm run - setup-backend.bat: Add UTF-8 support and use python -m pip 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- scripts/build-all.ps1 | 29 +- scripts/build-client.bat | 668 ++++++++++++++++++++------------------ scripts/setup-backend.bat | 475 +++++++++++++-------------- 3 files changed, 605 insertions(+), 567 deletions(-) diff --git a/scripts/build-all.ps1 b/scripts/build-all.ps1 index 24afe66..2b7ea49 100644 --- a/scripts/build-all.ps1 +++ b/scripts/build-all.ps1 @@ -217,10 +217,20 @@ function Build-Electron { exit 1 } - # 安裝依賴 - if (-not (Test-Path "node_modules")) { - Write-Host " 安裝 npm 依賴..." -ForegroundColor Gray - npm install + # 總是執行 npm install 確保依賴完整 + Write-Host " 安裝 npm 依賴..." -ForegroundColor Gray + npm install + if ($LASTEXITCODE -ne 0) { + Write-Err "npm install 失敗" + exit 1 + } + + # 確認 electron-builder 已安裝 + $electronBuilderPath = Join-Path $ClientDir "node_modules\.bin\electron-builder.cmd" + if (-not (Test-Path $electronBuilderPath)) { + Write-Err "electron-builder 未安裝" + Write-Warn "請確認 package.json 中的 devDependencies 包含 electron-builder" + exit 1 } # 建立 .env 如果不存在 @@ -230,12 +240,19 @@ function Build-Electron { } Write-Host " 執行 electron-builder..." -ForegroundColor Gray - npm run build -- --win + + # 直接執行 node_modules 中的 electron-builder + & $electronBuilderPath --win + + if ($LASTEXITCODE -ne 0) { + Write-Err "electron-builder 執行失敗" + exit 1 + } if (Test-Path "dist\*.exe") { Write-OK "Electron 打包完成" } else { - Write-Err "Electron 打包失敗" + Write-Err "Electron 打包失敗 - dist 目錄中找不到 exe 檔案" exit 1 } } diff --git a/scripts/build-client.bat b/scripts/build-client.bat index d9de4bd..7766386 100644 --- a/scripts/build-client.bat +++ b/scripts/build-client.bat @@ -1,324 +1,344 @@ -@echo off -REM Meeting Assistant Client - Windows 打包腳本 -REM 將 Electron 應用與 Python Sidecar 打包成免安裝 exe - -setlocal enabledelayedexpansion - -REM 顏色設定 (Windows 10+) -set "GREEN=[92m" -set "YELLOW=[93m" -set "RED=[91m" -set "BLUE=[94m" -set "CYAN=[96m" -set "NC=[0m" - -REM 專案路徑 -set "SCRIPT_DIR=%~dp0" -set "PROJECT_DIR=%SCRIPT_DIR%.." -set "CLIENT_DIR=%PROJECT_DIR%\client" -set "SIDECAR_DIR=%PROJECT_DIR%\sidecar" -set "BUILD_DIR=%PROJECT_DIR%\build" - -REM 預設配置 -set "SKIP_SIDECAR=false" -set "CLEAN_BUILD=false" - -REM 解析參數 -set "COMMAND=help" -:parse_args -if "%~1"=="" goto :main -if /i "%~1"=="build" (set "COMMAND=build" & shift & goto :parse_args) -if /i "%~1"=="sidecar" (set "COMMAND=sidecar" & shift & goto :parse_args) -if /i "%~1"=="electron" (set "COMMAND=electron" & shift & goto :parse_args) -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) -echo %RED%[ERROR]%NC% 未知參數: %~1 -goto :show_help - -:main -if "%COMMAND%"=="help" goto :show_help -if "%COMMAND%"=="build" goto :do_build -if "%COMMAND%"=="sidecar" goto :do_sidecar -if "%COMMAND%"=="electron" goto :do_electron -if "%COMMAND%"=="clean" goto :do_clean -goto :show_help - -:show_banner -echo. -echo %CYAN%========================================== -echo Meeting Assistant Client Builder -echo 打包 Electron + Sidecar 為免安裝執行檔 -echo ==========================================%NC% -echo. -goto :eof - -:check_environment -echo %BLUE%[STEP]%NC% 檢查建置環境... - -REM 檢查 Node.js -where node >nul 2>&1 -if %errorlevel% equ 0 ( - for /f "tokens=*" %%i in ('node --version') do echo %GREEN%[OK]%NC% Node.js: %%i -) else ( - echo %RED%[ERROR]%NC% Node.js 未安裝 - exit /b 1 -) - -REM 檢查 npm -where npm >nul 2>&1 -if %errorlevel% equ 0 ( - for /f "tokens=*" %%i in ('npm --version') do echo %GREEN%[OK]%NC% npm: %%i -) else ( - echo %RED%[ERROR]%NC% npm 未安裝 - exit /b 1 -) - -REM 檢查 Python -where python >nul 2>&1 -if %errorlevel% equ 0 ( - for /f "tokens=*" %%i in ('python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"') do set "PY_VERSION=%%i" - for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.major)"') do set "PY_MAJOR=%%i" - for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.minor)"') do set "PY_MINOR=%%i" - - if !PY_MAJOR! geq 3 if !PY_MINOR! geq 10 ( - set "PYTHON_CMD=python" - echo %GREEN%[OK]%NC% Python !PY_VERSION! - goto :eof - ) -) - -echo %RED%[ERROR]%NC% 需要 Python 3.10 或更高版本 -exit /b 1 - -:do_clean -echo %BLUE%[STEP]%NC% 清理建置目錄... - -if exist "%BUILD_DIR%" rmdir /s /q "%BUILD_DIR%" -if exist "%CLIENT_DIR%\dist" rmdir /s /q "%CLIENT_DIR%\dist" -if exist "%SIDECAR_DIR%\dist" rmdir /s /q "%SIDECAR_DIR%\dist" -if exist "%SIDECAR_DIR%\build" rmdir /s /q "%SIDECAR_DIR%\build" -if exist "%SIDECAR_DIR%\*.spec" del /q "%SIDECAR_DIR%\*.spec" - -echo %GREEN%[OK]%NC% 建置目錄已清理 -goto :eof - -:setup_sidecar_venv -echo %BLUE%[STEP]%NC% 設置 Sidecar 建置環境... - -cd /d "%SIDECAR_DIR%" - -if not exist "venv" ( - echo %BLUE%[INFO]%NC% 創建虛擬環境... - %PYTHON_CMD% -m venv venv -) - -echo %BLUE%[INFO]%NC% 安裝 Sidecar 依賴... -call venv\Scripts\activate.bat -pip install --upgrade pip -q -pip install -r requirements.txt -q - -echo %BLUE%[INFO]%NC% 安裝 PyInstaller... -pip install pyinstaller -q - -echo %GREEN%[OK]%NC% Sidecar 建置環境就緒 -goto :eof - -:build_sidecar -echo %BLUE%[STEP]%NC% 打包 Sidecar (Python → 獨立執行檔)... - -cd /d "%SIDECAR_DIR%" - -call venv\Scripts\activate.bat - -if not exist "dist" mkdir dist - -echo %BLUE%[INFO]%NC% 執行 PyInstaller... -echo %BLUE%[INFO]%NC% 這可能需要幾分鐘... - -pyinstaller ^ - --onedir ^ - --name transcriber ^ - --distpath dist ^ - --workpath build ^ - --specpath . ^ - --noconfirm ^ - --clean ^ - --log-level WARN ^ - --console ^ - --hidden-import=faster_whisper ^ - --hidden-import=ctranslate2 ^ - --hidden-import=huggingface_hub ^ - --hidden-import=tokenizers ^ - --hidden-import=onnxruntime ^ - --hidden-import=opencc ^ - --hidden-import=pydub ^ - --hidden-import=numpy ^ - --hidden-import=av ^ - --collect-data=onnxruntime ^ - --collect-data=faster_whisper ^ - transcriber.py - -if exist "dist\transcriber" ( - echo %GREEN%[OK]%NC% Sidecar 打包完成: %SIDECAR_DIR%\dist\transcriber -) else ( - echo %RED%[ERROR]%NC% Sidecar 打包失敗 - exit /b 1 -) -goto :eof - -:setup_client -echo %BLUE%[STEP]%NC% 設置前端建置環境... - -cd /d "%CLIENT_DIR%" - -if not exist "node_modules" ( - echo %BLUE%[INFO]%NC% 安裝前端依賴... - call npm install -) else ( - echo %BLUE%[INFO]%NC% 前端依賴已安裝 -) - -if not exist ".env" ( - if exist ".env.example" ( - copy .env.example .env >nul - echo %YELLOW%[WARN]%NC% 已創建 .env 檔案,請確認設定 - ) -) - -echo %GREEN%[OK]%NC% 前端建置環境就緒 -goto :eof - -:build_electron -echo %BLUE%[STEP]%NC% 打包 Electron 應用... - -cd /d "%CLIENT_DIR%" - -echo %BLUE%[INFO]%NC% 目標平台: Windows (Portable) -echo %BLUE%[INFO]%NC% 執行 electron-builder... - -call npm run build -- --win - -if exist "dist" ( - echo %GREEN%[OK]%NC% Electron 打包完成 - echo %BLUE%[INFO]%NC% 輸出目錄: %CLIENT_DIR%\dist -) else ( - echo %RED%[ERROR]%NC% Electron 打包失敗 - exit /b 1 -) -goto :eof - -:finalize_build -echo %BLUE%[STEP]%NC% 整合建置輸出... - -if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%" - -REM 複製 Electron 輸出 -if exist "%CLIENT_DIR%\dist" ( - xcopy /s /e /y "%CLIENT_DIR%\dist\*" "%BUILD_DIR%\" >nul 2>&1 -) - -echo. -echo %CYAN%========================================== -echo 建置完成 -echo ==========================================%NC% -echo. -echo 輸出目錄: %BUILD_DIR% -echo. - -dir /b "%BUILD_DIR%" - -echo. -echo %GREEN%[OK]%NC% 打包完成! -echo. -echo Windows 使用說明: -echo 1. 找到 build\ 中的 .exe 檔案 -echo 2. 直接執行即可,無需安裝 -echo. -goto :eof - -:do_build -call :show_banner -call :check_environment -if errorlevel 1 exit /b 1 - -if "%CLEAN_BUILD%"=="true" call :do_clean - -if "%SKIP_SIDECAR%"=="false" ( - call :setup_sidecar_venv - call :build_sidecar -) - -call :setup_client -call :build_electron -call :finalize_build -goto :eof - -:do_sidecar -call :show_banner -call :check_environment -if errorlevel 1 exit /b 1 - -if "%CLEAN_BUILD%"=="true" ( - if exist "%SIDECAR_DIR%\dist" rmdir /s /q "%SIDECAR_DIR%\dist" - if exist "%SIDECAR_DIR%\build" rmdir /s /q "%SIDECAR_DIR%\build" -) - -call :setup_sidecar_venv -call :build_sidecar -goto :eof - -:do_electron -call :show_banner -call :check_environment -if errorlevel 1 exit /b 1 - -if not exist "%SIDECAR_DIR%\dist\transcriber" ( - if "%SKIP_SIDECAR%"=="false" ( - echo %YELLOW%[WARN]%NC% Sidecar 尚未打包 - echo %BLUE%[INFO]%NC% 請先執行: %~nx0 sidecar - echo %BLUE%[INFO]%NC% 或使用 --skip-sidecar 跳過 - exit /b 1 - ) -) - -if "%CLEAN_BUILD%"=="true" ( - if exist "%CLIENT_DIR%\dist" rmdir /s /q "%CLIENT_DIR%\dist" -) - -call :setup_client -call :build_electron -call :finalize_build -goto :eof - -:show_help -echo. -echo Meeting Assistant Client - Windows 打包腳本 -echo. -echo 用法: %~nx0 [命令] [選項] -echo. -echo 命令: -echo build 完整建置 (Sidecar + Electron) -echo sidecar 僅打包 Sidecar -echo electron 僅打包 Electron (需先打包 Sidecar) -echo clean 清理建置目錄 -echo help 顯示此幫助訊息 -echo. -echo 選項: -echo --skip-sidecar 跳過 Sidecar 打包 -echo --clean 建置前先清理 -echo. -echo 範例: -echo %~nx0 build 完整建置 -echo %~nx0 sidecar 僅打包 Sidecar -echo %~nx0 electron --skip-sidecar 僅打包 Electron -echo. -echo 注意: -echo - 首次打包 Sidecar 需下載 Whisper 模型,可能需要較長時間 -echo - 確保有足夠的磁碟空間 (建議 5GB+) -echo. -goto :eof - -:end -endlocal +@echo off +chcp 65001 >nul +REM Meeting Assistant Client - Windows 打包腳本 +REM 將 Electron 應用與 Python Sidecar 打包成免安裝 exe + +setlocal enabledelayedexpansion + +REM 顏色設定 (Windows 10+) +set "GREEN=[92m" +set "YELLOW=[93m" +set "RED=[91m" +set "BLUE=[94m" +set "CYAN=[96m" +set "NC=[0m" + +REM 專案路徑 +set "SCRIPT_DIR=%~dp0" +set "PROJECT_DIR=%SCRIPT_DIR%.." +set "CLIENT_DIR=%PROJECT_DIR%\client" +set "SIDECAR_DIR=%PROJECT_DIR%\sidecar" +set "BUILD_DIR=%PROJECT_DIR%\build" + +REM 預設配置 +set "SKIP_SIDECAR=false" +set "CLEAN_BUILD=false" + +REM 解析參數 +set "COMMAND=help" +:parse_args +if "%~1"=="" goto :main +if /i "%~1"=="build" (set "COMMAND=build" & shift & goto :parse_args) +if /i "%~1"=="sidecar" (set "COMMAND=sidecar" & shift & goto :parse_args) +if /i "%~1"=="electron" (set "COMMAND=electron" & shift & goto :parse_args) +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) +echo %RED%[ERROR]%NC% 未知參數: %~1 +goto :show_help + +:main +if "%COMMAND%"=="help" goto :show_help +if "%COMMAND%"=="build" goto :do_build +if "%COMMAND%"=="sidecar" goto :do_sidecar +if "%COMMAND%"=="electron" goto :do_electron +if "%COMMAND%"=="clean" goto :do_clean +goto :show_help + +:show_banner +echo. +echo %CYAN%========================================== +echo Meeting Assistant Client Builder +echo 打包 Electron + Sidecar 為免安裝執行檔 +echo ==========================================%NC% +echo. +goto :eof + +:check_environment +echo %BLUE%[STEP]%NC% 檢查建置環境... + +REM 檢查 Node.js +where node >nul 2>&1 +if %errorlevel% equ 0 ( + for /f "tokens=*" %%i in ('node --version') do echo %GREEN%[OK]%NC% Node.js: %%i +) else ( + echo %RED%[ERROR]%NC% Node.js 未安裝 + exit /b 1 +) + +REM 檢查 npm +where npm >nul 2>&1 +if %errorlevel% equ 0 ( + for /f "tokens=*" %%i in ('npm --version') do echo %GREEN%[OK]%NC% npm: %%i +) else ( + echo %RED%[ERROR]%NC% npm 未安裝 + exit /b 1 +) + +REM 檢查 Python +where python >nul 2>&1 +if %errorlevel% equ 0 ( + for /f "tokens=*" %%i in ('python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"') do set "PY_VERSION=%%i" + for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.major)"') do set "PY_MAJOR=%%i" + for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.minor)"') do set "PY_MINOR=%%i" + + if !PY_MAJOR! geq 3 if !PY_MINOR! geq 10 ( + set "PYTHON_CMD=python" + echo %GREEN%[OK]%NC% Python !PY_VERSION! + goto :eof + ) +) + +echo %RED%[ERROR]%NC% 需要 Python 3.10 或更高版本 +exit /b 1 + +:do_clean +echo %BLUE%[STEP]%NC% 清理建置目錄... + +if exist "%BUILD_DIR%" rmdir /s /q "%BUILD_DIR%" +if exist "%CLIENT_DIR%\dist" rmdir /s /q "%CLIENT_DIR%\dist" +if exist "%SIDECAR_DIR%\dist" rmdir /s /q "%SIDECAR_DIR%\dist" +if exist "%SIDECAR_DIR%\build" rmdir /s /q "%SIDECAR_DIR%\build" +if exist "%SIDECAR_DIR%\venv" rmdir /s /q "%SIDECAR_DIR%\venv" +if exist "%SIDECAR_DIR%\*.spec" del /q "%SIDECAR_DIR%\*.spec" + +echo %GREEN%[OK]%NC% 建置目錄已清理 +goto :eof + +:setup_sidecar_venv +echo %BLUE%[STEP]%NC% 設置 Sidecar 建置環境... + +cd /d "%SIDECAR_DIR%" + +if not exist "venv" ( + echo %BLUE%[INFO]%NC% 創建虛擬環境... + %PYTHON_CMD% -m venv venv +) + +echo %BLUE%[INFO]%NC% 安裝 Sidecar 依賴... +call venv\Scripts\activate.bat +python -m pip install --upgrade pip -q +python -m pip install -r requirements.txt -q + +echo %BLUE%[INFO]%NC% 安裝 PyInstaller... +python -m pip install pyinstaller -q + +echo %GREEN%[OK]%NC% Sidecar 建置環境就緒 +goto :eof + +:build_sidecar +echo %BLUE%[STEP]%NC% 打包 Sidecar (Python → 獨立執行檔)... + +cd /d "%SIDECAR_DIR%" + +call venv\Scripts\activate.bat + +if not exist "dist" mkdir dist + +echo %BLUE%[INFO]%NC% 執行 PyInstaller... +echo %BLUE%[INFO]%NC% 這可能需要幾分鐘... + +pyinstaller ^ + --onedir ^ + --name transcriber ^ + --distpath dist ^ + --workpath build ^ + --specpath . ^ + --noconfirm ^ + --clean ^ + --log-level WARN ^ + --console ^ + --hidden-import=faster_whisper ^ + --hidden-import=ctranslate2 ^ + --hidden-import=huggingface_hub ^ + --hidden-import=tokenizers ^ + --hidden-import=onnxruntime ^ + --hidden-import=opencc ^ + --hidden-import=pydub ^ + --hidden-import=numpy ^ + --hidden-import=av ^ + --collect-data=onnxruntime ^ + --collect-data=faster_whisper ^ + transcriber.py + +if exist "dist\transcriber" ( + echo %GREEN%[OK]%NC% Sidecar 打包完成: %SIDECAR_DIR%\dist\transcriber +) else ( + echo %RED%[ERROR]%NC% Sidecar 打包失敗 + exit /b 1 +) +goto :eof + +:setup_client +echo %BLUE%[STEP]%NC% 設置前端建置環境... + +cd /d "%CLIENT_DIR%" + +REM 總是執行 npm install 確保依賴完整 +echo %BLUE%[INFO]%NC% 安裝前端依賴... +call npm install +if errorlevel 1 ( + echo %RED%[ERROR]%NC% npm install 失敗 + exit /b 1 +) + +REM 確認 electron-builder 已安裝 +if not exist "node_modules\electron-builder" ( + echo %RED%[ERROR]%NC% electron-builder 未安裝 + echo %BLUE%[INFO]%NC% 請檢查 package.json 中的 devDependencies + exit /b 1 +) + +if not exist ".env" ( + if exist ".env.example" ( + copy .env.example .env >nul + echo %YELLOW%[WARN]%NC% 已創建 .env 檔案,請確認設定 + ) +) + +echo %GREEN%[OK]%NC% 前端建置環境就緒 +goto :eof + +:build_electron +echo %BLUE%[STEP]%NC% 打包 Electron 應用... + +cd /d "%CLIENT_DIR%" + +echo %BLUE%[INFO]%NC% 目標平台: Windows (Portable) +echo %BLUE%[INFO]%NC% 執行 electron-builder... + +REM 使用 npm run build 或直接執行 node_modules 中的 electron-builder +if exist "node_modules\.bin\electron-builder.cmd" ( + call "node_modules\.bin\electron-builder.cmd" --win +) else ( + call npx electron-builder --win +) + +if errorlevel 1 ( + echo %RED%[ERROR]%NC% electron-builder 執行失敗 + exit /b 1 +) + +if exist "dist" ( + echo %GREEN%[OK]%NC% Electron 打包完成 + echo %BLUE%[INFO]%NC% 輸出目錄: %CLIENT_DIR%\dist +) else ( + echo %RED%[ERROR]%NC% Electron 打包失敗 - dist 目錄不存在 + exit /b 1 +) +goto :eof + +:finalize_build +echo %BLUE%[STEP]%NC% 整合建置輸出... + +if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%" + +REM 複製 Electron 輸出 +if exist "%CLIENT_DIR%\dist" ( + xcopy /s /e /y "%CLIENT_DIR%\dist\*" "%BUILD_DIR%\" >nul 2>&1 +) + +echo. +echo %CYAN%========================================== +echo 建置完成 +echo ==========================================%NC% +echo. +echo 輸出目錄: %BUILD_DIR% +echo. + +dir /b "%BUILD_DIR%" + +echo. +echo %GREEN%[OK]%NC% 打包完成! +echo. +echo Windows 使用說明: +echo 1. 找到 build\ 中的 .exe 檔案 +echo 2. 直接執行即可,無需安裝 +echo. +goto :eof + +:do_build +call :show_banner +call :check_environment +if errorlevel 1 exit /b 1 + +if "%CLEAN_BUILD%"=="true" call :do_clean + +if "%SKIP_SIDECAR%"=="false" ( + call :setup_sidecar_venv + call :build_sidecar +) + +call :setup_client +call :build_electron +call :finalize_build +goto :eof + +:do_sidecar +call :show_banner +call :check_environment +if errorlevel 1 exit /b 1 + +if "%CLEAN_BUILD%"=="true" ( + if exist "%SIDECAR_DIR%\dist" rmdir /s /q "%SIDECAR_DIR%\dist" + if exist "%SIDECAR_DIR%\build" rmdir /s /q "%SIDECAR_DIR%\build" +) + +call :setup_sidecar_venv +call :build_sidecar +goto :eof + +:do_electron +call :show_banner +call :check_environment +if errorlevel 1 exit /b 1 + +if not exist "%SIDECAR_DIR%\dist\transcriber" ( + if "%SKIP_SIDECAR%"=="false" ( + echo %YELLOW%[WARN]%NC% Sidecar 尚未打包 + echo %BLUE%[INFO]%NC% 請先執行: %~nx0 sidecar + echo %BLUE%[INFO]%NC% 或使用 --skip-sidecar 跳過 + exit /b 1 + ) +) + +if "%CLEAN_BUILD%"=="true" ( + if exist "%CLIENT_DIR%\dist" rmdir /s /q "%CLIENT_DIR%\dist" +) + +call :setup_client +call :build_electron +call :finalize_build +goto :eof + +:show_help +echo. +echo Meeting Assistant Client - Windows 打包腳本 +echo. +echo 用法: %~nx0 [命令] [選項] +echo. +echo 命令: +echo build 完整建置 (Sidecar + Electron) +echo sidecar 僅打包 Sidecar +echo electron 僅打包 Electron (需先打包 Sidecar) +echo clean 清理建置目錄 +echo help 顯示此幫助訊息 +echo. +echo 選項: +echo --skip-sidecar 跳過 Sidecar 打包 +echo --clean 建置前先清理 +echo. +echo 範例: +echo %~nx0 build 完整建置 +echo %~nx0 sidecar 僅打包 Sidecar +echo %~nx0 electron --skip-sidecar 僅打包 Electron +echo. +echo 注意: +echo - 首次打包 Sidecar 需下載 Whisper 模型,可能需要較長時間 +echo - 確保有足夠的磁碟空間 (建議 5GB+) +echo. +goto :eof + +:end +endlocal diff --git a/scripts/setup-backend.bat b/scripts/setup-backend.bat index 4708c63..3a7825b 100644 --- a/scripts/setup-backend.bat +++ b/scripts/setup-backend.bat @@ -1,237 +1,238 @@ -@echo off -REM Meeting Assistant Backend - Windows 一鍵設置與啟動腳本 -REM 自動安裝依賴、設置環境並啟動後端服務 - -setlocal enabledelayedexpansion - -REM 顏色設定 (Windows 10+) -set "GREEN=[92m" -set "YELLOW=[93m" -set "RED=[91m" -set "BLUE=[94m" -set "CYAN=[96m" -set "NC=[0m" - -REM 專案路徑 -set "SCRIPT_DIR=%~dp0" -set "PROJECT_DIR=%SCRIPT_DIR%.." -set "BACKEND_DIR=%PROJECT_DIR%\backend" -set "SIDECAR_DIR=%PROJECT_DIR%\sidecar" - -REM 預設配置 -set "DEFAULT_PORT=8000" -set "DEFAULT_HOST=0.0.0.0" - -REM 解析參數 -set "COMMAND=start" -set "PORT=%DEFAULT_PORT%" -set "HOST=%DEFAULT_HOST%" -set "NO_SIDECAR=false" - -:parse_args -if "%~1"=="" goto :main -if /i "%~1"=="setup" (set "COMMAND=setup" & shift & goto :parse_args) -if /i "%~1"=="start" (set "COMMAND=start" & shift & goto :parse_args) -if /i "%~1"=="stop" (set "COMMAND=stop" & shift & goto :parse_args) -if /i "%~1"=="help" (set "COMMAND=help" & shift & goto :parse_args) -if /i "%~1"=="--port" (set "PORT=%~2" & shift & shift & goto :parse_args) -if /i "%~1"=="--host" (set "HOST=%~2" & shift & shift & goto :parse_args) -if /i "%~1"=="--no-sidecar" (set "NO_SIDECAR=true" & shift & goto :parse_args) -echo %RED%[ERROR]%NC% 未知參數: %~1 -goto :show_help - -:main -if "%COMMAND%"=="help" goto :show_help -if "%COMMAND%"=="setup" goto :do_setup -if "%COMMAND%"=="start" goto :do_start -if "%COMMAND%"=="stop" goto :do_stop -goto :show_help - -:show_banner -echo. -echo %CYAN%========================================== -echo Meeting Assistant Backend Setup -echo Windows 一鍵設置與啟動腳本 -echo ==========================================%NC% -echo. -goto :eof - -:check_python -echo %BLUE%[STEP]%NC% 檢查 Python 環境... - -REM 嘗試找到 Python -where python >nul 2>&1 -if %errorlevel% equ 0 ( - for /f "tokens=*" %%i in ('python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"') do set "PY_VERSION=%%i" - for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.major)"') do set "PY_MAJOR=%%i" - for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.minor)"') do set "PY_MINOR=%%i" - - if !PY_MAJOR! geq 3 if !PY_MINOR! geq 10 ( - set "PYTHON_CMD=python" - echo %GREEN%[OK]%NC% Python !PY_VERSION! - goto :eof - ) -) - -echo %RED%[ERROR]%NC% 需要 Python 3.10 或更高版本 -echo %BLUE%[INFO]%NC% 請安裝 Python: https://www.python.org/downloads/ -exit /b 1 - -:setup_backend_venv -echo %BLUE%[STEP]%NC% 設置後端虛擬環境... - -cd /d "%BACKEND_DIR%" - -if not exist "venv" ( - echo %BLUE%[INFO]%NC% 創建虛擬環境... - %PYTHON_CMD% -m venv venv - echo %GREEN%[OK]%NC% 虛擬環境已創建 -) else ( - echo %BLUE%[INFO]%NC% 虛擬環境已存在 -) - -echo %BLUE%[INFO]%NC% 安裝後端依賴... -call venv\Scripts\activate.bat -pip install --upgrade pip -q -pip install -r requirements.txt -q -echo %GREEN%[OK]%NC% 後端依賴安裝完成 -goto :eof - -:setup_sidecar_venv -echo %BLUE%[STEP]%NC% 設置 Sidecar 虛擬環境... - -cd /d "%SIDECAR_DIR%" - -if not exist "venv" ( - echo %BLUE%[INFO]%NC% 創建 Sidecar 虛擬環境... - %PYTHON_CMD% -m venv venv - echo %GREEN%[OK]%NC% Sidecar 虛擬環境已創建 -) else ( - echo %BLUE%[INFO]%NC% Sidecar 虛擬環境已存在 -) - -echo %BLUE%[INFO]%NC% 安裝 Sidecar 依賴 (這可能需要幾分鐘)... -call venv\Scripts\activate.bat -pip install --upgrade pip -q -pip install -r requirements.txt -q -echo %GREEN%[OK]%NC% Sidecar 依賴安裝完成 -goto :eof - -:setup_env_file -echo %BLUE%[STEP]%NC% 檢查環境變數配置... - -cd /d "%BACKEND_DIR%" - -if not exist ".env" ( - if exist ".env.example" ( - copy .env.example .env >nul - echo %YELLOW%[WARN]%NC% 已從 .env.example 創建 .env 檔案 - echo %YELLOW%[WARN]%NC% 請編輯 %BACKEND_DIR%\.env 設置資料庫和 API 密鑰 - ) else ( - echo %RED%[ERROR]%NC% 找不到 .env.example 檔案 - exit /b 1 - ) -) else ( - echo %GREEN%[OK]%NC% 環境變數檔案已存在 -) -goto :eof - -:start_backend -echo %BLUE%[STEP]%NC% 啟動後端服務... - -cd /d "%BACKEND_DIR%" - -REM 載入環境變數 -if exist ".env" ( - for /f "usebackq tokens=1,* delims==" %%a in (".env") do ( - set "%%a=%%b" - ) -) - -REM 使用 .env 中的配置或預設值 -if defined BACKEND_HOST set "HOST=%BACKEND_HOST%" -if defined BACKEND_PORT set "PORT=%BACKEND_PORT%" - -REM 啟動虛擬環境 -call venv\Scripts\activate.bat - -echo. -echo %GREEN%[OK]%NC% 後端服務準備就緒! -echo. -echo %CYAN%========================================== -echo 服務資訊 -echo ==========================================%NC% -echo. -echo API 地址: http://localhost:%PORT% -echo API 文件: http://localhost:%PORT%/docs -echo 健康檢查: http://localhost:%PORT%/api/health -echo. -echo 按 Ctrl+C 停止服務 -echo. - -uvicorn app.main:app --host %HOST% --port %PORT% --reload -goto :eof - -:do_setup -call :show_banner -call :check_python -if errorlevel 1 exit /b 1 -call :setup_backend_venv -if "%NO_SIDECAR%"=="false" call :setup_sidecar_venv -call :setup_env_file -echo. -echo %GREEN%[OK]%NC% 環境設置完成! -echo. -echo %BLUE%[INFO]%NC% 啟動服務: %~nx0 start -goto :eof - -:do_start -call :show_banner -call :check_python -if errorlevel 1 exit /b 1 -call :setup_backend_venv -call :setup_env_file -call :start_backend -goto :eof - -:do_stop -echo %BLUE%[STEP]%NC% 停止後端服務... - -REM 查找並終止 uvicorn 程序 -for /f "tokens=2" %%i in ('tasklist /fi "imagename eq python.exe" /fo list ^| findstr "PID:"') do ( - wmic process where "processid=%%i" get commandline 2>nul | findstr /i "uvicorn" >nul - if not errorlevel 1 ( - taskkill /pid %%i /f >nul 2>&1 - echo %GREEN%[OK]%NC% 已停止 PID: %%i - ) -) - -echo %GREEN%[OK]%NC% 後端服務已停止 -goto :eof - -:show_help -echo. -echo Meeting Assistant Backend - Windows 一鍵設置與啟動腳本 -echo. -echo 用法: %~nx0 [命令] [選項] -echo. -echo 命令: -echo setup 僅設置環境 (安裝依賴) -echo start 設置並啟動後端服務 (預設) -echo stop 停止後端服務 -echo help 顯示此幫助訊息 -echo. -echo 選項: -echo --port PORT 服務端口 (預設: %DEFAULT_PORT%) -echo --host HOST 綁定地址 (預設: %DEFAULT_HOST%) -echo --no-sidecar 不安裝 Sidecar 依賴 -echo. -echo 範例: -echo %~nx0 start 設置並啟動服務 -echo %~nx0 start --port 8080 使用自訂端口 -echo %~nx0 setup 僅安裝依賴 -echo. -goto :eof - -:end -endlocal +@echo off +chcp 65001 >nul +REM Meeting Assistant Backend - Windows 一鍵設置與啟動腳本 +REM 自動安裝依賴、設置環境並啟動後端服務 + +setlocal enabledelayedexpansion + +REM 顏色設定 (Windows 10+) +set "GREEN=[92m" +set "YELLOW=[93m" +set "RED=[91m" +set "BLUE=[94m" +set "CYAN=[96m" +set "NC=[0m" + +REM 專案路徑 +set "SCRIPT_DIR=%~dp0" +set "PROJECT_DIR=%SCRIPT_DIR%.." +set "BACKEND_DIR=%PROJECT_DIR%\backend" +set "SIDECAR_DIR=%PROJECT_DIR%\sidecar" + +REM 預設配置 +set "DEFAULT_PORT=8000" +set "DEFAULT_HOST=0.0.0.0" + +REM 解析參數 +set "COMMAND=start" +set "PORT=%DEFAULT_PORT%" +set "HOST=%DEFAULT_HOST%" +set "NO_SIDECAR=false" + +:parse_args +if "%~1"=="" goto :main +if /i "%~1"=="setup" (set "COMMAND=setup" & shift & goto :parse_args) +if /i "%~1"=="start" (set "COMMAND=start" & shift & goto :parse_args) +if /i "%~1"=="stop" (set "COMMAND=stop" & shift & goto :parse_args) +if /i "%~1"=="help" (set "COMMAND=help" & shift & goto :parse_args) +if /i "%~1"=="--port" (set "PORT=%~2" & shift & shift & goto :parse_args) +if /i "%~1"=="--host" (set "HOST=%~2" & shift & shift & goto :parse_args) +if /i "%~1"=="--no-sidecar" (set "NO_SIDECAR=true" & shift & goto :parse_args) +echo %RED%[ERROR]%NC% 未知參數: %~1 +goto :show_help + +:main +if "%COMMAND%"=="help" goto :show_help +if "%COMMAND%"=="setup" goto :do_setup +if "%COMMAND%"=="start" goto :do_start +if "%COMMAND%"=="stop" goto :do_stop +goto :show_help + +:show_banner +echo. +echo %CYAN%========================================== +echo Meeting Assistant Backend Setup +echo Windows 一鍵設置與啟動腳本 +echo ==========================================%NC% +echo. +goto :eof + +:check_python +echo %BLUE%[STEP]%NC% 檢查 Python 環境... + +REM 嘗試找到 Python +where python >nul 2>&1 +if %errorlevel% equ 0 ( + for /f "tokens=*" %%i in ('python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"') do set "PY_VERSION=%%i" + for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.major)"') do set "PY_MAJOR=%%i" + for /f "tokens=*" %%i in ('python -c "import sys; print(sys.version_info.minor)"') do set "PY_MINOR=%%i" + + if !PY_MAJOR! geq 3 if !PY_MINOR! geq 10 ( + set "PYTHON_CMD=python" + echo %GREEN%[OK]%NC% Python !PY_VERSION! + goto :eof + ) +) + +echo %RED%[ERROR]%NC% 需要 Python 3.10 或更高版本 +echo %BLUE%[INFO]%NC% 請安裝 Python: https://www.python.org/downloads/ +exit /b 1 + +:setup_backend_venv +echo %BLUE%[STEP]%NC% 設置後端虛擬環境... + +cd /d "%BACKEND_DIR%" + +if not exist "venv" ( + echo %BLUE%[INFO]%NC% 創建虛擬環境... + %PYTHON_CMD% -m venv venv + echo %GREEN%[OK]%NC% 虛擬環境已創建 +) else ( + echo %BLUE%[INFO]%NC% 虛擬環境已存在 +) + +echo %BLUE%[INFO]%NC% 安裝後端依賴... +call venv\Scripts\activate.bat +python -m pip install --upgrade pip -q +python -m pip install -r requirements.txt -q +echo %GREEN%[OK]%NC% 後端依賴安裝完成 +goto :eof + +:setup_sidecar_venv +echo %BLUE%[STEP]%NC% 設置 Sidecar 虛擬環境... + +cd /d "%SIDECAR_DIR%" + +if not exist "venv" ( + echo %BLUE%[INFO]%NC% 創建 Sidecar 虛擬環境... + %PYTHON_CMD% -m venv venv + echo %GREEN%[OK]%NC% Sidecar 虛擬環境已創建 +) else ( + echo %BLUE%[INFO]%NC% Sidecar 虛擬環境已存在 +) + +echo %BLUE%[INFO]%NC% 安裝 Sidecar 依賴 (這可能需要幾分鐘)... +call venv\Scripts\activate.bat +python -m pip install --upgrade pip -q +python -m pip install -r requirements.txt -q +echo %GREEN%[OK]%NC% Sidecar 依賴安裝完成 +goto :eof + +:setup_env_file +echo %BLUE%[STEP]%NC% 檢查環境變數配置... + +cd /d "%BACKEND_DIR%" + +if not exist ".env" ( + if exist ".env.example" ( + copy .env.example .env >nul + echo %YELLOW%[WARN]%NC% 已從 .env.example 創建 .env 檔案 + echo %YELLOW%[WARN]%NC% 請編輯 %BACKEND_DIR%\.env 設置資料庫和 API 密鑰 + ) else ( + echo %RED%[ERROR]%NC% 找不到 .env.example 檔案 + exit /b 1 + ) +) else ( + echo %GREEN%[OK]%NC% 環境變數檔案已存在 +) +goto :eof + +:start_backend +echo %BLUE%[STEP]%NC% 啟動後端服務... + +cd /d "%BACKEND_DIR%" + +REM 載入環境變數 +if exist ".env" ( + for /f "usebackq tokens=1,* delims==" %%a in (".env") do ( + set "%%a=%%b" + ) +) + +REM 使用 .env 中的配置或預設值 +if defined BACKEND_HOST set "HOST=%BACKEND_HOST%" +if defined BACKEND_PORT set "PORT=%BACKEND_PORT%" + +REM 啟動虛擬環境 +call venv\Scripts\activate.bat + +echo. +echo %GREEN%[OK]%NC% 後端服務準備就緒! +echo. +echo %CYAN%========================================== +echo 服務資訊 +echo ==========================================%NC% +echo. +echo API 地址: http://localhost:%PORT% +echo API 文件: http://localhost:%PORT%/docs +echo 健康檢查: http://localhost:%PORT%/api/health +echo. +echo 按 Ctrl+C 停止服務 +echo. + +uvicorn app.main:app --host %HOST% --port %PORT% --reload +goto :eof + +:do_setup +call :show_banner +call :check_python +if errorlevel 1 exit /b 1 +call :setup_backend_venv +if "%NO_SIDECAR%"=="false" call :setup_sidecar_venv +call :setup_env_file +echo. +echo %GREEN%[OK]%NC% 環境設置完成! +echo. +echo %BLUE%[INFO]%NC% 啟動服務: %~nx0 start +goto :eof + +:do_start +call :show_banner +call :check_python +if errorlevel 1 exit /b 1 +call :setup_backend_venv +call :setup_env_file +call :start_backend +goto :eof + +:do_stop +echo %BLUE%[STEP]%NC% 停止後端服務... + +REM 查找並終止 uvicorn 程序 +for /f "tokens=2" %%i in ('tasklist /fi "imagename eq python.exe" /fo list ^| findstr "PID:"') do ( + wmic process where "processid=%%i" get commandline 2>nul | findstr /i "uvicorn" >nul + if not errorlevel 1 ( + taskkill /pid %%i /f >nul 2>&1 + echo %GREEN%[OK]%NC% 已停止 PID: %%i + ) +) + +echo %GREEN%[OK]%NC% 後端服務已停止 +goto :eof + +:show_help +echo. +echo Meeting Assistant Backend - Windows 一鍵設置與啟動腳本 +echo. +echo 用法: %~nx0 [命令] [選項] +echo. +echo 命令: +echo setup 僅設置環境 (安裝依賴) +echo start 設置並啟動後端服務 (預設) +echo stop 停止後端服務 +echo help 顯示此幫助訊息 +echo. +echo 選項: +echo --port PORT 服務端口 (預設: %DEFAULT_PORT%) +echo --host HOST 綁定地址 (預設: %DEFAULT_HOST%) +echo --no-sidecar 不安裝 Sidecar 依賴 +echo. +echo 範例: +echo %~nx0 start 設置並啟動服務 +echo %~nx0 start --port 8080 使用自訂端口 +echo %~nx0 setup 僅安裝依賴 +echo. +goto :eof + +:end +endlocal