|
|
@@ -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
|