-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapstox-dev.ps1
More file actions
73 lines (61 loc) · 1.95 KB
/
mapstox-dev.ps1
File metadata and controls
73 lines (61 loc) · 1.95 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
# run-dev.ps1
# Script to run both backend and frontend development servers simultaneously
$ErrorActionPreference = 'Stop'
$workspaceRoot = $PSScriptRoot
# Function to stop all child processes when the script exits
function Cleanup {
param(
[Parameter(Mandatory=$true)]
[System.Management.Automation.Job[]]$jobs
)
Write-Host "`nStopping services..." -ForegroundColor Yellow
$jobs | Stop-Job
$jobs | Remove-Job
Get-Job | Where-Object { $_.State -eq 'Running' } | Stop-Job
exit
}
Write-Host "Starting MapStox development environment..." -ForegroundColor Cyan
Write-Host "Press Ctrl+C to stop all services`n" -ForegroundColor Yellow
# Start the backend
$backendJob = Start-Job -Name "Backend" -ScriptBlock {
param($path)
Set-Location $path
go run main.go
} -ArgumentList $workspaceRoot
# Start the frontend
$frontendJob = Start-Job -Name "Frontend" -ScriptBlock {
param($path)
Set-Location $path
bun run dev
} -ArgumentList $workspaceRoot
$jobs = @($backendJob, $frontendJob)
# Set up cleanup on script exit
try {
# Register cleanup on Ctrl+C
[Console]::TreatControlCAsInput = $true
# Main loop to show output from both services
while ($true) {
# Check if any job has failed
$jobs | ForEach-Object {
$job = $_
if ($job.State -eq 'Failed') {
Write-Host "Service $($job.Name) failed! Error:" -ForegroundColor Red
Receive-Job -Job $job
Cleanup -jobs $jobs
}
# Show job output
Receive-Job -Job $job -ErrorAction SilentlyContinue
}
# Check for Ctrl+C
if ([Console]::KeyAvailable) {
$key = [Console]::ReadKey($true)
if ($key.Key -eq 'C' -and $key.Modifiers -eq 'Control') {
throw "Ctrl+C pressed"
}
}
Start-Sleep -Milliseconds 100
}
}
finally {
Cleanup -jobs $jobs
}