deploy.ps1 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # 智裁云前端部署脚本(PowerShell)
  2. # 使用方法: .\deploy.ps1 -Env production
  3. param(
  4. [Parameter(Mandatory=$false)]
  5. [ValidateSet("development", "production")]
  6. [string]$Env = "production"
  7. )
  8. Write-Host "开始构建智裁云前端项目..." -ForegroundColor Green
  9. # 检查pnpm是否安装
  10. if (!(Get-Command pnpm -ErrorAction SilentlyContinue)) {
  11. Write-Host "错误: pnpm未安装,请先运行 npm install -g pnpm" -ForegroundColor Red
  12. exit 1
  13. }
  14. # 安装依赖
  15. Write-Host "安装依赖..." -ForegroundColor Yellow
  16. pnpm install
  17. # 构建所有应用
  18. Write-Host "构建所有应用..." -ForegroundColor Yellow
  19. pnpm build:all
  20. # 检查构建产物
  21. $apps = @("platform-app", "factory-app", "worker-app")
  22. foreach ($app in $apps) {
  23. $distPath = "apps\$app\dist"
  24. if (Test-Path $distPath) {
  25. Write-Host "✓ $app 构建成功" -ForegroundColor Green
  26. } else {
  27. Write-Host "✗ $app 构建失败" -ForegroundColor Red
  28. exit 1
  29. }
  30. }
  31. # 创建部署目录
  32. $deployDir = "dist"
  33. if (Test-Path $deployDir) {
  34. Remove-Item $deployDir -Recurse -Force
  35. }
  36. New-Item -ItemType Directory -Path $deployDir -Force | Out-Null
  37. # 复制构建产物
  38. foreach ($app in $apps) {
  39. $srcPath = "apps\$app\dist"
  40. $destPath = "$deployDir\$app"
  41. Copy-Item -Path $srcPath -Destination $destPath -Recurse
  42. Write-Host "✓ 已复制 $app 到 $destPath" -ForegroundColor Green
  43. }
  44. # 复制Nginx配置
  45. Copy-Item -Path "deploy\nginx.conf" -Destination "$deployDir\nginx.conf"
  46. Write-Host "✓ 已复制Nginx配置" -ForegroundColor Green
  47. Write-Host ""
  48. Write-Host "==========================================" -ForegroundColor Cyan
  49. Write-Host "构建完成!" -ForegroundColor Green
  50. Write-Host "==========================================" -ForegroundColor Cyan
  51. Write-Host ""
  52. Write-Host "部署目录: $deployPath" -ForegroundColor Yellow
  53. Write-Host ""
  54. Write-Host "部署步骤:" -ForegroundColor Yellow
  55. Write-Host "1. 将 $deployDir 目录上传到服务器" -ForegroundColor White
  56. Write-Host "2. 复制 nginx.conf 到 /etc/nginx/conf.d/" -ForegroundColor White
  57. Write-Host "3. 重启Nginx: sudo nginx -s reload" -ForegroundColor White
  58. Write-Host ""
  59. Write-Host "应用访问地址:" -ForegroundColor Yellow
  60. Write-Host " 系统管理后台: https://smartcut.example.com/platform" -ForegroundColor White
  61. Write-Host " 工厂管理后台: https://smartcut.example.com/factory" -ForegroundColor White
  62. Write-Host " 工人端: https://smartcut.example.com/worker" -ForegroundColor White