-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·353 lines (298 loc) · 9.5 KB
/
setup.sh
File metadata and controls
executable file
·353 lines (298 loc) · 9.5 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
# RecipeGenius Project Setup Script
# This script sets up the entire RecipeGenius application
set -e
# 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_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${BLUE}$1${NC}"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check Node.js version
check_node_version() {
local required_version="16"
local current_version=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$current_version" -lt "$required_version" ]; then
print_error "Node.js version $required_version or higher is required. Current version: $current_version"
return 1
fi
return 0
}
# Function to install dependencies
install_dependencies() {
print_header "📦 Installing Dependencies"
# Backend dependencies
if [ -d "backend" ]; then
print_status "Installing backend dependencies..."
cd backend
npm install
cd ..
fi
# Frontend dependencies
if [ -d "frontend" ]; then
print_status "Installing frontend dependencies..."
cd frontend
npm install
cd ..
fi
print_status "✅ Dependencies installed successfully!"
}
# Function to setup environment files
setup_environment() {
print_header "🔧 Setting up environment files"
# Backend .env
if [ -d "backend" ] && [ ! -f "backend/.env" ]; then
print_status "Creating backend .env file..."
cat > backend/.env << EOF
# RecipeGenius Backend Environment Variables
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/recipegenius
# Authentication (Get these from https://clerk.com)
CLERK_PUBLISHABLE_KEY=pk_test_your_clerk_publishable_key_here
CLERK_SECRET_KEY=sk_test_your_clerk_secret_key_here
# External APIs (Get from https://spoonacular.com/food-api)
SPOONACULAR_API_KEY=your_spoonacular_api_key_here
# Optional: For production
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/recipegenius
EOF
print_status "✅ Backend .env file created"
fi
# Frontend .env
if [ -d "frontend" ] && [ ! -f "frontend/.env" ]; then
print_status "Creating frontend .env file..."
cat > frontend/.env << EOF
# RecipeGenius Frontend Environment Variables
REACT_APP_API_URL=http://localhost:5000
REACT_APP_CLERK_PUBLISHABLE_KEY=pk_test_your_clerk_publishable_key_here
REACT_APP_SPOONACULAR_API_KEY=your_spoonacular_api_key_here
EOF
print_status "✅ Frontend .env file created"
fi
print_warning "⚠️ Please update the .env files with your actual API keys!"
}
# Function to check prerequisites
check_prerequisites() {
print_header "🔍 Checking prerequisites"
# Check Node.js
if ! command_exists node; then
print_error "Node.js is not installed. Please install Node.js from https://nodejs.org/"
exit 1
fi
if ! check_node_version; then
exit 1
fi
print_status "✅ Node.js $(node -v) is installed"
# Check npm
if ! command_exists npm; then
print_error "npm is not installed. Please install npm."
exit 1
fi
print_status "✅ npm $(npm -v) is installed"
# Check MongoDB (optional)
if command_exists mongod; then
print_status "✅ MongoDB is installed"
else
print_warning "⚠️ MongoDB is not installed locally. You'll need to use MongoDB Atlas or install MongoDB."
fi
# Check Git
if command_exists git; then
print_status "✅ Git is installed"
else
print_warning "⚠️ Git is not installed. You may need it for version control."
fi
# Check Docker (optional)
if command_exists docker; then
print_status "✅ Docker is installed"
else
print_warning "⚠️ Docker is not installed. You won't be able to use Docker deployment."
fi
}
# Function to start development servers
start_development() {
print_header "🚀 Starting development servers"
# Check if MongoDB is running
if ! pgrep mongod > /dev/null; then
print_warning "⚠️ MongoDB is not running. Please start MongoDB first."
print_status "You can start MongoDB with: sudo systemctl start mongod"
print_status "Or use MongoDB Atlas cloud database."
fi
# Start backend in background
if [ -d "backend" ]; then
print_status "Starting backend server..."
cd backend
npm run dev &
BACKEND_PID=$!
cd ..
sleep 3
print_status "✅ Backend server started (PID: $BACKEND_PID)"
fi
# Start frontend
if [ -d "frontend" ]; then
print_status "Starting frontend server..."
cd frontend
npm start &
FRONTEND_PID=$!
cd ..
sleep 3
print_status "✅ Frontend server started (PID: $FRONTEND_PID)"
fi
print_status "🎉 Development servers are starting!"
print_status "📱 Frontend: http://localhost:3000"
print_status "🔧 Backend: http://localhost:5000"
print_status "Press Ctrl+C to stop all servers"
# Wait for user input to stop servers
trap 'kill $BACKEND_PID $FRONTEND_PID 2>/dev/null' EXIT
read -p "Press Enter to stop servers..."
}
# Function to run tests
run_tests() {
print_header "🧪 Running tests"
# Backend tests
if [ -d "backend" ] && [ -f "backend/package.json" ]; then
if grep -q "test" backend/package.json; then
print_status "Running backend tests..."
cd backend
npm test
cd ..
fi
fi
# Frontend tests
if [ -d "frontend" ] && [ -f "frontend/package.json" ]; then
if grep -q "test" frontend/package.json; then
print_status "Running frontend tests..."
cd frontend
npm test -- --watchAll=false
cd ..
fi
fi
print_status "✅ Tests completed!"
}
# Function to build for production
build_production() {
print_header "🏗️ Building for production"
# Build backend
if [ -d "backend" ]; then
print_status "Building backend..."
cd backend
npm install --production
cd ..
fi
# Build frontend
if [ -d "frontend" ]; then
print_status "Building frontend..."
cd frontend
npm run build
cd ..
fi
print_status "✅ Production build completed!"
}
# Function to setup with Docker
setup_docker() {
print_header "🐳 Setting up with Docker"
if ! command_exists docker; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
if ! command_exists docker-compose; then
print_error "Docker Compose is not installed. Please install Docker Compose first."
exit 1
fi
# Create .env file for Docker
if [ ! -f ".env" ]; then
cp .env.example .env
print_status "Created .env file from .env.example"
print_warning "⚠️ Please update .env with your actual values!"
fi
# Build and start containers
print_status "Building and starting Docker containers..."
docker-compose up --build -d
print_status "✅ Docker setup completed!"
print_status "🌐 Application is available at: http://localhost:3000"
print_status "🔧 API is available at: http://localhost:5000"
print_status "Use 'docker-compose logs -f' to view logs"
print_status "Use 'docker-compose down' to stop containers"
}
# Function to show help
show_help() {
echo "🍽️ RecipeGenius Setup Script"
echo "Usage: $0 [OPTION]"
echo ""
echo "Options:"
echo " setup Complete setup (default)"
echo " install Install dependencies only"
echo " env Setup environment files only"
echo " start Start development servers"
echo " test Run tests"
echo " build Build for production"
echo " docker Setup with Docker"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " $0 setup # Complete setup"
echo " $0 docker # Setup with Docker"
echo " $0 start # Start development servers"
}
# Main function
main() {
local action=${1:-setup}
case $action in
setup)
print_header "🍽️ RecipeGenius Complete Setup"
check_prerequisites
install_dependencies
setup_environment
print_status "🎉 Setup completed!"
print_status "Next steps:"
print_status "1. Update .env files with your API keys"
print_status "2. Start MongoDB (if using local installation)"
print_status "3. Run './setup.sh start' to start development servers"
;;
install)
install_dependencies
;;
env)
setup_environment
;;
start)
start_development
;;
test)
run_tests
;;
build)
build_production
;;
docker)
setup_docker
;;
help|--help|-h)
show_help
;;
*)
print_error "Unknown option: $action"
show_help
exit 1
;;
esac
}
# Run main function
main "$@"