-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdev.ps1
More file actions
85 lines (76 loc) · 2.5 KB
/
Copy pathdev.ps1
File metadata and controls
85 lines (76 loc) · 2.5 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
# DeviceKit - dev helper
#
# Usage:
# .\dev.ps1 Start backend + frontend in separate windows
# .\dev.ps1 backend Start only the backend (in this window)
# .\dev.ps1 frontend Start only the frontend (in this window)
# .\dev.ps1 test Run backend tests (extra args go to pytest)
# .\dev.ps1 test -k ai e.g. only tests matching "ai"
param(
[Parameter(Position = 0)]
[ValidateSet('dev', 'backend', 'frontend', 'test')]
[string]$Command = 'dev',
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Rest
)
$root = $PSScriptRoot
# Add ADB to PATH if not already available
if (-not (Get-Command adb -ErrorAction SilentlyContinue)) {
$adbDirs = @(
'C:\Program Files (x86)\Android\android-sdk\platform-tools',
"$env:LOCALAPPDATA\Android\Sdk\platform-tools"
)
foreach ($dir in $adbDirs) {
if (Test-Path "$dir\adb.exe") {
$env:PATH = "$env:PATH;$dir"
break
}
}
}
switch ($Command) {
'test' {
Push-Location "$root\backend"
try {
python -m pytest tests/ @Rest
exit $LASTEXITCODE
}
finally {
Pop-Location
}
}
'backend' {
Set-Location "$root\backend"
python app.py
}
'frontend' {
Set-Location "$root\frontend"
npm run dev
}
'dev' {
Write-Host 'Starting DeviceKit dev servers...'
Write-Host ''
Write-Host ' Backend : http://localhost:7317'
Write-Host ' Frontend : http://localhost:7318'
Write-Host ''
Start-Process pwsh -WorkingDirectory "$root\backend" `
-ArgumentList '-NoExit', '-Command', 'python app.py'
# Wait for the backend to answer /health before opening the frontend,
# so the first page load doesn't race the boot.
Write-Host 'Waiting for backend...' -NoNewline
for ($i = 0; $i -lt 30; $i++) {
try {
$null = Invoke-WebRequest -Uri 'http://127.0.0.1:7317/health' -TimeoutSec 2 -UseBasicParsing
Write-Host ' ready.'
break
}
catch {
Write-Host '.' -NoNewline
Start-Sleep -Seconds 1
}
}
Start-Process pwsh -WorkingDirectory "$root\frontend" `
-ArgumentList '-NoExit', '-Command', 'npm run dev'
Write-Host 'Both servers started in separate windows.'
Write-Host 'Close those windows to stop the servers.'
}
}