-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-dev.ps1
More file actions
178 lines (155 loc) · 6.91 KB
/
start-dev.ps1
File metadata and controls
178 lines (155 loc) · 6.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env pwsh
<#
.SYNOPSIS
SteerDock Development Mode Startup Script
.DESCRIPTION
Starts backend and frontend in development mode with hot-reload
.EXAMPLE
.\start-dev.ps1
#>
$ErrorActionPreference = "Stop"
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ SteerDock Development Mode ║" -ForegroundColor Cyan
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
# Check requirements
Write-Host "Checking requirements..." -ForegroundColor Yellow
# Check Go
try {
$null = Get-Command go -ErrorAction Stop
Write-Host "Go found" -ForegroundColor Green
} catch {
Write-Host "Go is not installed. Please install Go 1.24+" -ForegroundColor Red
exit 1
}
# Check Node.js
try {
$null = Get-Command node -ErrorAction Stop
Write-Host "Node.js found" -ForegroundColor Green
} catch {
Write-Host "Node.js is not installed. Please install Node.js 18+" -ForegroundColor Red
exit 1
}
# Check npm
try {
$null = Get-Command npm -ErrorAction Stop
Write-Host "npm found" -ForegroundColor Green
} catch {
Write-Host "npm is not installed. Please install npm" -ForegroundColor Red
exit 1
}
Write-Host ""
# Stop any existing processes
Write-Host "Stopping existing processes..." -ForegroundColor Yellow
# Stop Go processes (backend)
$goProcesses = Get-Process -Name "go" -ErrorAction SilentlyContinue
if ($goProcesses) {
$goProcesses | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Host "Stopped $($goProcesses.Count) Go process(es)" -ForegroundColor Green
}
# Stop Node.js processes (frontend)
$nodeProcesses = Get-Process -Name "node" -ErrorAction SilentlyContinue | Where-Object {
$_.ProcessName -eq "node" -and $_.MainWindowTitle -notlike "*Visual Studio Code*"
}
if ($nodeProcesses) {
$nodeProcesses | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Host "Stopped $($nodeProcesses.Count) Node.js process(es)" -ForegroundColor Green
}
# Stop any processes using ports 8383 and 5151
$portsToCheck = @(8383, 5151)
foreach ($port in $portsToCheck) {
try {
$connections = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue
if ($connections) {
foreach ($connection in $connections) {
$processId = $connection.OwningProcess
if ($processId -gt 0) {
$process = Get-Process -Id $processId -ErrorAction SilentlyContinue
if ($process) {
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
Write-Host "Stopped process $($process.ProcessName) (PID: $processId) using port $port" -ForegroundColor Green
}
}
}
}
} catch {
# Ignore errors when checking ports
}
}
Start-Sleep -Seconds 2
# Create logs directory if it doesn't exist
if (-not (Test-Path "logs")) {
New-Item -ItemType Directory -Path "logs" | Out-Null
}
# Start backend
Write-Host "Starting backend (Go)..." -ForegroundColor Yellow
Set-Location backend
go mod tidy
$backendProcess = Start-Process -FilePath "go" -ArgumentList "run", "." -RedirectStandardOutput "..\logs\backend-dev.log" -RedirectStandardError "..\logs\backend-dev-error.log" -PassThru -NoNewWindow
Write-Host "Backend started (PID: $($backendProcess.Id))" -ForegroundColor Green
Set-Location ..
# Wait for backend to start
Write-Host "Waiting for backend to start..." -ForegroundColor Yellow
Start-Sleep -Seconds 5
# Check if backend is running
try {
$response = Invoke-WebRequest -Uri "http://localhost:8383/health/live" -UseBasicParsing -TimeoutSec 10
if ($response.StatusCode -eq 200) {
Write-Host "Backend is healthy" -ForegroundColor Green
} else {
Write-Host "Backend health check failed (Status: $($response.StatusCode))" -ForegroundColor Red
exit 1
}
} catch {
Write-Host "Backend failed to start or health check failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Check logs\backend-dev.log for details" -ForegroundColor Yellow
exit 1
}
# Start frontend
Write-Host "Starting frontend (Vite)..." -ForegroundColor Yellow
Set-Location frontend
# Install dependencies if needed
if (-not (Test-Path "node_modules")) {
Write-Host "Installing frontend dependencies..." -ForegroundColor Yellow
& npm install
}
# Find npm.cmd or use cmd to run npm
$npmCmd = Get-Command npm.cmd -ErrorAction SilentlyContinue
if (-not $npmCmd) {
$npmCmd = Get-Command npm -ErrorAction SilentlyContinue
}
if (-not $npmCmd) {
Write-Host "npm not found in PATH. Please ensure Node.js is properly installed." -ForegroundColor Red
exit 1
}
Write-Host "Using npm at: $($npmCmd.Source)" -ForegroundColor Gray
try {
# Use cmd.exe to run npm for better compatibility
$frontendProcess = Start-Process -FilePath "cmd.exe" -ArgumentList "/c", "npm run dev" -RedirectStandardOutput "..\logs\frontend-dev.log" -RedirectStandardError "..\logs\frontend-dev-error.log" -PassThru -NoNewWindow
Write-Host "Frontend started (PID: $($frontendProcess.Id))" -ForegroundColor Green
} catch {
Write-Host "Failed to start frontend: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Set-Location ..
Write-Host ""
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ SteerDock Started ║" -ForegroundColor Green
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
Write-Host "Access Points:" -ForegroundColor Cyan
Write-Host " Frontend (Dev): http://localhost:5151" -ForegroundColor Green
Write-Host " Backend API: http://localhost:8383" -ForegroundColor Green
Write-Host " Health Check: http://localhost:8383/health/live" -ForegroundColor Green
Write-Host ""
Write-Host "Default Login:" -ForegroundColor Cyan
Write-Host " Username: admin" -ForegroundColor Yellow
Write-Host " Password: admin123" -ForegroundColor Yellow
Write-Host ""
Write-Host "Logs:" -ForegroundColor Cyan
Write-Host " Backend: Get-Content logs\backend-dev.log -Wait" -ForegroundColor Yellow
Write-Host " Frontend: Get-Content logs\frontend-dev.log -Wait" -ForegroundColor Yellow
Write-Host ""
Write-Host "To stop all services:" -ForegroundColor Cyan
Write-Host " .\stop-all.ps1" -ForegroundColor Yellow
Write-Host ""