-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-dev.ps1
More file actions
98 lines (82 loc) · 2.91 KB
/
Copy pathrun-dev.ps1
File metadata and controls
98 lines (82 loc) · 2.91 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
param(
[switch]$InstallIfNeeded,
[switch]$Reload,
[int]$ApiPort = 8000,
[int]$FrontendPort = 3000
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $root
$venvPython = Join-Path $root ".venv\Scripts\python.exe"
$frontendNodeModules = Join-Path $root "frontend\node_modules"
$frontendRoot = Join-Path $root "frontend"
if ((-not (Test-Path $venvPython)) -or (-not (Test-Path $frontendNodeModules))) {
if ($InstallIfNeeded) {
& (Join-Path $root "setup.ps1")
} else {
throw "Dependencies are not installed yet. Run .\setup.cmd first, or use .\run-dev.ps1 -InstallIfNeeded."
}
}
if ((-not (Test-Path ".env")) -and (Test-Path ".env.example")) {
Copy-Item ".env.example" ".env"
}
function Test-PortInUse {
param([int]$Port)
$client = New-Object System.Net.Sockets.TcpClient
try {
$iar = $client.BeginConnect("127.0.0.1", $Port, $null, $null)
$connected = $iar.AsyncWaitHandle.WaitOne(250)
if ($connected -and $client.Connected) {
$client.EndConnect($iar) | Out-Null
return $true
}
return $false
} catch {
return $false
} finally {
$client.Close()
}
}
if (Test-PortInUse -Port $ApiPort) {
throw "Port $ApiPort is already in use. Run .\run-dev.cmd -ApiPort <free-port> to override it."
}
if (Test-PortInUse -Port $FrontendPort) {
throw "Port $FrontendPort is already in use. Run .\run-dev.cmd -FrontendPort <free-port> to override it."
}
if (-not $Reload) {
$buildIdFile = Join-Path $frontendRoot ".next\BUILD_ID"
if (-not (Test-Path $buildIdFile)) {
Write-Host "Building frontend for the first run..."
Push-Location $frontendRoot
try {
npm run build
} finally {
Pop-Location
}
}
}
$reloadArg = ""
if ($Reload) {
$reloadArg = " --reload"
}
$apiCommand = "Set-Location '$root'; & '$venvPython' -m uvicorn api.main:app --host 0.0.0.0 --port $ApiPort --log-level info$reloadArg"
if ($Reload) {
$frontendCommand = "Set-Location '$frontendRoot'; `$env:NEXT_PUBLIC_API_URL='http://localhost:$ApiPort'; npm run dev -- --port $FrontendPort"
} else {
$frontendCommand = "Set-Location '$frontendRoot'; `$env:NEXT_PUBLIC_API_URL='http://localhost:$ApiPort'; npx next start -p $FrontendPort"
}
Start-Process -FilePath "powershell" -WorkingDirectory $root -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-Command", $apiCommand
)
Start-Sleep -Seconds 2
Start-Process -FilePath "powershell" -WorkingDirectory $frontendRoot -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-Command", $frontendCommand
)
Write-Host "BloomFL dev servers are starting in separate PowerShell windows."
Write-Host "Backend: http://localhost:$ApiPort"
Write-Host "Docs: http://localhost:$ApiPort/docs"
Write-Host "Frontend: http://localhost:$FrontendPort"