2025-12-23 13:56:38 +08:00
|
|
|
|
# Local build and push script
|
|
|
|
|
|
# Usage: .\scripts\deploy\build-and-push.ps1
|
2025-12-23 13:46:15 +08:00
|
|
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Starting local build and push process..." -ForegroundColor Cyan
|
2025-12-23 13:46:15 +08:00
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path "package.json")) {
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Error: Please run this script from project root" -ForegroundColor Red
|
2025-12-23 13:46:15 +08:00
|
|
|
|
exit 1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Cleaning old build artifacts..." -ForegroundColor Yellow
|
|
|
|
|
|
$distPath = "apps\web-antd\dist"
|
|
|
|
|
|
if (Test-Path $distPath) {
|
|
|
|
|
|
Remove-Item -Recurse -Force $distPath
|
2025-12-23 13:46:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path "node_modules")) {
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Installing dependencies..." -ForegroundColor Yellow
|
2025-12-23 13:46:15 +08:00
|
|
|
|
pnpm install
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Building project..." -ForegroundColor Yellow
|
2025-12-23 14:05:04 +08:00
|
|
|
|
# 确保使用生产环境模式构建,避免使用开发环境配置
|
|
|
|
|
|
$env:NODE_ENV = "production"
|
2025-12-23 13:46:15 +08:00
|
|
|
|
pnpm build:antd
|
|
|
|
|
|
|
2025-12-23 13:53:31 +08:00
|
|
|
|
if (-not (Test-Path $distPath)) {
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Error: Build failed, dist directory not found" -ForegroundColor Red
|
2025-12-23 13:53:31 +08:00
|
|
|
|
exit 1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$distItems = Get-ChildItem $distPath -ErrorAction SilentlyContinue
|
2025-12-23 13:56:38 +08:00
|
|
|
|
if ($null -eq $distItems) {
|
|
|
|
|
|
Write-Host "Error: Build failed, dist directory is empty" -ForegroundColor Red
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($distItems.Count -eq 0) {
|
|
|
|
|
|
Write-Host "Error: Build failed, dist directory is empty" -ForegroundColor Red
|
2025-12-23 13:46:15 +08:00
|
|
|
|
exit 1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Build successful!" -ForegroundColor Green
|
2025-12-23 13:46:15 +08:00
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
$buildSize = (Get-ChildItem $distPath -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
|
|
|
|
|
|
$buildSizeRounded = [math]::Round($buildSize, 2)
|
|
|
|
|
|
Write-Host "Build size: $buildSizeRounded MB" -ForegroundColor Cyan
|
2025-12-23 13:46:15 +08:00
|
|
|
|
|
|
|
|
|
|
$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) {
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Staging build artifacts..." -ForegroundColor Yellow
|
2025-12-23 13:53:31 +08:00
|
|
|
|
git add -f apps/web-antd/dist
|
2025-12-23 13:56:38 +08:00
|
|
|
|
git add -A
|
2025-12-23 13:46:15 +08:00
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Committing changes..." -ForegroundColor Yellow
|
2025-12-23 14:05:04 +08:00
|
|
|
|
# 使用 --no-verify 跳过 pre-commit hooks,避免检查大量构建产物文件
|
2025-12-23 14:09:26 +08:00
|
|
|
|
# 注意:不要使用 [skip ci],否则 CI/CD 不会触发
|
|
|
|
|
|
git commit --no-verify -m "chore: build and deploy web-antd" 2>&1 | Out-Null
|
2025-12-23 13:46:15 +08:00
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Pushing to repository..." -ForegroundColor Yellow
|
2025-12-23 13:46:15 +08:00
|
|
|
|
git push origin master
|
|
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Build artifacts pushed successfully!" -ForegroundColor Green
|
|
|
|
|
|
Write-Host "Waiting for CI/CD to deploy..." -ForegroundColor Cyan
|
2025-12-23 13:46:15 +08:00
|
|
|
|
} else {
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "No changes to commit" -ForegroundColor Yellow
|
2025-12-23 13:46:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Skipping git push. You can manually commit and push later." -ForegroundColor Yellow
|
2025-12-23 13:46:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 13:56:38 +08:00
|
|
|
|
Write-Host "Done!" -ForegroundColor Green
|
2025-12-23 13:46:15 +08:00
|
|
|
|
|