-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-local.sh
More file actions
278 lines (229 loc) · 6.59 KB
/
Copy pathsetup-local.sh
File metadata and controls
278 lines (229 loc) · 6.59 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
#!/bin/bash
# ============================================
# ResCash Local Development Setup Script
# ============================================
set -e # Exit on error
echo "============================================"
echo "ResCash Local Development Setup"
echo "============================================"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored messages
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_info() {
echo -e "${YELLOW}ℹ $1${NC}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Step 1: Check Prerequisites
echo "Step 1: Checking Prerequisites..."
echo "-----------------------------------"
# Check Node.js
if command_exists node; then
NODE_VERSION=$(node -v)
print_success "Node.js is installed: $NODE_VERSION"
else
print_error "Node.js is not installed!"
echo "Please install Node.js from https://nodejs.org/"
exit 1
fi
# Check npm
if command_exists npm; then
NPM_VERSION=$(npm -v)
print_success "npm is installed: $NPM_VERSION"
else
print_error "npm is not installed!"
exit 1
fi
# Check MongoDB
if command_exists mongod; then
print_success "MongoDB is installed"
else
print_error "MongoDB is not installed!"
echo "Please install MongoDB from https://www.mongodb.com/try/download/community"
exit 1
fi
echo ""
# Step 2: Setup Backend
echo "Step 2: Setting Up Backend..."
echo "-----------------------------------"
cd backend
# Copy environment file if it doesn't exist
if [ ! -f .env ]; then
if [ -f .env.local ]; then
cp .env.local .env
print_success "Created .env from .env.local"
else
cp .env.example .env
print_info "Created .env from .env.example - Please update with your settings"
fi
else
print_info ".env file already exists"
fi
# Install backend dependencies
print_info "Installing backend dependencies..."
npm install
if [ $? -eq 0 ]; then
print_success "Backend dependencies installed"
else
print_error "Failed to install backend dependencies"
exit 1
fi
cd ..
echo ""
# Step 3: Setup Frontend
echo "Step 3: Setting Up Frontend..."
echo "-----------------------------------"
cd resCash
# Copy environment file if it doesn't exist
if [ ! -f .env.local ]; then
if [ -f .env.local.example ]; then
cp .env.local.example .env.local
print_success "Created .env.local from .env.local.example"
else
cp .env.example .env.local
print_info "Created .env.local from .env.example"
fi
else
print_info ".env.local file already exists"
fi
# Install frontend dependencies
print_info "Installing frontend dependencies..."
npm install
if [ $? -eq 0 ]; then
print_success "Frontend dependencies installed"
else
print_error "Failed to install frontend dependencies"
exit 1
fi
cd ..
echo ""
# Step 4: Check MongoDB Status
echo "Step 4: Checking MongoDB..."
echo "-----------------------------------"
# Try to connect to MongoDB
if mongosh --eval "db.runCommand({ ping: 1 })" --quiet > /dev/null 2>&1; then
print_success "MongoDB is running"
else
print_info "MongoDB is not running. Attempting to start..."
# Try to start MongoDB (platform-specific)
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
if command_exists brew; then
brew services start mongodb-community
sleep 2
if mongosh --eval "db.runCommand({ ping: 1 })" --quiet > /dev/null 2>&1; then
print_success "MongoDB started successfully"
else
print_error "Failed to start MongoDB"
echo "Please start MongoDB manually: brew services start mongodb-community"
fi
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
sudo systemctl start mongod
sleep 2
if mongosh --eval "db.runCommand({ ping: 1 })" --quiet > /dev/null 2>&1; then
print_success "MongoDB started successfully"
else
print_error "Failed to start MongoDB"
echo "Please start MongoDB manually: sudo systemctl start mongod"
fi
else
print_info "Please start MongoDB manually"
fi
fi
echo ""
# Step 5: Create Startup Scripts
echo "Step 5: Creating Startup Scripts..."
echo "-----------------------------------"
# Create start script
cat > start-dev.sh << 'EOF'
#!/bin/bash
# Start Backend and Frontend in Development Mode
echo "Starting ResCash Development Environment..."
# Start backend in background
echo "Starting backend server..."
cd backend
npm start &
BACKEND_PID=$!
echo "Backend started (PID: $BACKEND_PID)"
# Wait for backend to be ready
sleep 3
# Start frontend
echo "Starting frontend development server..."
cd ../resCash
npm start
# When frontend stops, kill backend
kill $BACKEND_PID
EOF
chmod +x start-dev.sh
print_success "Created start-dev.sh script"
# Create stop script
cat > stop-dev.sh << 'EOF'
#!/bin/bash
# Stop all ResCash processes
echo "Stopping ResCash Development Environment..."
# Kill backend (Node.js on port 8099)
lsof -ti:8099 | xargs kill -9 2>/dev/null
echo "Backend stopped"
# Kill frontend (React dev server on port 3000)
lsof -ti:3000 | xargs kill -9 2>/dev/null
echo "Frontend stopped"
echo "All processes stopped"
EOF
chmod +x stop-dev.sh
print_success "Created stop-dev.sh script"
echo ""
# Step 6: Summary
echo "============================================"
echo "Setup Complete!"
echo "============================================"
echo ""
print_success "Backend configured in: ./backend"
print_success "Frontend configured in: ./resCash"
echo ""
echo "Configuration Files:"
echo " - backend/.env (Backend environment)"
echo " - resCash/.env.local (Frontend environment)"
echo ""
echo "Development Mode Settings:"
echo " ✓ ENABLE_DEV_LOGIN=true (bypasses ResVault)"
echo " ✓ ENABLE_RESILIENT_SYNC=false (faster startup)"
echo " ✓ MongoDB: Local instance"
echo ""
echo "Next Steps:"
echo "-----------------------------------"
echo "1. Review configuration files if needed:"
echo " nano backend/.env"
echo " nano resCash/.env.local"
echo ""
echo "2. Start the application:"
echo " ./start-dev.sh"
echo ""
echo " Or start manually:"
echo " # Terminal 1 - Backend"
echo " cd backend && npm start"
echo ""
echo " # Terminal 2 - Frontend"
echo " cd resCash && npm start"
echo ""
echo "3. Access the application:"
echo " http://localhost:3000"
echo ""
echo "4. Stop the application:"
echo " ./stop-dev.sh"
echo ""
print_info "For production deployment, see DEPLOYMENT.md"
echo ""