# 发布所有子包到私有 npm 仓库 # 使用方法: powershell scripts/publish.ps1 # 注意: 发布仓库地址使用各子包 package.json 中的 publishConfig.registry 配置 # 版本管理请先通过 pnpm release (standard-version) 完成,本脚本仅负责构建和发布 $ErrorActionPreference = "Stop" Write-Host "🚀 开始发布流程" -ForegroundColor Green Write-Host "" # 子包列表 $PACKAGES = @( "packages/common", "packages/vue3", "packages/uni-app", "packages/vue2" ) # 1. 检查工作区是否干净 Write-Host "🔍 检查 Git 工作区状态..." -ForegroundColor Cyan $gitStatus = git status -s if ($gitStatus) { Write-Host "⚠️ 工作区有未提交的更改,请先提交或暂存" -ForegroundColor Yellow git status -s $continue = Read-Host "是否继续? (y/N)" if ($continue -ne "y" -and $continue -ne "Y") { exit 1 } } Write-Host "" # 2. 运行测试 Write-Host "🧪 运行测试..." -ForegroundColor Cyan pnpm test if ($LASTEXITCODE -ne 0) { Write-Host "❌ 测试失败,停止发布" -ForegroundColor Red exit 1 } Write-Host "" # 3. 构建所有包 Write-Host "📦 构建所有包..." -ForegroundColor Cyan pnpm build if ($LASTEXITCODE -ne 0) { Write-Host "❌ 构建失败,停止发布" -ForegroundColor Red exit 1 } Write-Host "" # 获取当前版本号 $CURRENT_VERSION = node -p "require('./package.json').version" Write-Host " 当前版本: v$CURRENT_VERSION" -ForegroundColor Gray Write-Host "" # 4. 发布每个包 Write-Host "📤 开始发布包到 npm..." -ForegroundColor Cyan foreach ($package in $PACKAGES) { if (Test-Path $package) { Push-Location $package $PACKAGE_NAME = node -p "require('./package.json').name" $PACKAGE_VERSION = node -p "require('./package.json').version" Write-Host "📤 发布 $PACKAGE_NAME@$PACKAGE_VERSION ..." -ForegroundColor Cyan pnpm publish --no-git-checks if ($LASTEXITCODE -ne 0) { Pop-Location Write-Host "❌ $package 发布失败,停止后续发布" -ForegroundColor Red exit 1 } Pop-Location Write-Host "✅ $PACKAGE_NAME@$PACKAGE_VERSION 发布成功" -ForegroundColor Green Write-Host "" } else { Write-Host "⚠️ 跳过不存在的包: $package" -ForegroundColor Yellow } } # 5. 推送到远程仓库 Write-Host "🔼 推送到远程仓库..." -ForegroundColor Cyan $push = Read-Host "是否推送到远程仓库? (y/N)" if ($push -eq "y" -or $push -eq "Y") { git push origin master git push origin --tags Write-Host "✅ 已推送到远程仓库" -ForegroundColor Green } else { Write-Host "⚠️ 跳过推送,请手动执行:" -ForegroundColor Yellow Write-Host " git push origin master" -ForegroundColor Gray Write-Host " git push origin --tags" -ForegroundColor Gray } Write-Host "" Write-Host "🎉 所有包发布完成!版本: v$CURRENT_VERSION" -ForegroundColor Green