-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-local.ps1
More file actions
288 lines (244 loc) · 8.57 KB
/
Copy pathsetup-local.ps1
File metadata and controls
288 lines (244 loc) · 8.57 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
# ============================================
# ResCash Local Development Setup Script (Windows)
# ============================================
Write-Host "============================================" -ForegroundColor Cyan
Write-Host "ResCash Local Development Setup" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
# Function to print colored messages
function Print-Success {
param($Message)
Write-Host "✓ $Message" -ForegroundColor Green
}
function Print-Error {
param($Message)
Write-Host "✗ $Message" -ForegroundColor Red
}
function Print-Info {
param($Message)
Write-Host "ℹ $Message" -ForegroundColor Yellow
}
# Check if command exists
function Test-Command {
param($Command)
try {
if (Get-Command $Command -ErrorAction Stop) {
return $true
}
}
catch {
return $false
}
}
# Step 1: Check Prerequisites
Write-Host "Step 1: Checking Prerequisites..." -ForegroundColor Cyan
Write-Host "-----------------------------------"
# Check Node.js
if (Test-Command node) {
$nodeVersion = node -v
Print-Success "Node.js is installed: $nodeVersion"
}
else {
Print-Error "Node.js is not installed!"
Write-Host "Please install Node.js from https://nodejs.org/"
exit 1
}
# Check npm
if (Test-Command npm) {
$npmVersion = npm -v
Print-Success "npm is installed: $npmVersion"
}
else {
Print-Error "npm is not installed!"
exit 1
}
# Check MongoDB
if (Test-Command mongod) {
Print-Success "MongoDB is installed"
}
else {
Print-Error "MongoDB is not installed!"
Write-Host "Please install MongoDB from https://www.mongodb.com/try/download/community"
exit 1
}
Write-Host ""
# Step 2: Setup Backend
Write-Host "Step 2: Setting Up Backend..." -ForegroundColor Cyan
Write-Host "-----------------------------------"
Set-Location backend
# Copy environment file if it doesn't exist
if (-Not (Test-Path .env)) {
if (Test-Path .env.local) {
Copy-Item .env.local .env
Print-Success "Created .env from .env.local"
}
elseif (Test-Path .env.example) {
Copy-Item .env.example .env
Print-Info "Created .env from .env.example - Please update with your settings"
}
}
else {
Print-Info ".env file already exists"
}
# Install backend dependencies
Print-Info "Installing backend dependencies..."
npm install
if ($LASTEXITCODE -eq 0) {
Print-Success "Backend dependencies installed"
}
else {
Print-Error "Failed to install backend dependencies"
exit 1
}
Set-Location ..
Write-Host ""
# Step 3: Setup Frontend
Write-Host "Step 3: Setting Up Frontend..." -ForegroundColor Cyan
Write-Host "-----------------------------------"
Set-Location resCash
# Copy environment file if it doesn't exist
if (-Not (Test-Path .env.local)) {
if (Test-Path .env.local.example) {
Copy-Item .env.local.example .env.local
Print-Success "Created .env.local from .env.local.example"
}
elseif (Test-Path .env.example) {
Copy-Item .env.example .env.local
Print-Info "Created .env.local from .env.example"
}
}
else {
Print-Info ".env.local file already exists"
}
# Install frontend dependencies
Print-Info "Installing frontend dependencies..."
npm install
if ($LASTEXITCODE -eq 0) {
Print-Success "Frontend dependencies installed"
}
else {
Print-Error "Failed to install frontend dependencies"
exit 1
}
Set-Location ..
Write-Host ""
# Step 4: Check MongoDB Status
Write-Host "Step 4: Checking MongoDB..." -ForegroundColor Cyan
Write-Host "-----------------------------------"
# Check if MongoDB service is running
$mongoService = Get-Service -Name MongoDB -ErrorAction SilentlyContinue
if ($mongoService) {
if ($mongoService.Status -eq 'Running') {
Print-Success "MongoDB service is running"
}
else {
Print-Info "Starting MongoDB service..."
Start-Service MongoDB
Start-Sleep -Seconds 2
Print-Success "MongoDB service started"
}
}
else {
Print-Info "MongoDB service not found. Checking if MongoDB is running manually..."
try {
$testConnection = mongosh --eval "db.runCommand({ ping: 1 })" --quiet 2>$null
if ($?) {
Print-Success "MongoDB is running"
}
else {
Print-Error "MongoDB is not running"
Print-Info "Please start MongoDB manually"
}
}
catch {
Print-Error "Cannot connect to MongoDB"
Print-Info "Please start MongoDB manually"
}
}
Write-Host ""
# Step 5: Create Startup Scripts
Write-Host "Step 5: Creating Startup Scripts..." -ForegroundColor Cyan
Write-Host "-----------------------------------"
# Create start script
$startScript = @'
# Start ResCash Development Environment
Write-Host "Starting ResCash Development Environment..." -ForegroundColor Cyan
# Start backend
Write-Host "Starting backend server..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; npm start"
# Wait for backend to start
Start-Sleep -Seconds 3
# Start frontend
Write-Host "Starting frontend development server..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd resCash; npm start"
Write-Host ""
Write-Host "✓ Development servers started!" -ForegroundColor Green
Write-Host " Backend: http://localhost:8099" -ForegroundColor Cyan
Write-Host " Frontend: http://localhost:3000" -ForegroundColor Cyan
Write-Host ""
Write-Host "To stop servers, run: .\stop-dev.ps1" -ForegroundColor Yellow
'@
$startScript | Out-File -FilePath start-dev.ps1 -Encoding UTF8
Print-Success "Created start-dev.ps1 script"
# Create stop script
$stopScript = @'
# Stop ResCash Development Environment
Write-Host "Stopping ResCash Development Environment..." -ForegroundColor Cyan
# Kill backend (Node.js on port 8099)
Write-Host "Stopping backend..." -ForegroundColor Yellow
$backendProcesses = Get-NetTCPConnection -LocalPort 8099 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess -Unique
foreach ($pid in $backendProcesses) {
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
}
# Kill frontend (React dev server on port 3000)
Write-Host "Stopping frontend..." -ForegroundColor Yellow
$frontendProcesses = Get-NetTCPConnection -LocalPort 3000 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess -Unique
foreach ($pid in $frontendProcesses) {
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
}
Write-Host "✓ All processes stopped" -ForegroundColor Green
'@
$stopScript | Out-File -FilePath stop-dev.ps1 -Encoding UTF8
Print-Success "Created stop-dev.ps1 script"
Write-Host ""
# Step 6: Summary
Write-Host "============================================" -ForegroundColor Cyan
Write-Host "Setup Complete!" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Print-Success "Backend configured in: .\backend"
Print-Success "Frontend configured in: .\resCash"
Write-Host ""
Write-Host "Configuration Files:"
Write-Host " - backend\.env (Backend environment)"
Write-Host " - resCash\.env.local (Frontend environment)"
Write-Host ""
Write-Host "Development Mode Settings:"
Write-Host " ✓ ENABLE_DEV_LOGIN=true (bypasses ResVault)" -ForegroundColor Green
Write-Host " ✓ ENABLE_RESILIENT_SYNC=false (faster startup)" -ForegroundColor Green
Write-Host " ✓ MongoDB: Local instance" -ForegroundColor Green
Write-Host ""
Write-Host "Next Steps:" -ForegroundColor Yellow
Write-Host "-----------------------------------"
Write-Host "1. Review configuration files if needed:"
Write-Host " notepad backend\.env"
Write-Host " notepad resCash\.env.local"
Write-Host ""
Write-Host "2. Start the application:"
Write-Host " .\start-dev.ps1" -ForegroundColor Cyan
Write-Host ""
Write-Host " Or start manually in separate terminals:"
Write-Host " # Terminal 1 - Backend"
Write-Host " cd backend; npm start"
Write-Host ""
Write-Host " # Terminal 2 - Frontend"
Write-Host " cd resCash; npm start"
Write-Host ""
Write-Host "3. Access the application:"
Write-Host " http://localhost:3000" -ForegroundColor Cyan
Write-Host ""
Write-Host "4. Stop the application:"
Write-Host " .\stop-dev.ps1" -ForegroundColor Cyan
Write-Host ""
Print-Info "For production deployment, see DEPLOYMENT.md"
Write-Host ""