-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.ps1
91 lines (74 loc) · 2.91 KB
/
dev.ps1
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
# dev.ps1
#Requires -Version 5.1
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Write-Status {
param(
[string]$Message,
[string]$Type = "Info"
)
$colors = @{
Info = "Cyan"
Success = "Green"
Warning = "Yellow"
Error = "Red"
}
$prefix = switch ($Type) {
"Success" { "[+]" }
"Error" { "[-]" }
"Warning" { "[!]" }
"Info" { "[*]" }
}
Write-Host "$prefix $Message" -ForegroundColor $colors[$Type]
}
function Start-Development {
try {
# Create logs directory if it doesn't exist
if (-not (Test-Path "logs")) {
New-Item -ItemType Directory -Path "logs"
}
# Start log file
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$logFile = "logs/dev_$timestamp.log"
Start-Transcript -Path $logFile
# Check for running processes on ports 3000 and 8787
$port3000 = Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue
$port8787 = Get-NetTCPConnection -LocalPort 8787 -ErrorAction SilentlyContinue
if ($port3000) {
Write-Status "Killing process using port 3000..." "Warning"
Stop-Process -Id (Get-Process -Id $port3000.OwningProcess).Id -Force
}
if ($port8787) {
Write-Status "Killing process using port 8787..." "Warning"
Stop-Process -Id (Get-Process -Id $port8787.OwningProcess).Id -Force
}
# Start Vite and Wrangler in separate windows
Write-Status "Starting development servers..." "Info"
# Start Vite
$viteWindow = Start-Process powershell -ArgumentList "-NoExit", "-Command", "npm run dev" -PassThru
# Start Wrangler
$wranglerWindow = Start-Process powershell -ArgumentList "-NoExit", "-Command", "npx wrangler dev spotify-worker.ts" -PassThru
Write-Status "Development servers started successfully!" "Success"
Write-Status "Vite running on: http://localhost:3000" "Info"
Write-Status "Worker running on: http://localhost:8787" "Info"
Write-Status "Log file: $logFile" "Info"
# Wait for user input to stop servers
Write-Host "`nPress any key to stop the development servers..." -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
# Stop the servers
if ($viteWindow) { Stop-Process -Id $viteWindow.Id -Force }
if ($wranglerWindow) { Stop-Process -Id $wranglerWindow.Id -Force }
Write-Status "Development servers stopped" "Success"
}
catch {
Write-Status "Error during development: $_" "Error"
if ($viteWindow) { Stop-Process -Id $viteWindow.Id -Force }
if ($wranglerWindow) { Stop-Process -Id $wranglerWindow.Id -Force }
exit 1
}
finally {
Stop-Transcript
}
}
# Run the development environment
Start-Development