-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
72 lines (61 loc) · 1.95 KB
/
start.ps1
File metadata and controls
72 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
# Exit immediately on error
$ErrorActionPreference = "Stop"
# ---- CONFIG ----
$pyEnv = ".\.venv\Scripts\Activate.ps1"
$nodeDir = ".\express-server"
$pyDir = ".\flask-server"
$nodeEntry = "server.js"
$pyEntry = "server.py"
$pyReqs = "$pyDir\requirements.txt"
# ---- CHECK PYTHON ENV ----
if (-Not (Test-Path $pyEnv)) {
Write-Host "Python virtual environment not found at $pyEnv"
Write-Host "Create it first with: python -m venv .venv"
exit 1
}
Write-Host "Activating Python virtual environment..."
& $pyEnv
# ---- INSTALL PYTHON DEPENDENCIES ----
if (Test-Path $pyReqs) {
Write-Host "Installing Python dependencies from requirements.txt..."
pip install --upgrade pip | Out-Null
pip install -r $pyReqs
} else {
Write-Host "No requirements.txt found in $pyDir — skipping Python dependency install."
}
# ---- INSTALL NODE DEPENDENCIES ----
if (-Not (Test-Path "$nodeDir\node_modules")) {
Write-Host "Installing Node.js dependencies..."
Push-Location $nodeDir
npm install
Pop-Location
} else {
Write-Host "Node.js dependencies already installed."
}
# ---- START SERVERS ----
Write-Host "Starting servers..."
# Start Flask server in background job
$flaskJob = Start-Job -ScriptBlock {
Write-Host "Starting Flask server..."
Set-Location ".\flask-server"
python "server.py"
}
# Start Node.js server in background job
$nodeJob = Start-Job -ScriptBlock {
Write-Host "Starting Node.js server..."
Set-Location ".\express-server"
node "server.js"
}
# ---- HANDLE SHUTDOWN ----
Write-Host "`nBoth servers started! Press Ctrl+C to stop them.`n"
# Graceful exit on Ctrl+C
$terminationHandler = {
Write-Host "`nStopping servers..."
Stop-Job $flaskJob, $nodeJob -Force | Out-Null
Remove-Job $flaskJob, $nodeJob -Force | Out-Null
Write-Host "👋 Shutdown complete."
exit
}
Register-EngineEvent PowerShell.Exiting -Action $terminationHandler | Out-Null
# Wait indefinitely
Wait-Job -Job $flaskJob, $nodeJob