-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.ps1
More file actions
133 lines (110 loc) · 4.05 KB
/
preview.ps1
File metadata and controls
133 lines (110 loc) · 4.05 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
# ChairShare Preview Script for Windows (PowerShell)
# This script automatically sets up and launches the ChairShare preview
# Set error action preference
$ErrorActionPreference = "Stop"
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " ChairShare Preview Launcher" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Function to check if a command exists
function Test-CommandExists {
param($command)
$null = Get-Command $command -ErrorAction SilentlyContinue
return $?
}
# Check if Node.js is installed
if (-not (Test-CommandExists "node")) {
Write-Host "[WARNING] Node.js is not installed. Please install Node.js 18 or higher." -ForegroundColor Yellow
Read-Host "Press Enter to exit"
exit 1
}
# Check if npm is installed
if (-not (Test-CommandExists "npm")) {
Write-Host "[WARNING] npm is not installed. Please install npm 9 or higher." -ForegroundColor Yellow
Read-Host "Press Enter to exit"
exit 1
}
Write-Host "[OK] Node.js and npm found" -ForegroundColor Green
Write-Host ""
# Check if node_modules exists in root
if (-not (Test-Path "node_modules")) {
Write-Host "[INFO] Installing root dependencies..." -ForegroundColor Blue
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed to install root dependencies" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
}
# Navigate to client directory
if (-not (Test-Path "client")) {
Write-Host "[ERROR] Client directory not found" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Set-Location client
# Check if node_modules exists in client
if (-not (Test-Path "node_modules")) {
Write-Host "[INFO] Installing frontend dependencies..." -ForegroundColor Blue
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed to install frontend dependencies" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
}
Write-Host "[OK] All dependencies are ready" -ForegroundColor Green
Write-Host ""
# Function to find an available port
function Find-AvailablePort {
param($startPort)
$maxPort = $startPort + 100
for ($port = $startPort; $port -le $maxPort; $port++) {
$portInUse = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue
if (-not $portInUse) {
return $port
}
}
return $null
}
# Find an available port starting from 3000
Write-Host "[INFO] Searching for an available port..." -ForegroundColor Blue
$PORT = Find-AvailablePort -startPort 3000
if ($null -eq $PORT) {
Write-Host "[ERROR] Could not find an available port between 3000-3100" -ForegroundColor Red
Write-Host "Please free some ports and try again." -ForegroundColor Yellow
Read-Host "Press Enter to exit"
exit 1
}
if ($PORT -ne 3000) {
Write-Host "[WARNING] Port 3000 is in use, using port $PORT instead" -ForegroundColor Yellow
} else {
Write-Host "[OK] Port 3000 is available" -ForegroundColor Green
}
Write-Host ""
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Starting ChairShare preview" -ForegroundColor Cyan
Write-Host " http://localhost:$PORT" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host " The application will open in your browser shortly..." -ForegroundColor Yellow
Write-Host " Press Ctrl+C to stop the preview server" -ForegroundColor Yellow
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
# Wait a moment before starting
Start-Sleep -Seconds 2
# Start browser in background after a delay
$job = Start-Job -ScriptBlock {
param($port)
Start-Sleep -Seconds 5
Start-Process "http://localhost:$port"
} -ArgumentList $PORT
# Set PORT environment variable for npm start
$env:PORT = $PORT
# Start the development server
npm start