fix: Improve Windows build scripts to properly execute electron-builder

- 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 <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-16 20:40:52 +08:00
parent 7d4fc69071
commit c19b4e8292
3 changed files with 605 additions and 567 deletions

View File

@@ -217,10 +217,20 @@ function Build-Electron {
exit 1
}
# 安裝依賴
if (-not (Test-Path "node_modules")) {
# 總是執行 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
}
}

View File

@@ -1,4 +1,5 @@
@echo off
chcp 65001 >nul
REM Meeting Assistant Client - Windows 打包腳本
REM 將 Electron 應用與 Python Sidecar 打包成免安裝 exe
@@ -99,6 +100,7 @@ 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% 建置目錄已清理
@@ -116,11 +118,11 @@ if not exist "venv" (
echo %BLUE%[INFO]%NC% 安裝 Sidecar 依賴...
call venv\Scripts\activate.bat
pip install --upgrade pip -q
pip install -r requirements.txt -q
python -m pip install --upgrade pip -q
python -m pip install -r requirements.txt -q
echo %BLUE%[INFO]%NC% 安裝 PyInstaller...
pip install pyinstaller -q
python -m pip install pyinstaller -q
echo %GREEN%[OK]%NC% Sidecar 建置環境就緒
goto :eof
@@ -173,11 +175,19 @@ echo %BLUE%[STEP]%NC% 設置前端建置環境...
cd /d "%CLIENT_DIR%"
if not exist "node_modules" (
REM 總是執行 npm install 確保依賴完整
echo %BLUE%[INFO]%NC% 安裝前端依賴...
call npm install
) else (
echo %BLUE%[INFO]%NC% 前端依賴已安裝
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" (
@@ -198,13 +208,23 @@ cd /d "%CLIENT_DIR%"
echo %BLUE%[INFO]%NC% 目標平台: Windows (Portable)
echo %BLUE%[INFO]%NC% 執行 electron-builder...
call npm run build -- --win
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 打包失敗
echo %RED%[ERROR]%NC% Electron 打包失敗 - dist 目錄不存在
exit /b 1
)
goto :eof

View File

@@ -1,4 +1,5 @@
@echo off
chcp 65001 >nul
REM Meeting Assistant Backend - Windows 一鍵設置與啟動腳本
REM 自動安裝依賴、設置環境並啟動後端服務
@@ -92,8 +93,8 @@ if not exist "venv" (
echo %BLUE%[INFO]%NC% 安裝後端依賴...
call venv\Scripts\activate.bat
pip install --upgrade pip -q
pip install -r requirements.txt -q
python -m pip install --upgrade pip -q
python -m pip install -r requirements.txt -q
echo %GREEN%[OK]%NC% 後端依賴安裝完成
goto :eof
@@ -112,8 +113,8 @@ if not exist "venv" (
echo %BLUE%[INFO]%NC% 安裝 Sidecar 依賴 (這可能需要幾分鐘)...
call venv\Scripts\activate.bat
pip install --upgrade pip -q
pip install -r requirements.txt -q
python -m pip install --upgrade pip -q
python -m pip install -r requirements.txt -q
echo %GREEN%[OK]%NC% Sidecar 依賴安裝完成
goto :eof