Ver código fonte

构建windows平台版本

黄中银 3 semanas atrás
pai
commit
0eb332c06b
3 arquivos alterados com 338 adições e 11 exclusões
  1. 293 0
      ApqInstaller/build-win.ps1
  2. 1 1
      ApqInstaller/package.json
  3. 44 10
      ApqInstaller/scripts/README.md

+ 293 - 0
ApqInstaller/build-win.ps1

@@ -0,0 +1,293 @@
+<#
+.SYNOPSIS
+    Windows 平台构建脚本 (NSIS + Portable)
+    Build script for Windows platform (NSIS installer + Portable)
+
+.DESCRIPTION
+    构建 Claude AI Installer 的 Windows 版本,包含:
+    - NSIS 安装程序 (.exe)
+    - Portable 便携版 (.exe)
+
+.PARAMETER SkipBuild
+    跳过前端构建,仅执行打包
+
+.PARAMETER SkipTypeCheck
+    跳过 TypeScript 类型检查
+
+.PARAMETER Clean
+    构建前清理旧文件
+
+.PARAMETER Arch
+    目标架构: x64, arm64, all (默认: x64)
+
+.PARAMETER Help
+    显示帮助信息
+
+.EXAMPLE
+    .\build-win.ps1
+    # 完整构建 Windows x64 版本
+
+.EXAMPLE
+    .\build-win.ps1 -SkipBuild
+    # 跳过前端构建,仅打包
+
+.EXAMPLE
+    .\build-win.ps1 -Arch all
+    # 构建所有架构版本
+
+.EXAMPLE
+    .\build-win.ps1 -Clean
+    # 清理后重新构建
+#>
+
+param(
+    [switch]$SkipBuild,
+    [switch]$SkipTypeCheck,
+    [switch]$Clean,
+    [ValidateSet("x64", "arm64", "all")]
+    [string]$Arch = "x64",
+    [switch]$Help
+)
+
+# 设置错误处理
+$ErrorActionPreference = "Stop"
+
+# 颜色输出函数
+function Write-Info { Write-Host "i " -ForegroundColor Blue -NoNewline; Write-Host $args }
+function Write-Success { Write-Host "√ " -ForegroundColor Green -NoNewline; Write-Host $args }
+function Write-Warning { Write-Host "! " -ForegroundColor Yellow -NoNewline; Write-Host $args }
+function Write-Error { Write-Host "x " -ForegroundColor Red -NoNewline; Write-Host $args }
+function Write-Step { Write-Host "`n> " -ForegroundColor Cyan -NoNewline; Write-Host $args -ForegroundColor White }
+
+# 显示帮助信息
+function Show-Help {
+    Write-Host @"
+
+Claude AI Installer Windows 构建脚本
+
+用法:
+    .\build-win.ps1 [参数]
+
+参数:
+    -SkipBuild       跳过前端构建,仅执行打包
+    -SkipTypeCheck   跳过 TypeScript 类型检查
+    -Clean           构建前清理旧文件
+    -Arch <arch>     目标架构: x64, arm64, all (默认: x64)
+    -Help            显示此帮助信息
+
+示例:
+    .\build-win.ps1                    # 完整构建
+    .\build-win.ps1 -SkipBuild         # 仅打包
+    .\build-win.ps1 -Arch all          # 构建所有架构
+    .\build-win.ps1 -Clean             # 清理后构建
+
+输出:
+    release\Claude AI Installer-x.x.x-win-x64-nsis.exe      (NSIS 安装程序)
+    release\Claude AI Installer-x.x.x-win-x64-portable.exe  (便携版)
+
+"@
+}
+
+# 执行命令并检查结果
+function Invoke-BuildCommand {
+    param(
+        [string]$Command,
+        [string]$Description
+    )
+
+    Write-Info "执行: $Command"
+
+    try {
+        Invoke-Expression $Command
+        if ($LASTEXITCODE -ne 0) {
+            throw "$Description 失败 (退出码: $LASTEXITCODE)"
+        }
+    }
+    catch {
+        Write-Error "$Description 失败: $_"
+        exit 1
+    }
+}
+
+# 清理构建目录
+function Clear-BuildDirs {
+    Write-Step "清理旧的构建文件..."
+
+    $dirsToClean = @("dist", "dist-electron")
+
+    foreach ($dir in $dirsToClean) {
+        $fullPath = Join-Path $PSScriptRoot $dir
+        if (Test-Path $fullPath) {
+            Remove-Item -Path $fullPath -Recurse -Force
+            Write-Info "已删除: $dir"
+        }
+    }
+
+    Write-Success "清理完成"
+}
+
+# 检查 Node.js 环境
+function Test-NodeEnvironment {
+    Write-Step "检查构建环境..."
+
+    # 检查 Node.js
+    try {
+        $nodeVersion = node --version
+        Write-Info "Node.js 版本: $nodeVersion"
+    }
+    catch {
+        Write-Error "未找到 Node.js,请先安装 Node.js"
+        exit 1
+    }
+
+    # 检查 npm
+    try {
+        $npmVersion = npm --version
+        Write-Info "npm 版本: $npmVersion"
+    }
+    catch {
+        Write-Error "未找到 npm"
+        exit 1
+    }
+
+    # 检查 node_modules
+    $nodeModulesPath = Join-Path $PSScriptRoot "node_modules"
+    if (-not (Test-Path $nodeModulesPath)) {
+        Write-Warning "未找到 node_modules,正在安装依赖..."
+        Invoke-BuildCommand "npm install" "安装依赖"
+    }
+
+    Write-Success "环境检查通过"
+}
+
+# 类型检查
+function Invoke-TypeCheck {
+    Write-Step "执行 TypeScript 类型检查..."
+    Invoke-BuildCommand "npx vue-tsc --noEmit" "类型检查"
+    Write-Success "类型检查通过"
+}
+
+# 构建前端
+function Build-Frontend {
+    Write-Step "构建前端资源..."
+    Invoke-BuildCommand "npx vite build" "前端构建"
+    Write-Success "前端构建完成"
+}
+
+# 打包 Electron 应用
+function Build-ElectronApp {
+    param([string]$Architecture)
+
+    Write-Step "打包 Windows 应用 (架构: $Architecture)..."
+
+    $archArgs = switch ($Architecture) {
+        "x64"   { "--x64" }
+        "arm64" { "--arm64" }
+        "all"   { "--x64 --arm64" }
+    }
+
+    $command = "npx electron-builder --win $archArgs"
+    Invoke-BuildCommand $command "应用打包"
+    Write-Success "应用打包完成"
+}
+
+# 显示构建结果
+function Show-BuildResults {
+    Write-Step "构建结果:"
+
+    $releaseDir = Join-Path $PSScriptRoot "release"
+
+    if (-not (Test-Path $releaseDir)) {
+        Write-Warning "release 目录不存在"
+        return
+    }
+
+    $packages = Get-ChildItem -Path $releaseDir -File | Where-Object {
+        $_.Extension -in @(".exe", ".zip")
+    }
+
+    if ($packages.Count -eq 0) {
+        Write-Warning "未找到打包文件"
+        return
+    }
+
+    Write-Host ""
+    foreach ($pkg in $packages) {
+        $sizeMB = [math]::Round($pkg.Length / 1MB, 2)
+        Write-Host "  * " -ForegroundColor Green -NoNewline
+        Write-Host "$($pkg.Name) ($sizeMB MB)"
+    }
+    Write-Host ""
+    Write-Info "输出目录: $releaseDir"
+}
+
+# 主函数
+function Main {
+    if ($Help) {
+        Show-Help
+        exit 0
+    }
+
+    # 切换到脚本所在目录
+    Push-Location $PSScriptRoot
+
+    try {
+        Write-Host @"
+
++--------------------------------------------+
+|     Claude AI Installer Windows 构建       |
++--------------------------------------------+
+
+"@ -ForegroundColor Cyan
+
+        Write-Info "目标架构: $Arch"
+        Write-Info "跳过构建: $SkipBuild"
+        Write-Info "跳过类型检查: $SkipTypeCheck"
+
+        $startTime = Get-Date
+
+        # 检查环境
+        Test-NodeEnvironment
+
+        # 清理(如果指定)
+        if ($Clean) {
+            Clear-BuildDirs
+        }
+
+        # 构建流程
+        if (-not $SkipBuild) {
+            if ($Clean -or -not (Test-Path (Join-Path $PSScriptRoot "dist"))) {
+                Clear-BuildDirs
+            }
+
+            if (-not $SkipTypeCheck) {
+                Invoke-TypeCheck
+            }
+
+            Build-Frontend
+        }
+        else {
+            Write-Warning "跳过前端构建"
+        }
+
+        # 打包
+        Build-ElectronApp -Architecture $Arch
+
+        # 显示结果
+        Show-BuildResults
+
+        $duration = [math]::Round(((Get-Date) - $startTime).TotalSeconds, 1)
+        Write-Host ""
+        Write-Success "构建完成! 耗时: ${duration}s"
+    }
+    catch {
+        Write-Error "构建失败: $_"
+        exit 1
+    }
+    finally {
+        Pop-Location
+    }
+}
+
+# 运行主函数
+Main

