forked from filip-pilar/makesomething
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.ps1
More file actions
75 lines (66 loc) · 2.39 KB
/
run.ps1
File metadata and controls
75 lines (66 loc) · 2.39 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
# Make Something — Resume Script (Windows)
# Resume script — double-click run.bat to restart your project
$ErrorActionPreference = "Stop"
$INSTALL_DIR = $PSScriptRoot
Set-Location $INSTALL_DIR
Write-Host ""
Write-Host " ==============================" -ForegroundColor Cyan
Write-Host " Make Something" -ForegroundColor Cyan
Write-Host " ==============================" -ForegroundColor Cyan
Write-Host ""
# --- 1. Check dependencies ---
if (-not (Test-Path "$INSTALL_DIR\node_modules")) {
Write-Host "-> Installing dependencies..."
npm install
} else {
Write-Host "[OK] Dependencies ready"
}
# --- 2. Kill any existing process on port 3000 ---
$existing = Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue
if ($existing) {
$existing | ForEach-Object {
Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue
}
}
# --- 3. Start dev server ---
Write-Host "-> Starting dev server..."
try {
$npmPath = (Get-Command npm).Source
} catch {
Write-Host ""
Write-Host " npm not found in PATH. Please close and reopen PowerShell, then re-run this script." -ForegroundColor Yellow
exit 1
}
$devProcess = Start-Process -FilePath $npmPath -ArgumentList "run","dev" -WorkingDirectory $INSTALL_DIR -PassThru -WindowStyle Hidden
try {
# --- 4. Wait for server ---
Write-Host "-> Waiting for your app to start..."
$tries = 0
$maxTries = 30
while ($tries -lt $maxTries) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) { break }
} catch {}
Start-Sleep -Seconds 1
$tries++
}
# --- 5. Open browser ---
Start-Process "http://localhost:3000"
Write-Host ""
Write-Host " [OK] Ready! Launching Codex..." -ForegroundColor Green
Write-Host ""
# --- 6. Launch Codex (full-auto so beginners never see approval prompts) ---
codex --full-auto
} finally {
# --- 7. Cleanup ---
Write-Host ""
Write-Host " Stopping dev server..."
Stop-Process -Id $devProcess.Id -Force -ErrorAction SilentlyContinue
$remaining = Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue
if ($remaining) {
$remaining | ForEach-Object {
Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue
}
}
}