Repository navigation
Expand file tree
/
Copy pathdev-tmux.sh
More file actions
executable file
·133 lines (107 loc) · 3.15 KB
/
Copy pathdev-tmux.sh
File metadata and controls
executable file
·133 lines (107 loc) · 3.15 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
#!/usr/bin/env bash
# Check if tmux is installed
if ! command -v tmux &> /dev/null; then
echo "tmux is not installed. Please install tmux first."
exit 1
fi
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check for required commands
for cmd in pnpm docker docker-compose; do
if ! command_exists "$cmd"; then
echo "Required command '$cmd' is not installed."
exit 1
fi
done
# Function to start docker services
start_docker() {
echo "Starting docker services..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
./dev.sh start
else
./dev.sh start-local
fi
}
# Function to setup services
setup_services() {
echo "Setting up services..."
echo "Running database migrations..."
pnpm i
pnpm dev:migrate latest
echo "Building database schemas..."
cd core/schema && pnpm build --env-file ../../.env && cd ../..
echo "Generating API schema..."
cd apps/server && mkdir -p dist/ && pnpm generate:swagger && cd ../..
echo "Building API client..."
cd core/openapi-spec && pnpm build && cd ../..
echo "All services are set up!"
}
# Function to setup tmux panes
setup_tmux() {
echo "Setting up tmux session for server processes..."
# Create a new tmux session
tmux new-session -d -s noctf
# Rename the window
tmux rename-window -t noctf:0 'noctf'
# Create first split (now we have 2 panes)
tmux split-window -h -t noctf:0
# Create second split (now we have 3 panes)
tmux split-window -h -t noctf:0.1
# Resize panes to make them equal size
tmux select-layout -t noctf:0 even-horizontal
echo "Starting server processes..."
# Left: Server
tmux send-keys -t noctf:0.0 'cd apps/server && pnpm dev:www' C-m
# Middle: Worker
tmux send-keys -t noctf:0.1 'cd apps/server && pnpm dev:worker' C-m
# Right: Web
tmux send-keys -t noctf:0.2 'cd apps/web && pnpm dev' C-m
}
# Function to cleanup on exit
stop() {
echo "Cleaning up noctf development environment..."
echo "Stopping tmux session..."
if tmux kill-session -t noctf 2>/dev/null; then
echo "✓ Tmux session 'noctf' stopped successfully"
else
echo "! No tmux session 'noctf' was running"
fi
echo "Stopping docker services..."
if ./dev.sh stop; then
echo "✓ Docker services stopped successfully"
else
echo "! Error stopping docker services"
exit 1
fi
echo "✓ Cleanup completed successfully"
}
# Main start function
start() {
echo "Starting noctf development environment..."
# Start docker services
start_docker
# Setup all services
setup_services
# Setup tmux and start server processes
setup_tmux
# Attach to the session
echo "Starting tmux session 'noctf'..."
echo "Use 'tmux attach -t noctf' to attach to the session if you detach."
echo "Use 'tmux kill-session -t noctf' to stop all services."
tmux attach -t noctf
}
# Handle command line arguments
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac