-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.ps1
57 lines (48 loc) · 2.18 KB
/
run.ps1
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
$airInstalled = Get-Command air -ErrorAction SilentlyContinue
if ($null -eq $airInstalled) {
Write-Host "air is not installed. Installing..."
go install github.com/cosmtrek/air@latest
$env:Path += ";$(go env GOPATH)\bin"
Ensure-GoBinPathInPath
}
$goxInstalled = Get-Command gox -ErrorAction SilentlyContinue
if ($null -eq $goxInstalled) {
Write-Host "gox is not installed. Installing..."
go install github.com/8byt/gox@latest
Ensure-GoBinPathInPath
}
function Ensure-GoBinPathInPath {
$goBinPath = "$(go env GOPATH)\bin"
$currentPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Process)
if ($currentPath -notcontains $goBinPath) {
Write-Host "Adding Go bin path to PATH..."
$newPath = $currentPath + ";" + $goBinPath
[System.Environment]::SetEnvironmentVariable("Path", $newPath, [System.EnvironmentVariableTarget]::Process)
Write-Host "Go bin path added to PATH."
} else {
Write-Host "Go bin path is already in PATH."
}
}
# Delete .go files in frontend/common and frontend/components recursively
$pathsToDeleteFrom = @("frontend/common", "frontend/components")
foreach ($path in $pathsToDeleteFrom) {
Get-ChildItem -Path $path -Recurse -Filter *.go | Remove-Item -Force
Write-Host "Deleted .go files from $path"
}
$frontendAirCommand = "air -c util/air-frontend-win.toml"
$frontendProcess = Start-Process -FilePath "powershell" -ArgumentList "-Command", $frontendAirCommand -PassThru -NoNewWindow
$frontendPID = $frontendProcess.Id
Write-Host "Frontend air running with PID: $frontendPID"
Register-ObjectEvent -InputObject $frontendProcess -EventName Exited -Action {
Stop-Process -Id $backendPID -Force
Write-Host "Frontend air process exited. Backend air process terminated."
}
$backendAirCommand = "air -c util/air-backend-win.toml"
$backendProcess = Start-Process -FilePath "powershell" -ArgumentList "-Command", $backendAirCommand -PassThru -NoNewWindow
$backendPID = $backendProcess.Id
Write-Host "Backend air running with PID: $backendPID"
Register-ObjectEvent -InputObject $backendProcess -EventName Exited -Action {
Stop-Process -Id $frontendPID -Force
Write-Host "Backend air process exited. Frontend air process terminated."
}
Wait-Event