-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathstart.ps1
More file actions
266 lines (216 loc) · 6.46 KB
/
start.ps1
File metadata and controls
266 lines (216 loc) · 6.46 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/env pwsh
<#
.SYNOPSIS
OwnPilot - Startup Script for Windows
.DESCRIPTION
Starts the OwnPilot platform with gateway API and optional UI.
.PARAMETER Mode
Startup mode: 'dev' (default), 'prod', or 'docker'
.PARAMETER NoUI
Skip starting the UI (gateway only)
.PARAMETER Build
Force rebuild before starting
.PARAMETER Port
Gateway API port (default: 8080)
.PARAMETER UIPort
UI dev server port (default: 5173)
.EXAMPLE
.\start.ps1
Starts in development mode with hot reload
.EXAMPLE
.\start.ps1 -Mode prod
Builds and starts in production mode
.EXAMPLE
.\start.ps1 -NoUI
Starts gateway only, without UI
.EXAMPLE
.\start.ps1 -Mode docker
Starts using Docker Compose
#>
param(
[ValidateSet('dev', 'prod', 'docker')]
[string]$Mode = 'dev',
[switch]$NoUI,
[switch]$Build,
[int]$Port = 8200,
[int]$UIPort = 5173
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Colors
function Write-Header { param([string]$msg) Write-Host "`n=== $msg ===" -ForegroundColor Cyan }
function Write-Success { param([string]$msg) Write-Host "[OK] $msg" -ForegroundColor Green }
function Write-Info { param([string]$msg) Write-Host "[INFO] $msg" -ForegroundColor Yellow }
function Write-Err { param([string]$msg) Write-Host "[ERROR] $msg" -ForegroundColor Red }
# Banner
Write-Host @"
___ ____ _ _ _
/ _ \__ ___ __ | _ \(_) | ___ | |_
| | | \ \ /\ / / '_ \| |_) | | |/ _ \| __|
| |_| |\ V V /| | | | __/| | | (_) | |_
\___/ \_/\_/ |_| |_|_| |_|_|\___/ \__|
Gateway v0.1.1
"@ -ForegroundColor Magenta
# Check prerequisites
function Test-Prerequisites {
Write-Header "Checking Prerequisites"
# Node.js
try {
$nodeVersion = node -v
if ($nodeVersion -match "v(\d+)") {
$major = [int]$Matches[1]
if ($major -lt 22) {
Write-Err "Node.js 22+ required (found $nodeVersion)"
exit 1
}
}
Write-Success "Node.js $nodeVersion"
} catch {
Write-Err "Node.js not found. Install from https://nodejs.org"
exit 1
}
# pnpm
try {
$pnpmVersion = pnpm -v
Write-Success "pnpm $pnpmVersion"
} catch {
Write-Info "pnpm not found, installing..."
npm install -g pnpm
}
# Docker (only for docker mode)
if ($Mode -eq 'docker') {
try {
$dockerVersion = docker -v
Write-Success "Docker $dockerVersion"
} catch {
Write-Err "Docker not found. Install from https://docker.com"
exit 1
}
}
}
# Load environment
function Initialize-Environment {
Write-Header "Loading Environment"
$envFile = Join-Path $ScriptDir ".env"
$envExampleFile = Join-Path $ScriptDir ".env.example"
if (Test-Path $envFile) {
Write-Success "Loading .env file"
Get-Content $envFile | ForEach-Object {
if ($_ -match "^([^#=]+)=(.*)$") {
$key = $Matches[1].Trim()
$value = $Matches[2].Trim()
[Environment]::SetEnvironmentVariable($key, $value, "Process")
}
}
} elseif (Test-Path $envExampleFile) {
Write-Info "No .env found. Copy .env.example to .env and configure it."
Write-Info "Continuing with default/demo settings..."
}
# Set defaults
$env:PORT = $Port
if (-not $env:HOST) { $env:HOST = "127.0.0.1" }
$env:NODE_ENV = if ($Mode -eq 'prod') { "production" } else { "development" }
}
# Install dependencies
function Install-Dependencies {
Write-Header "Installing Dependencies"
Set-Location $ScriptDir
if (-not (Test-Path "node_modules")) {
Write-Info "Installing packages..."
pnpm install --frozen-lockfile
} else {
Write-Success "Dependencies already installed"
}
}
# Build project
function Build-Project {
Write-Header "Building Project"
Set-Location $ScriptDir
pnpm build
if ($LASTEXITCODE -ne 0) {
Write-Err "Build failed!"
exit 1
}
Write-Success "Build complete"
}
# Start in development mode
function Start-DevMode {
Write-Header "Starting Development Mode"
Write-Info "Gateway API: http://localhost:$Port"
if (-not $NoUI) {
Write-Info "UI: http://localhost:$UIPort"
}
Write-Info "Press Ctrl+C to stop`n"
Set-Location $ScriptDir
# Start gateway in background
$gatewayJob = Start-Job -ScriptBlock {
param($dir, $port)
Set-Location $dir
$env:PORT = $port
pnpm --filter @ownpilot/gateway dev
} -ArgumentList $ScriptDir, $Port
if (-not $NoUI) {
# Start UI in background
$uiJob = Start-Job -ScriptBlock {
param($dir, $port)
Set-Location $dir
$env:UI_PORT = $port
pnpm --filter @ownpilot/ui dev
} -ArgumentList $ScriptDir, $UIPort
}
# Wait and show output
try {
while ($true) {
Receive-Job -Job $gatewayJob -ErrorAction SilentlyContinue
if ($uiJob) {
Receive-Job -Job $uiJob -ErrorAction SilentlyContinue
}
Start-Sleep -Milliseconds 500
}
} finally {
Write-Info "`nStopping services..."
Stop-Job -Job $gatewayJob -ErrorAction SilentlyContinue
Remove-Job -Job $gatewayJob -Force -ErrorAction SilentlyContinue
if ($uiJob) {
Stop-Job -Job $uiJob -ErrorAction SilentlyContinue
Remove-Job -Job $uiJob -Force -ErrorAction SilentlyContinue
}
}
}
# Start in production mode
function Start-ProdMode {
Write-Header "Starting Production Mode"
Write-Info "Gateway API: http://localhost:$Port"
Write-Info "Press Ctrl+C to stop`n"
Set-Location $ScriptDir
# Serve gateway
$env:PORT = $Port
pnpm --filter @ownpilot/gateway start
}
# Start with Docker
function Start-DockerMode {
Write-Header "Starting with Docker"
Set-Location $ScriptDir
if ($NoUI) {
docker compose up --build gateway
} else {
docker compose --profile postgres up --build
}
}
# Main
try {
Test-Prerequisites
Initialize-Environment
Install-Dependencies
if ($Build -or $Mode -eq 'prod') {
Build-Project
}
switch ($Mode) {
'dev' { Start-DevMode }
'prod' { Start-ProdMode }
'docker' { Start-DockerMode }
}
} catch {
Write-Err $_.Exception.Message
exit 1
}