+ 1 - 1
ApqInstaller/package.json

@@ -54,7 +54,7 @@
   "build": {
     "appId": "com.claude.ai.installer",
     "productName": "Claude AI Installer",
-    "artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
+    "artifactName": "${productName}-${version}-${os}-${arch}-${target}.${ext}",
     "directories": {
       "output": "release"
     },

+ 44 - 10
ApqInstaller/scripts/README.md

@@ -2,6 +2,35 @@
 
 本目录包含 Claude AI Installer 的构建和发布脚本。
 
+## 两种使用方式
+
+### 1. 只构建,不发布
+
+```bash
+npm run build:win      # 仅构建 Windows
+npm run build:mac      # 仅构建 macOS
+npm run build:linux    # 仅构建 Linux
+npm run build:all      # 构建所有平台
+```
+
+只生成安装包到 `release/` 目录,不修改版本号,不创建 Git tag。
+
+### 2. 发布(包含构建)
+
+```bash
+npm run release:patch  # 更新版本 → 构建 → 创建 tag
+npm run release:minor  # 次版本发布
+npm run release:major  # 主版本发布
+```
+
+完整流程:更新版本号 → 构建所有平台 → 生成发布说明 → 创建 Git tag。
+
+**简单来说:**
+- `build.js` = 单纯构建
+- `release.js` = 更新版本 + 构建 + 发布相关操作
+
+---
+
 ## 快速开始
 
 ```bash
@@ -60,7 +89,12 @@ node scripts/build.js -p win --skip-build
 
 ### release.js - 发布脚本
 
-自动化发布脚本,支持版本更新、构建、Git tag 创建。
+自动化发布脚本,按以下顺序执行:
+1. 更新版本号(可选)
+2. 构建所有平台安装包
+3. 生成发布说明
+4. 创建 Git tag(可选)
+5. 推送到远程(可选)
 
 #### 用法
 
@@ -140,25 +174,25 @@ node scripts/release.js patch --dry-run
 
 | 格式 | 文件名 | 说明 |
 |------|--------|------|
-| NSIS | `Claude AI Installer-x.x.x-win-x64.exe` | 安装程序 |
-| Portable | `Claude AI Installer-x.x.x-win-x64.exe` | 便携版 |
+| NSIS | `Claude AI Installer-x.x.x-win-x64-nsis.exe` | 安装程序 |
+| Portable | `Claude AI Installer-x.x.x-win-x64-portable.exe` | 便携版 |
 
 ### macOS
 
 | 格式 | 文件名 | 说明 |
 |------|--------|------|
-| DMG | `Claude AI Installer-x.x.x-mac-x64.dmg` | Intel 版 |
-| DMG | `Claude AI Installer-x.x.x-mac-arm64.dmg` | Apple Silicon 版 |
-| ZIP | `Claude AI Installer-x.x.x-mac-x64.zip` | Intel 压缩包 |
-| ZIP | `Claude AI Installer-x.x.x-mac-arm64.zip` | Apple Silicon 压缩包 |
+| DMG | `Claude AI Installer-x.x.x-mac-x64-dmg.dmg` | Intel 版 |
+| DMG | `Claude AI Installer-x.x.x-mac-arm64-dmg.dmg` | Apple Silicon 版 |
+| ZIP | `Claude AI Installer-x.x.x-mac-x64-zip.zip` | Intel 压缩包 |
+| ZIP | `Claude AI Installer-x.x.x-mac-arm64-zip.zip` | Apple Silicon 压缩包 |
 
 ### Linux
 
 | 格式 | 文件名 | 说明 |
 |------|--------|------|
-| AppImage | `Claude AI Installer-x.x.x-linux-x64.AppImage` | 通用格式 |
-| DEB | `Claude AI Installer-x.x.x-linux-x64.deb` | Debian/Ubuntu |
-| RPM | `Claude AI Installer-x.x.x-linux-x64.rpm` | Fedora/RHEL |
+| AppImage | `Claude AI Installer-x.x.x-linux-x64-AppImage.AppImage` | 通用格式 |
+| DEB | `Claude AI Installer-x.x.x-linux-x64-deb.deb` | Debian/Ubuntu |
+| RPM | `Claude AI Installer-x.x.x-linux-x64-rpm.rpm` | Fedora/RHEL |
 
 ---