-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
132 lines (103 loc) · 4.66 KB
/
deploy.ps1
File metadata and controls
132 lines (103 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Solar Expert - Production Deployment Script
# This script deploys all three applications (backend, frontend, admin-panel)
param(
[Parameter(Mandatory=$false)]
[ValidateSet("all", "backend", "frontend", "admin")]
[string]$Target = "all",
[Parameter(Mandatory=$false)]
[switch]$SkipBuild,
[Parameter(Mandatory=$false)]
[switch]$SkipTests
)
Write-Host "`n╔════════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ Solar Expert - Production Deployment ║" -ForegroundColor Cyan
Write-Host "╚════════════════════════════════════════════════════════════════════╝`n" -ForegroundColor Cyan
$ErrorActionPreference = "Stop"
# Function to check if a command exists
function Test-Command {
param($Command)
$null -ne (Get-Command $Command -ErrorAction SilentlyContinue)
}
# Check prerequisites
Write-Host "Checking prerequisites..." -ForegroundColor Yellow
if (-not (Test-Command "node")) {
Write-Host "❌ Node.js is not installed!" -ForegroundColor Red
exit 1
}
if (-not (Test-Command "npm")) {
Write-Host "❌ npm is not installed!" -ForegroundColor Red
exit 1
}
Write-Host "✅ Prerequisites check passed`n" -ForegroundColor Green
# Function to deploy backend
function Deploy-Backend {
Write-Host "`n📦 Deploying Backend..." -ForegroundColor Cyan
Set-Location backend
if (-not $SkipTests) {
Write-Host "Running backend tests..." -ForegroundColor Yellow
npm test
}
Write-Host "Installing production dependencies..." -ForegroundColor Yellow
npm ci --production
Write-Host "✅ Backend deployed successfully!" -ForegroundColor Green
Set-Location ..
}
# Function to deploy frontend
function Deploy-Frontend {
Write-Host "`n📦 Deploying User Frontend..." -ForegroundColor Cyan
Set-Location frontend
if (-not $SkipBuild) {
Write-Host "Building frontend for production..." -ForegroundColor Yellow
npm ci
npm run build
Write-Host "✅ Frontend built successfully!" -ForegroundColor Green
Write-Host "Build output: frontend/build/" -ForegroundColor Gray
}
Set-Location ..
}
# Function to deploy admin panel
function Deploy-AdminPanel {
Write-Host "`n📦 Deploying Admin Panel..." -ForegroundColor Cyan
Set-Location admin-panel
if (-not $SkipBuild) {
Write-Host "Building admin panel for production..." -ForegroundColor Yellow
npm ci
npm run build
Write-Host "✅ Admin Panel built successfully!" -ForegroundColor Green
Write-Host "Build output: admin-panel/build/" -ForegroundColor Gray
}
Set-Location ..
}
# Main deployment logic
try {
switch ($Target) {
"backend" {
Deploy-Backend
}
"frontend" {
Deploy-Frontend
}
"admin" {
Deploy-AdminPanel
}
"all" {
Deploy-Backend
Deploy-Frontend
Deploy-AdminPanel
}
}
Write-Host "`n╔════════════════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ Deployment Completed Successfully! ║" -ForegroundColor Green
Write-Host "╚════════════════════════════════════════════════════════════════════╝`n" -ForegroundColor Green
Write-Host "Next Steps:" -ForegroundColor Yellow
Write-Host "1. Configure your web server (nginx, Apache, IIS)" -ForegroundColor White
Write-Host "2. Set up environment variables for production" -ForegroundColor White
Write-Host "3. Configure SSL certificates" -ForegroundColor White
Write-Host "4. Point domains to the build directories" -ForegroundColor White
Write-Host " - User Panel: frontend/build/" -ForegroundColor Gray
Write-Host " - Admin Panel: admin-panel/build/" -ForegroundColor Gray
Write-Host "5. Start the backend server with PM2 or similar process manager`n" -ForegroundColor White
} catch {
Write-Host "`n❌ Deployment failed: $_" -ForegroundColor Red
exit 1
}