33
44# Parameters for switches and options
55param (
6- [switch ]$SkipLLM ,
7- [switch ]$SkipTTS ,
6+ [switch ]$SkipWorkers ,
87 [switch ]$SkipFrontend ,
98 [switch ]$SkipElectron ,
10- [switch ]$Verbose
9+ [switch ]$Verbose ,
10+ [switch ]$ContinueOnError # Continue setup for remaining services even if one fails
1111)
1212
1313# Helper: Cleanup processes
@@ -38,7 +38,8 @@ function Invoke-ServiceSetup {
3838 # Check if setup.ps1 exists
3939 $setupScript = Join-Path $ServicePath " setup.ps1"
4040 if (-not (Test-Path $setupScript )) {
41- throw " setup.ps1 not found in $ServicePath "
41+ Write-ColorOutput " Warning: setup.ps1 not found in $ServicePath " " Yellow"
42+ return @ { Success = $false ; ErrorMessage = " setup.ps1 not found" ; ExitCode = -1 }
4243 }
4344
4445 try {
@@ -49,9 +50,8 @@ function Invoke-ServiceSetup {
4950
5051 # Add skip parameters for workers setup
5152 if ($ServiceName -eq " Workers" ) {
52- if ($SkipLLM ) { $scriptArgs += " -SkipLLM" }
53- if ($SkipTTS ) { $scriptArgs += " -SkipTTS" }
5453 if ($Verbose ) { $scriptArgs += " -Verbose" }
54+ if ($ContinueOnError ) { $scriptArgs += " -ContinueOnError" }
5555 }
5656
5757 if ($Verbose ) {
@@ -95,21 +95,23 @@ function Invoke-ServiceSetup {
9595 # Check the exit code
9696 if ($setupProcess.ExitCode -eq 0 ) {
9797 Write-ColorOutput " $ServiceName setup completed successfully!" " Green"
98+ return @ { Success = $true ; ErrorMessage = $null ; ExitCode = $setupProcess.ExitCode }
9899 } else {
100+ $errorMsg = " Setup failed with exit code $ ( $setupProcess.ExitCode ) "
99101 Write-ColorOutput " $ServiceName setup failed with exit code $ ( $setupProcess.ExitCode ) !" " Red"
100- throw " Setup failed for $ServiceName with exit code $ ( $ setupProcess.ExitCode ) "
102+ return @ { Success = $false ; ErrorMessage = $errorMsg ; ExitCode = $ setupProcess.ExitCode }
101103 }
102104
103- return $setupProcess
104105 } catch {
105- Write-ColorOutput " Setup failed for $ServiceName `: $ ( $_.Exception.Message ) " " Red"
106- throw
106+ $errorMsg = $_.Exception.Message
107+ Write-ColorOutput " Setup failed for $ServiceName `: $errorMsg " " Red"
108+ return @ { Success = $false ; ErrorMessage = $errorMsg ; ExitCode = -1 }
107109 }
108110}
109111
110112# Define service configuration
111113$services = @ (
112- @ {Name = " Workers" ; Path = " workers" ; Skip = $false },
114+ @ {Name = " Workers" ; Path = " workers" ; Skip = $SkipWorkers },
113115 @ {Name = " Frontend" ; Path = " frontend" ; Skip = $SkipFrontend },
114116 @ {Name = " Electron" ; Path = " electron" ; Skip = $SkipElectron }
115117)
@@ -121,6 +123,11 @@ foreach ($service in $services) {
121123}
122124Write-ColorOutput " ==========================================" " Cyan"
123125
126+ # Track setup results
127+ $setupResults = @ ()
128+ $successfulSetups = @ ()
129+ $failedSetups = @ ()
130+
124131try {
125132 # Install Node.js first using shared setup_thirdparty.ps1 function
126133 $thirdPartyScript = Join-Path $PSScriptRoot ' scripts\setup_thirdparty.ps1'
@@ -132,24 +139,119 @@ try {
132139 $setupPath = Join-Path $PWD " $ ( $service.Path ) \setup.ps1"
133140 if (Test-Path $setupPath ) {
134141 Write-ColorOutput " Starting $ ( $service.Name ) setup..." " Yellow"
135- try {
136- $setupProcess = Invoke-ServiceSetup - ServicePath (Join-Path $PWD $service.Path ) - ServiceName $service.Name
137- } catch {
138- Write-ColorOutput " $ ( $service.Name ) setup failed: $ ( $_.Exception.Message ) " " Red"
139- throw
142+
143+ $result = Invoke-ServiceSetup - ServicePath (Join-Path $PWD $service.Path ) - ServiceName $service.Name
144+ $setupResults += @ {
145+ ServiceName = $service.Name
146+ Success = $result.Success
147+ ErrorMessage = $result.ErrorMessage
148+ ExitCode = $result.ExitCode
149+ }
150+
151+ if ($result.Success ) {
152+ $successfulSetups += $service.Name
153+ } else {
154+ $failedSetups += @ {
155+ Name = $service.Name
156+ Error = $result.ErrorMessage
157+ ExitCode = $result.ExitCode
158+ }
159+
160+ if (-not $ContinueOnError ) {
161+ Write-ColorOutput " Setup failed for $ ( $service.Name ) . Use -ContinueOnError to continue with remaining services." " Red"
162+ throw " Setup failed for $ ( $service.Name ) : $ ( $result.ErrorMessage ) "
163+ } else {
164+ Write-ColorOutput " Setup failed for $ ( $service.Name ) , but continuing with remaining services..." " Yellow"
165+ }
140166 }
141167 } else {
142168 Write-ColorOutput " Warning: $ ( $service.Name ) setup.ps1 not found!" " Yellow"
169+ $setupResults += @ {
170+ ServiceName = $service.Name
171+ Success = $false
172+ ErrorMessage = " setup.ps1 not found"
173+ ExitCode = -1
174+ }
175+ $failedSetups += @ {
176+ Name = $service.Name
177+ Error = " setup.ps1 not found"
178+ ExitCode = -1
179+ }
180+
181+ if (-not $ContinueOnError ) {
182+ throw " Setup script not found for $ ( $service.Name ) "
183+ } else {
184+ Write-ColorOutput " Setup script not found for $ ( $service.Name ) , but continuing with remaining services..." " Yellow"
185+ }
186+ }
187+ } else {
188+ Write-ColorOutput " Skipping $ ( $service.Name ) setup..." " Yellow"
189+ $setupResults += @ {
190+ ServiceName = $service.Name
191+ Success = $null # Indicates skipped
192+ ErrorMessage = " Skipped by user"
193+ ExitCode = 0
143194 }
144195 }
145196 }
146197
147- Write-ColorOutput " All setup processes completed successfully!" " Green"
198+ # Display summary
199+ Write-ColorOutput " `n === Setup Summary ===" " Cyan"
200+
201+ if ($successfulSetups.Count -gt 0 ) {
202+ Write-ColorOutput " ✅ Successful setups ($ ( $successfulSetups.Count ) ):" " Green"
203+ foreach ($success in $successfulSetups ) {
204+ Write-ColorOutput " - $success " " Green"
205+ }
206+ }
207+
208+ if ($failedSetups.Count -gt 0 ) {
209+ Write-ColorOutput " ❌ Failed setups ($ ( $failedSetups.Count ) ):" " Red"
210+ foreach ($failure in $failedSetups ) {
211+ Write-ColorOutput " - $ ( $failure.Name ) : $ ( $failure.Error ) (Exit Code: $ ( $failure.ExitCode ) )" " Red"
212+ }
213+ }
214+
215+ $skippedCount = ($setupResults | Where-Object { $_.Success -eq $null }).Count
216+ if ($skippedCount -gt 0 ) {
217+ Write-ColorOutput " ⏭️ Skipped setups ($skippedCount ):" " Yellow"
218+ foreach ($result in ($setupResults | Where-Object { $_.Success -eq $null })) {
219+ Write-ColorOutput " - $ ( $result.ServiceName ) " " Yellow"
220+ }
221+ }
222+
223+ Write-ColorOutput " ===================" " Cyan"
224+
225+ # Final status
226+ if ($failedSetups.Count -eq 0 ) {
227+ Write-ColorOutput " All setup processes completed successfully!" " Green"
228+ } else {
229+ Write-ColorOutput " Some setup processes failed. Check the summary above for details." " Red"
230+ exit 1
231+ }
232+
148233} catch {
149234 Write-ColorOutput " Error occurred: $ ( $_.Exception.Message ) " " Red"
150235 if ($Verbose ) {
151236 Write-ColorOutput " Stack trace: $ ( $_.ScriptStackTrace ) " " Red"
152237 }
238+
239+ # Display partial summary if any setups were completed
240+ if ($setupResults.Count -gt 0 ) {
241+ Write-ColorOutput " `n === Partial Setup Summary ===" " Cyan"
242+ foreach ($result in $setupResults ) {
243+ if ($result.Success -eq $true ) {
244+ Write-ColorOutput " ✅ $ ( $result.ServiceName ) : Success" " Green"
245+ } elseif ($result.Success -eq $false ) {
246+ Write-ColorOutput " ❌ $ ( $result.ServiceName ) : $ ( $result.ErrorMessage ) " " Red"
247+ } else {
248+ Write-ColorOutput " ⏭️ $ ( $result.ServiceName ) : Skipped" " Yellow"
249+ }
250+ }
251+ Write-ColorOutput " ===================" " Cyan"
252+ }
253+
254+ exit 1
153255} finally {
154256 Cleanup
155257}
0 commit comments