-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRUN-DEMO.ps1
More file actions
199 lines (170 loc) Β· 6.73 KB
/
RUN-DEMO.ps1
File metadata and controls
199 lines (170 loc) Β· 6.73 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# HR Management System - Complete Demo Runner
Write-Host "π HR Management System - Complete Setup" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Gray
Write-Host ""
# Step 1: Setup Java if needed
Write-Host "π Step 1: Checking Java..." -ForegroundColor Cyan
try {
java -version 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host "β
Java found in system PATH" -ForegroundColor Green
} else {
throw "Java not found"
}
} catch {
Write-Host "β οΈ Java not found, setting up portable JDK..." -ForegroundColor Yellow
$jdkDir = "jdk-17"
if (-not (Test-Path $jdkDir)) {
Write-Host "π₯ Downloading Microsoft OpenJDK 17..." -ForegroundColor Blue
# Use a reliable, fast download
$url = "https://aka.ms/download-jdk/microsoft-jdk-17.0.8-windows-x64.zip"
$zip = "jdk17.zip"
try {
Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing
Write-Host "π¦ Extracting..." -ForegroundColor Blue
Expand-Archive -Path $zip -DestinationPath "temp" -Force
$folder = Get-ChildItem "temp" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
Move-Item $folder.FullName $jdkDir
Remove-Item $zip -Force
Remove-Item "temp" -Recurse -Force
Write-Host "β
JDK installed successfully" -ForegroundColor Green
} catch {
Write-Host "β Failed to setup Java. Please install manually:" -ForegroundColor Red
Write-Host " https://adoptium.net/temurin/releases/?version=17" -ForegroundColor Yellow
exit 1
}
}
# Set JAVA_HOME for this session
$javaHome = (Resolve-Path $jdkDir).Path
$env:JAVA_HOME = $javaHome
$env:PATH = "$javaHome\bin;$env:PATH"
Write-Host "β
Using portable JDK at $javaHome" -ForegroundColor Green
}
Write-Host ""
# Step 2: Kill existing processes
Write-Host "π Step 2: Cleaning up..." -ForegroundColor Cyan
Get-Process | Where-Object {$_.ProcessName -match "java|node"} | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Host "β
Cleaned up existing processes" -ForegroundColor Green
Write-Host ""
# Step 3: Start Backend
Write-Host "π Step 3: Starting Spring Boot backend..." -ForegroundColor Cyan
$backendJob = Start-Job -ScriptBlock {
param($workDir, $javaHome)
Set-Location $workDir
cd server
if ($javaHome) {
$env:JAVA_HOME = $javaHome
$env:PATH = "$javaHome\bin;$env:PATH"
}
Write-Output "Starting Maven..."
.\mvnw.cmd spring-boot:run
} -ArgumentList $PWD, $env:JAVA_HOME
Write-Host "β³ Waiting for backend to start..." -ForegroundColor Yellow
# Wait for backend with timeout
$timeout = 90
$count = 0
do {
Start-Sleep -Seconds 2
$count += 2
try {
$response = Invoke-WebRequest -Uri "http://localhost:8080/api/departments" -TimeoutSec 3 -UseBasicParsing
if ($response.StatusCode -eq 200) {
Write-Host "β
Backend is ready!" -ForegroundColor Green
break
}
} catch {
Write-Host "." -NoNewline -ForegroundColor Gray
}
if ($count -ge $timeout) {
Write-Host ""
Write-Host "β οΈ Backend taking longer than expected..." -ForegroundColor Yellow
Write-Host " Continuing with frontend setup..." -ForegroundColor Yellow
break
}
} while ($true)
Write-Host ""
# Step 4: Start Frontend
Write-Host "π Step 4: Starting Angular frontend..." -ForegroundColor Cyan
# Ensure node_modules are installed
cd client
if (-not (Test-Path "node_modules")) {
Write-Host "π¦ Installing npm dependencies..." -ForegroundColor Blue
npm ci
}
Write-Host "π¨ Starting Angular dev server..." -ForegroundColor Blue
$frontendJob = Start-Job -ScriptBlock {
param($workDir)
Set-Location $workDir
cd client
npx ng serve --proxy-config proxy.conf.json --port 4200
} -ArgumentList $PWD
# Wait for frontend
Write-Host "β³ Waiting for frontend to start..." -ForegroundColor Yellow
$timeout = 60
$count = 0
do {
Start-Sleep -Seconds 2
$count += 2
try {
$response = Invoke-WebRequest -Uri "http://localhost:4200" -TimeoutSec 3 -UseBasicParsing
if ($response.StatusCode -eq 200) {
Write-Host "β
Frontend is ready!" -ForegroundColor Green
break
}
} catch {
Write-Host "." -NoNewline -ForegroundColor Gray
}
if ($count -ge $timeout) {
Write-Host ""
Write-Host "β οΈ Frontend taking longer than expected..." -ForegroundColor Yellow
break
}
} while ($true)
cd ..
Write-Host ""
# Step 5: Open browsers
Write-Host "π Step 5: Opening demo..." -ForegroundColor Cyan
Start-Process "http://localhost:4200"
Start-Sleep -Seconds 2
Start-Process "http://localhost:8080/api/departments"
Write-Host ""
Write-Host "π HR Management System is running!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Gray
Write-Host ""
Write-Host "π± Demo URLs:" -ForegroundColor Cyan
Write-Host " Main App: http://localhost:4200" -ForegroundColor White
Write-Host " API Test: http://localhost:8080/api/departments" -ForegroundColor White
Write-Host " PDF Report: http://localhost:8080/api/reports/employees-by-department.pdf" -ForegroundColor White
Write-Host " Static Page: http://localhost:8080/cards.html" -ForegroundColor White
Write-Host ""
Write-Host "π§ Demo Steps:" -ForegroundColor Cyan
Write-Host " 1. Search for 'dept01' in the main app" -ForegroundColor White
Write-Host " 2. Click 'View' on any employee" -ForegroundColor White
Write-Host " 3. Try editing employee details" -ForegroundColor White
Write-Host " 4. Download PDF report from navigation" -ForegroundColor White
Write-Host " 5. Visit Cards Showcase page" -ForegroundColor White
Write-Host ""
Write-Host "Press Ctrl+C to stop all servers" -ForegroundColor Yellow
# Keep script alive and monitor jobs
try {
while ($true) {
Start-Sleep -Seconds 5
# Check job status
if ($backendJob.State -eq "Failed") {
Write-Host "β Backend failed" -ForegroundColor Red
Receive-Job $backendJob
break
}
if ($frontendJob.State -eq "Failed") {
Write-Host "β Frontend failed" -ForegroundColor Red
Receive-Job $frontendJob
break
}
}
} finally {
Write-Host "π Stopping servers..." -ForegroundColor Red
Stop-Job $backendJob -ErrorAction SilentlyContinue
Stop-Job $frontendJob -ErrorAction SilentlyContinue
Remove-Job $backendJob -ErrorAction SilentlyContinue
Remove-Job $frontendJob -ErrorAction SilentlyContinue
}