Files
aiot-platform-ui/scripts/deploy/build-and-push.ps1

77 lines
2.7 KiB
PowerShell
Raw Normal View History

# 本地构建并推送到仓库的 PowerShell 脚本
# 使用方法: .\scripts\deploy\build-and-push.ps1
$ErrorActionPreference = "Stop"
Write-Host "🚀 Starting local build and push process..." -ForegroundColor Cyan
# 1. 检查是否在项目根目录
if (-not (Test-Path "package.json")) {
Write-Host "❌ Error: Please run this script from project root" -ForegroundColor Red
exit 1
}
# 2. 清理旧的构建产物
Write-Host "📦 Cleaning old build artifacts..." -ForegroundColor Yellow
if (Test-Path "apps\web-antd\dist") {
Remove-Item -Recurse -Force "apps\web-antd\dist"
}
# 3. 安装依赖(如果需要)
if (-not (Test-Path "node_modules")) {
Write-Host "📥 Installing dependencies..." -ForegroundColor Yellow
pnpm install
}
# 4. 构建项目
Write-Host "🔨 Building project..." -ForegroundColor Yellow
pnpm build:antd
# 5. 检查构建结果
2025-12-23 13:53:31 +08:00
$distPath = "apps\web-antd\dist"
if (-not (Test-Path $distPath)) {
Write-Host "❌ Error: Build failed, dist directory not found" -ForegroundColor Red
exit 1
}
$distItems = Get-ChildItem $distPath -ErrorAction SilentlyContinue
if ($null -eq $distItems -or $distItems.Count -eq 0) {
Write-Host "❌ Error: Build failed, dist directory is empty" -ForegroundColor Red
exit 1
}
Write-Host "✅ Build successful!" -ForegroundColor Green
# 6. 显示构建产物大小
$buildSize = (Get-ChildItem "apps\web-antd\dist" -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
Write-Host "📊 Build size: $([math]::Round($buildSize, 2)) MB" -ForegroundColor Cyan
# 7. 提交并推送(可选)
$response = Read-Host "Do you want to commit and push to repository? (y/n)"
if ($response -eq "y" -or $response -eq "Y") {
# 检查是否有未提交的更改
$gitStatus = git status --porcelain
if ($gitStatus) {
Write-Host "📝 Staging build artifacts..." -ForegroundColor Yellow
2025-12-23 13:53:31 +08:00
# 使用 -f 强制添加被 .gitignore 忽略的 dist 目录
git add -f apps/web-antd/dist
git add -A # 添加其他更改
Write-Host "💾 Committing changes..." -ForegroundColor Yellow
git commit -m "chore: build and deploy web-antd [skip ci]" 2>&1 | Out-Null
Write-Host "📤 Pushing to repository..." -ForegroundColor Yellow
git push origin master
Write-Host "✅ Build artifacts pushed successfully!" -ForegroundColor Green
Write-Host "⏳ Waiting for CI/CD to deploy..." -ForegroundColor Cyan
} else {
Write-Host " No changes to commit" -ForegroundColor Yellow
}
} else {
Write-Host " Skipping git push. You can manually commit and push later." -ForegroundColor Yellow
}
Write-Host "✨ Done!" -ForegroundColor Green