-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-dev-remote.sh
executable file
·99 lines (81 loc) · 2.44 KB
/
start-dev-remote.sh
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
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# Function to check if a port is in use
check_port() {
local port=$1
if lsof -i :$port > /dev/null; then
return 0
else
return 1
fi
}
# Store the script's directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PID_DIR="${SCRIPT_DIR}/storage/pids"
LARAVEL_PID_FILE="${PID_DIR}/laravel.pid"
VITE_PID_FILE="${PID_DIR}/vite.pid"
# Create pids directory if it doesn't exist
mkdir -p "${PID_DIR}"
# Check if .env file exists
if [ ! -f "${SCRIPT_DIR}/.env" ]; then
print_status "$RED" "Error: .env file not found"
exit 1
fi
# Check if required ports are available
if check_port 8000; then
print_status "$RED" "Error: Port 8000 is already in use"
exit 1
fi
if check_port 5173; then
print_status "$RED" "Error: Port 5173 is already in use"
exit 1
fi
# Install dependencies if needed
if [ ! -d "${SCRIPT_DIR}/vendor" ]; then
print_status "$YELLOW" "Installing PHP dependencies..."
composer install
fi
if [ ! -d "${SCRIPT_DIR}/node_modules" ]; then
print_status "$YELLOW" "Installing Node.js dependencies..."
npm install
fi
# Clear Laravel caches
print_status "$YELLOW" "Clearing Laravel caches..."
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
# Run database migrations
# print_status "$YELLOW" "Running database migrations..."
# php artisan migrate
# Start Laravel development server
print_status "$YELLOW" "Starting Laravel development server..."
php artisan serve > /dev/null 2>&1 & echo $! > "${LARAVEL_PID_FILE}"
# Start Vite development server
print_status "$YELLOW" "Starting Vite development server..."
npm run dev > /dev/null 2>&1 & echo $! > "${VITE_PID_FILE}"
# Wait for servers to start
sleep 3
# Check if servers are running
if ! check_port 8000; then
print_status "$RED" "Error: Laravel development server failed to start"
exit 1
fi
if ! check_port 5173; then
print_status "$RED" "Error: Vite development server failed to start"
exit 1
fi
print_status "$GREEN" "Development servers started successfully!"
print_status "$GREEN" "Laravel: http://localhost:8000"
print_status "$GREEN" "Vite: http://localhost:5173"
print_status "$YELLOW" "Use ./stop-dev-remote.sh to stop the servers"