-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·208 lines (180 loc) · 5.84 KB
/
start.sh
File metadata and controls
executable file
·208 lines (180 loc) · 5.84 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
# Smart Code Diff - Easy Start Script (Linux/macOS)
# This script starts both the Rust backend and Next.js frontend
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}ℹ ${NC}$1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check if a port is in use
port_in_use() {
lsof -i :"$1" >/dev/null 2>&1 || netstat -an | grep -q ":$1.*LISTEN" 2>/dev/null
}
# Function to kill process on port
kill_port() {
local port=$1
print_info "Killing process on port $port..."
lsof -ti:$port | xargs kill -9 2>/dev/null || true
}
# Cleanup function
cleanup() {
print_info "Shutting down services..."
if [ ! -z "$BACKEND_PID" ]; then
kill $BACKEND_PID 2>/dev/null || true
fi
if [ ! -z "$FRONTEND_PID" ]; then
kill $FRONTEND_PID 2>/dev/null || true
fi
print_success "Services stopped"
exit 0
}
# Set up trap for cleanup
trap cleanup SIGINT SIGTERM
# Print banner
echo ""
echo "╔═══════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ Smart Code Diff - Easy Start ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════╝"
echo ""
# Check prerequisites
print_info "Checking prerequisites..."
if ! command_exists cargo; then
print_error "Rust/Cargo is not installed. Please install from https://rustup.rs/"
exit 1
fi
print_success "Rust/Cargo found"
if ! command_exists node; then
print_error "Node.js is not installed. Please install from https://nodejs.org/"
exit 1
fi
print_success "Node.js found"
if ! command_exists npm; then
print_error "npm is not installed. Please install Node.js from https://nodejs.org/"
exit 1
fi
print_success "npm found"
# Check if ports are available
BACKEND_PORT=8080
FRONTEND_PORT=3000
if port_in_use $BACKEND_PORT; then
print_warning "Port $BACKEND_PORT is already in use"
read -p "Kill the process and continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
kill_port $BACKEND_PORT
sleep 2
else
print_error "Cannot start backend on port $BACKEND_PORT"
exit 1
fi
fi
if port_in_use $FRONTEND_PORT; then
print_warning "Port $FRONTEND_PORT is already in use"
read -p "Kill the process and continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
kill_port $FRONTEND_PORT
sleep 2
else
print_error "Cannot start frontend on port $FRONTEND_PORT"
exit 1
fi
fi
# Install frontend dependencies if needed
if [ ! -d "nextjs-frontend/node_modules" ]; then
print_info "Installing frontend dependencies (this may take a few minutes)..."
cd nextjs-frontend
npm install
cd ..
print_success "Frontend dependencies installed"
else
print_success "Frontend dependencies already installed"
fi
# Build backend if needed
if [ ! -f "target/release/smart-diff-server" ]; then
print_info "Building Rust backend (this may take a few minutes)..."
cargo build --release --bin smart-diff-server
print_success "Backend built successfully"
else
print_success "Backend already built"
fi
# Start backend
print_info "Starting Rust backend on port $BACKEND_PORT..."
RUST_LOG=info cargo run --release --bin smart-diff-server > backend.log 2>&1 &
BACKEND_PID=$!
# Wait for backend to start
print_info "Waiting for backend to be ready..."
for i in {1..30}; do
if curl -s http://localhost:$BACKEND_PORT/api/health > /dev/null 2>&1; then
print_success "Backend is ready!"
break
fi
if [ $i -eq 30 ]; then
print_error "Backend failed to start. Check backend.log for details."
cat backend.log
cleanup
exit 1
fi
sleep 1
done
# Start frontend
print_info "Starting Next.js frontend on port $FRONTEND_PORT..."
cd nextjs-frontend
npm run dev > ../frontend.log 2>&1 &
FRONTEND_PID=$!
cd ..
# Wait for frontend to start
print_info "Waiting for frontend to be ready..."
for i in {1..30}; do
if curl -s http://localhost:$FRONTEND_PORT > /dev/null 2>&1; then
print_success "Frontend is ready!"
break
fi
if [ $i -eq 30 ]; then
print_error "Frontend failed to start. Check frontend.log for details."
cat frontend.log
cleanup
exit 1
fi
sleep 1
done
# Success!
echo ""
echo "╔═══════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ 🚀 Services Started! ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════╝"
echo ""
print_success "Backend running at: http://localhost:$BACKEND_PORT"
print_success "Frontend running at: http://localhost:$FRONTEND_PORT"
echo ""
print_info "Logs:"
echo " - Backend: tail -f backend.log"
echo " - Frontend: tail -f frontend.log"
echo ""
print_warning "Press Ctrl+C to stop all services"
echo ""
# Keep script running and wait for Ctrl+C
wait