-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconductor-run.sh
More file actions
executable file
·99 lines (83 loc) · 2.47 KB
/
conductor-run.sh
File metadata and controls
executable file
·99 lines (83 loc) · 2.47 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
#!/bin/bash
set -e
echo "🚀 Starting Lab development servers..."
echo ""
# Function to find an available port
find_available_port() {
local start_port=$1
local port=$start_port
while lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1 ; do
port=$((port + 1))
done
echo $port
}
# Determine ports
VITE_PORT=$(find_available_port 5173)
STORYBOOK_PORT=$(find_available_port 6006)
# Function to cleanup on exit
cleanup() {
echo ""
echo "🛑 Shutting down servers..."
kill $VITE_PID 2>/dev/null || true
kill $STORYBOOK_PID 2>/dev/null || true
exit
}
# Trap SIGINT and SIGTERM
trap cleanup SIGINT SIGTERM
# Create log files for capturing output
VITE_LOG=$(mktemp)
STORYBOOK_LOG=$(mktemp)
# Start Vite dev server in background
echo "📦 Starting Vite dev server..."
PORT=$VITE_PORT pnpm dev > "$VITE_LOG" 2>&1 &
VITE_PID=$!
# Start Storybook in background
echo "📚 Starting Storybook..."
pnpm exec storybook dev -p $STORYBOOK_PORT --no-open > "$STORYBOOK_LOG" 2>&1 &
STORYBOOK_PID=$!
# Wait for servers to be ready and capture their ports
echo "⏳ Waiting for servers to start..."
# Wait for Vite to output its port
ACTUAL_VITE_PORT=""
for i in {1..30}; do
if [ -f "$VITE_LOG" ]; then
ACTUAL_VITE_PORT=$(grep -oE "http://localhost:[0-9]+" "$VITE_LOG" | grep -oE "[0-9]+" | head -1)
if [ -n "$ACTUAL_VITE_PORT" ]; then
break
fi
fi
sleep 0.2
done
# Wait for Storybook to output its port
ACTUAL_STORYBOOK_PORT=""
for i in {1..30}; do
if [ -f "$STORYBOOK_LOG" ]; then
ACTUAL_STORYBOOK_PORT=$(grep -oE "Local:.*http://localhost:[0-9]+" "$STORYBOOK_LOG" | grep -oE "[0-9]+" | head -1)
if [ -n "$ACTUAL_STORYBOOK_PORT" ]; then
break
fi
fi
sleep 0.2
done
# Fallback to expected ports if detection failed
ACTUAL_VITE_PORT=${ACTUAL_VITE_PORT:-$VITE_PORT}
ACTUAL_STORYBOOK_PORT=${ACTUAL_STORYBOOK_PORT:-$STORYBOOK_PORT}
echo ""
echo "✅ Both servers are running!"
echo ""
echo " 📦 Frontend: http://localhost:$ACTUAL_VITE_PORT"
echo " 📚 Storybook: http://localhost:$ACTUAL_STORYBOOK_PORT"
echo ""
echo "Press Ctrl+C to stop both servers"
echo ""
# Cleanup temp log files on exit
cleanup_logs() {
rm -f "$VITE_LOG" "$STORYBOOK_LOG"
kill $TAIL_PID 2>/dev/null || true
}
trap "cleanup; cleanup_logs" SIGINT SIGTERM EXIT
# Tail both log files to show output
tail -f "$VITE_LOG" "$STORYBOOK_LOG" &
TAIL_PID=$!
# Wait for both processes
wait $VITE_PID $STORYBOOK_PID