@gv-sh/specgen-app 0.6.3 โ†’ 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SpecGen App - Complete Platform
2
2
 
3
- [![Version](https://img.shields.io/badge/version-0.6.3-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.6.4-blue.svg)](https://github.com/gv-sh/specgen-app)
4
4
 
5
5
  A unified deployment package for the SpecGen speculative fiction generator platform. **Optimized for port 8080 deployment with low memory usage.**
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gv-sh/specgen-app",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,6 +13,8 @@
13
13
  "start": "cd server && npm start",
14
14
  "production": "chmod +x scripts/production.sh && ./scripts/production.sh",
15
15
  "deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
16
+ "deploy:dry-run": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
17
+ "test:deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
16
18
  "make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
17
19
  "deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
18
20
  "deploy:restart": "chmod +x scripts/restart.sh && ./scripts/restart.sh",
package/scripts/deploy.sh CHANGED
@@ -3,7 +3,16 @@
3
3
  # SpecGen Deploy Script - Self-Contained Deployment on Port 8080
4
4
  set -e
5
5
 
6
- echo "๐Ÿš€ Deploying SpecGen to production on port 8080..."
6
+ # Check for dry-run mode
7
+ DRY_RUN=false
8
+ if [ "$1" = "--dry-run" ] || [ "$1" = "-d" ]; then
9
+ DRY_RUN=true
10
+ echo "๐Ÿงช DRY RUN MODE - Testing deployment locally"
11
+ echo "๐Ÿ–ฅ๏ธ Platform: $(uname -s) $(uname -m)"
12
+ else
13
+ echo "๐Ÿš€ Deploying SpecGen to production on port 8080..."
14
+ fi
15
+
7
16
  echo "๐Ÿ“ฆ This is a complete deployment - no separate setup needed!"
8
17
 
9
18
  # Function to check if port is available
@@ -21,30 +30,51 @@ PROJECT_DIR=$(pwd)
21
30
  echo "๐Ÿ“‚ Project directory: $PROJECT_DIR"
22
31
 
23
32
  # ========================================
24
- # FULL CLEANUP
33
+ # PLATFORM-SPECIFIC SETUP
25
34
  # ========================================
26
35
 
27
- echo "๐Ÿงน Cleaning up existing installations..."
28
-
29
- # Stop and remove all PM2 processes
30
- npx pm2 stop all 2>/dev/null || true
31
- npx pm2 delete all 2>/dev/null || true
32
- npx pm2 kill 2>/dev/null || true
33
-
34
- # Remove old PM2 config files
35
- rm -f ecosystem.config.js 2>/dev/null || true
36
+ # Detect platform
37
+ PLATFORM=$(uname -s)
38
+ if [ "$PLATFORM" = "Darwin" ]; then
39
+ echo "๐ŸŽ Detected macOS"
40
+ PM2_CMD="npx pm2"
41
+ elif [ "$PLATFORM" = "Linux" ]; then
42
+ echo "๐Ÿง Detected Linux"
43
+ PM2_CMD="npx pm2"
44
+ else
45
+ echo "โš ๏ธ Unknown platform: $PLATFORM"
46
+ PM2_CMD="npx pm2"
47
+ fi
36
48
 
37
- # Kill processes on all relevant ports
38
- for port in 8080 3000 3001 3002; do
39
- if ! check_port $port; then
40
- echo "Killing processes on port $port..."
41
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
42
- sleep 1
43
- fi
44
- done
49
+ # ========================================
50
+ # CLEANUP (Skip in dry-run for safety)
51
+ # ========================================
45
52
 
46
- # Clean up old files
47
- rm -rf logs/* 2>/dev/null || true
53
+ if [ "$DRY_RUN" = false ]; then
54
+ echo "๐Ÿงน Cleaning up existing installations..."
55
+
56
+ # Stop and remove all PM2 processes
57
+ $PM2_CMD stop all 2>/dev/null || true
58
+ $PM2_CMD delete all 2>/dev/null || true
59
+ $PM2_CMD kill 2>/dev/null || true
60
+
61
+ # Remove old PM2 config files
62
+ rm -f ecosystem.config.js 2>/dev/null || true
63
+
64
+ # Kill processes on all relevant ports
65
+ for port in 8080 3000 3001 3002; do
66
+ if ! check_port $port; then
67
+ echo "Killing processes on port $port..."
68
+ lsof -ti:$port | xargs kill -9 2>/dev/null || true
69
+ sleep 1
70
+ fi
71
+ done
72
+
73
+ # Clean up old files
74
+ rm -rf logs/* 2>/dev/null || true
75
+ else
76
+ echo "๐Ÿงช DRY RUN: Skipping cleanup (existing processes will remain)"
77
+ fi
48
78
 
49
79
  # ========================================
50
80
  # VERIFY PREREQUISITES
@@ -56,8 +86,32 @@ echo "๐Ÿ” Checking prerequisites..."
56
86
  NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
57
87
  if [ "$NODE_VERSION" -lt 20 ]; then
58
88
  echo "โŒ Node.js 20+ required. Current version: $(node --version)"
59
- echo "Install with: curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs"
89
+ if [ "$PLATFORM" = "Darwin" ]; then
90
+ echo "Install with: brew install node@20"
91
+ else
92
+ echo "Install with: curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs"
93
+ fi
60
94
  exit 1
95
+ else
96
+ echo "โœ… Node.js version: $(node --version)"
97
+ fi
98
+
99
+ # Check npm
100
+ echo "โœ… npm version: $(npm --version)"
101
+
102
+ # Check available memory
103
+ if [ "$PLATFORM" = "Darwin" ]; then
104
+ MEMORY_GB=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024)}')
105
+ echo "โœ… Available memory: ${MEMORY_GB}GB"
106
+ if [ "$MEMORY_GB" -lt 4 ]; then
107
+ echo "โš ๏ธ Warning: Less than 4GB RAM detected. Builds may be slow."
108
+ fi
109
+ elif [ "$PLATFORM" = "Linux" ]; then
110
+ MEMORY_GB=$(free -g | awk '/^Mem:/{print $2}')
111
+ echo "โœ… Available memory: ${MEMORY_GB}GB"
112
+ if [ "$MEMORY_GB" -lt 1 ]; then
113
+ echo "โš ๏ธ Warning: Less than 1GB RAM detected. Consider adding swap space."
114
+ fi
61
115
  fi
62
116
 
63
117
  # ========================================
@@ -66,8 +120,14 @@ fi
66
120
 
67
121
  echo "๐Ÿ”‘ Setting up OpenAI API key..."
68
122
 
69
- # Check if .env exists and has API key
70
- if [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
123
+ # In dry-run mode, use a test key
124
+ if [ "$DRY_RUN" = true ]; then
125
+ echo "๐Ÿงช DRY RUN: Using test API key"
126
+ mkdir -p "$PROJECT_DIR/server"
127
+ echo "OPENAI_API_KEY=sk-test1234567890abcdef" > "$PROJECT_DIR/server/.env"
128
+ echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
129
+ echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
130
+ elif [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
71
131
  if [ "$CI" = "true" ]; then
72
132
  echo "CI mode - using test API key"
73
133
  mkdir -p "$PROJECT_DIR/server"
@@ -76,12 +136,12 @@ if [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$P
76
136
  echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
77
137
  else
78
138
  echo "โš ๏ธ OpenAI API key required for SpecGen to work."
79
- echo "Enter your OpenAI API key: "
139
+ echo "Enter your OpenAI API key (or press Enter to use test key for dry-run): "
80
140
  read -r OPENAI_KEY
81
141
 
82
142
  if [ -z "$OPENAI_KEY" ]; then
83
- echo "โŒ No API key provided. SpecGen needs an OpenAI API key to function."
84
- exit 1
143
+ OPENAI_KEY="sk-test1234567890abcdef"
144
+ echo "Using test API key for this deployment"
85
145
  fi
86
146
 
87
147
  mkdir -p "$PROJECT_DIR/server"
@@ -101,35 +161,80 @@ echo "๐Ÿ—๏ธ Building application components..."
101
161
  # Navigate to project directory
102
162
  cd "$PROJECT_DIR"
103
163
 
104
- # Install and build server
105
- if [ ! -d "server" ] || [ ! -d "server/node_modules" ]; then
164
+ # Install and build server with better extraction
165
+ if [ ! -f "server/index.js" ]; then
106
166
  echo "๐Ÿ“ฆ Setting up server..."
107
- npm pack @gv-sh/specgen-server
167
+
168
+ # Clean up any existing server directory
169
+ rm -rf server
170
+
171
+ # Download and extract server
172
+ echo " Downloading server package..."
173
+ npm pack @gv-sh/specgen-server --loglevel=warn
174
+
175
+ echo " Extracting server package..."
108
176
  tar -xzf gv-sh-specgen-server-*.tgz
109
- mv package server
177
+
178
+ # Move the extracted package to server directory
179
+ if [ -d "package" ]; then
180
+ mv package server
181
+ echo "โœ… Server extracted successfully"
182
+ else
183
+ echo "โŒ Failed to extract server package"
184
+ ls -la
185
+ exit 1
186
+ fi
187
+
188
+ # Clean up the tar file
110
189
  rm gv-sh-specgen-server-*.tgz
111
190
 
191
+ # Install server dependencies
192
+ echo " Installing server dependencies..."
112
193
  cd server
113
194
  echo "engine-strict=false" > .npmrc
114
195
  npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
196
+
197
+ # Verify server files
198
+ if [ ! -f "index.js" ]; then
199
+ echo "โŒ Server index.js not found after installation"
200
+ echo "Server directory contents:"
201
+ ls -la
202
+ exit 1
203
+ fi
204
+
115
205
  cd "$PROJECT_DIR"
116
206
  fi
117
207
 
118
208
  # Install and build admin
119
209
  if [ ! -d "admin/build" ]; then
120
210
  echo "๐Ÿ“ฑ Building admin interface..."
211
+
121
212
  if [ ! -d "admin" ]; then
122
- npm pack @gv-sh/specgen-admin
213
+ # Clean up any existing admin directory
214
+ rm -rf admin
215
+
216
+ echo " Downloading admin package..."
217
+ npm pack @gv-sh/specgen-admin --loglevel=warn
123
218
  tar -xzf gv-sh-specgen-admin-*.tgz
124
- mv package admin
219
+
220
+ if [ -d "package" ]; then
221
+ mv package admin
222
+ echo "โœ… Admin extracted successfully"
223
+ else
224
+ echo "โŒ Failed to extract admin package"
225
+ exit 1
226
+ fi
227
+
125
228
  rm gv-sh-specgen-admin-*.tgz
126
229
  fi
127
230
 
231
+ echo " Installing admin dependencies..."
128
232
  cd admin
129
233
  echo "engine-strict=false" > .npmrc
130
234
  # Install ALL dependencies for build process
131
235
  npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
132
- # Build with proper environment variables (no cross-env needed on Linux)
236
+ echo " Building admin interface..."
237
+ # Build with proper environment variables
133
238
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
134
239
  cd "$PROJECT_DIR"
135
240
  fi
@@ -137,18 +242,33 @@ fi
137
242
  # Install and build user
138
243
  if [ ! -d "user/build" ]; then
139
244
  echo "๐Ÿ‘ค Building user interface..."
245
+
140
246
  if [ ! -d "user" ]; then
141
- npm pack @gv-sh/specgen-user
247
+ # Clean up any existing user directory
248
+ rm -rf user
249
+
250
+ echo " Downloading user package..."
251
+ npm pack @gv-sh/specgen-user --loglevel=warn
142
252
  tar -xzf gv-sh-specgen-user-*.tgz
143
- mv package user
253
+
254
+ if [ -d "package" ]; then
255
+ mv package user
256
+ echo "โœ… User extracted successfully"
257
+ else
258
+ echo "โŒ Failed to extract user package"
259
+ exit 1
260
+ fi
261
+
144
262
  rm gv-sh-specgen-user-*.tgz
145
263
  fi
146
264
 
265
+ echo " Installing user dependencies..."
147
266
  cd user
148
267
  echo "engine-strict=false" > .npmrc
149
268
  # Install ALL dependencies for build process
150
269
  npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
151
- # Build with proper environment variables (no cross-env needed on Linux)
270
+ echo " Building user interface..."
271
+ # Build with proper environment variables
152
272
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
153
273
  cd "$PROJECT_DIR"
154
274
  fi
@@ -158,20 +278,25 @@ fi
158
278
  # ========================================
159
279
 
160
280
  echo "โœ… Verifying builds..."
281
+
282
+ # Check admin build
161
283
  if [ ! -d "$PROJECT_DIR/admin/build" ]; then
162
284
  echo "โŒ Admin build failed"
163
285
  ls -la "$PROJECT_DIR/admin/" || echo "Admin directory not found"
164
286
  exit 1
165
287
  fi
166
288
 
289
+ # Check user build
167
290
  if [ ! -d "$PROJECT_DIR/user/build" ]; then
168
291
  echo "โŒ User build failed"
169
292
  ls -la "$PROJECT_DIR/user/" || echo "User directory not found"
170
293
  exit 1
171
294
  fi
172
295
 
296
+ # Check server
173
297
  if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
174
298
  echo "โŒ Server index.js not found"
299
+ echo "Server directory contents:"
175
300
  ls -la "$PROJECT_DIR/server/" || echo "Server directory not found"
176
301
  exit 1
177
302
  fi
@@ -179,23 +304,84 @@ fi
179
304
  echo "๐Ÿ“ Build verification:"
180
305
  echo " Admin build: $(ls -la "$PROJECT_DIR/admin/build/" | wc -l) files"
181
306
  echo " User build: $(ls -la "$PROJECT_DIR/user/build/" | wc -l) files"
182
- echo " Server: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
183
- echo " Server script: $PROJECT_DIR/server/index.js"
307
+ echo " Server files: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
308
+ echo " โœ… Server script: $PROJECT_DIR/server/index.js"
184
309
 
185
310
  # Show some sample files to verify builds
186
- echo "๐Ÿ“„ Admin build files:"
187
- ls "$PROJECT_DIR/admin/build/" | head -5
188
- echo "๐Ÿ“„ User build files:"
189
- ls "$PROJECT_DIR/user/build/" | head -5
311
+ echo "๐Ÿ“„ Key files found:"
312
+ echo " Admin: $(ls "$PROJECT_DIR/admin/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
313
+ echo " User: $(ls "$PROJECT_DIR/user/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
314
+ echo " Server: $(ls "$PROJECT_DIR/server/" | grep -E '\.(js|json)$' | head -3 | tr '\n' ' ')"
190
315
 
191
316
  # ========================================
192
- # PM2 DEPLOYMENT
317
+ # DEPLOYMENT / TEST SERVER
193
318
  # ========================================
194
319
 
195
- echo "๐Ÿš€ Starting PM2 deployment..."
196
-
197
- # Create PM2 ecosystem configuration with absolute paths
198
- cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
320
+ if [ "$DRY_RUN" = true ]; then
321
+ echo ""
322
+ echo "๐Ÿงช DRY RUN: Testing server startup..."
323
+
324
+ # Test if the server can start
325
+ cd "$PROJECT_DIR"
326
+
327
+ # Copy environment
328
+ cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
329
+
330
+ echo " Starting test server on port 8080 for 10 seconds..."
331
+
332
+ # Start server in background
333
+ (cd server && NODE_ENV=production PORT=8080 node index.js) &
334
+ SERVER_PID=$!
335
+
336
+ # Wait a bit for server to start
337
+ sleep 3
338
+
339
+ # Test the endpoints
340
+ echo " Testing endpoints:"
341
+
342
+ if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
343
+ echo " โœ… Health endpoint: OK"
344
+ echo " Response: $(curl -s http://localhost:8080/api/health | head -c 100)..."
345
+ else
346
+ echo " โŒ Health endpoint: FAILED"
347
+ fi
348
+
349
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null || echo "000")
350
+ echo " ๐Ÿ“„ Main page: HTTP $HTTP_CODE"
351
+
352
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null || echo "000")
353
+ echo " โš™๏ธ Admin page: HTTP $HTTP_CODE"
354
+
355
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null || echo "000")
356
+ echo " ๐Ÿ‘ค User page: HTTP $HTTP_CODE"
357
+
358
+ # Stop test server
359
+ sleep 2
360
+ kill $SERVER_PID 2>/dev/null || true
361
+ wait $SERVER_PID 2>/dev/null || true
362
+
363
+ echo ""
364
+ echo "๐ŸŽ‰ DRY RUN COMPLETED!"
365
+ echo ""
366
+ echo "๐Ÿ“Š Summary:"
367
+ echo " โœ… All packages downloaded and extracted"
368
+ echo " โœ… All dependencies installed"
369
+ echo " โœ… React apps built successfully"
370
+ echo " โœ… Server can start and respond"
371
+ echo ""
372
+ echo "๐Ÿš€ Ready for production deployment!"
373
+ echo " Run without --dry-run to deploy for real"
374
+ echo ""
375
+ echo "๐Ÿ”ง To test locally:"
376
+ echo " cd server && npm start"
377
+ echo " Open http://localhost:8080/"
378
+
379
+ else
380
+ # Real deployment with PM2
381
+ echo "๐Ÿš€ Starting PM2 deployment..."
382
+
383
+ # Create PM2 ecosystem configuration with absolute paths
384
+ cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
199
385
  module.exports = {
200
386
  apps: [{
201
387
  name: 'specgen',
@@ -220,113 +406,72 @@ module.exports = {
220
406
  }]
221
407
  }
222
408
  EOF
223
-
224
- # Create logs directory
225
- mkdir -p "$PROJECT_DIR/logs"
226
-
227
- # Copy .env to project root for PM2
228
- cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
229
-
230
- # Final port check
231
- if ! check_port 8080; then
232
- echo "Port 8080 occupied, force cleaning..."
233
- lsof -ti:8080 | xargs kill -9 2>/dev/null || true
234
- sleep 2
235
- fi
236
-
237
- # Change to project directory and start with PM2
238
- cd "$PROJECT_DIR"
239
- echo "โ–ถ๏ธ Starting SpecGen with PM2..."
240
- echo " Script: $PROJECT_DIR/server/index.js"
241
- echo " Working Directory: $PROJECT_DIR"
242
-
243
- # Verify the script exists before starting PM2
244
- if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
245
- echo "โŒ ERROR: Server script not found at $PROJECT_DIR/server/index.js"
246
- echo "Contents of server directory:"
247
- ls -la "$PROJECT_DIR/server/"
248
- exit 1
249
- fi
250
-
251
- NODE_ENV=production PORT=8080 npx pm2 start "$PROJECT_DIR/ecosystem.config.js"
252
-
253
- # Wait for startup and verify
254
- sleep 5
255
-
256
- # ========================================
257
- # DEPLOYMENT VERIFICATION
258
- # ========================================
259
-
260
- echo "๐Ÿ” Verifying deployment..."
261
-
262
- if npx pm2 list | grep -q "online"; then
263
- # Test endpoints
264
- echo "Testing endpoints:"
265
409
 
266
- # Test health endpoint
267
- if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
268
- echo "โœ… Health endpoint: OK"
269
- else
270
- echo "โŒ Health endpoint: FAILED"
271
- fi
410
+ # Create logs directory
411
+ mkdir -p "$PROJECT_DIR/logs"
272
412
 
273
- # Test main page
274
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
275
- if [ "$HTTP_CODE" = "200" ]; then
276
- echo "โœ… Main page: OK (HTTP $HTTP_CODE)"
277
- else
278
- echo "โš ๏ธ Main page: HTTP $HTTP_CODE"
279
- # Show what the server is actually serving
280
- echo "Response preview:"
281
- curl -s http://localhost:8080/ | head -3
282
- fi
413
+ # Copy .env to project root for PM2
414
+ cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
283
415
 
284
- # Test admin
285
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null)
286
- if [ "$HTTP_CODE" = "200" ]; then
287
- echo "โœ… Admin page: OK (HTTP $HTTP_CODE)"
288
- else
289
- echo "โš ๏ธ Admin page: HTTP $HTTP_CODE"
416
+ # Final port check
417
+ if ! check_port 8080; then
418
+ echo "Port 8080 occupied, force cleaning..."
419
+ lsof -ti:8080 | xargs kill -9 2>/dev/null || true
420
+ sleep 2
290
421
  fi
291
422
 
292
- # Test user app
293
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null)
294
- if [ "$HTTP_CODE" = "200" ]; then
295
- echo "โœ… User app: OK (HTTP $HTTP_CODE)"
296
- else
297
- echo "โš ๏ธ User app: HTTP $HTTP_CODE"
298
- fi
423
+ # Start with PM2
424
+ cd "$PROJECT_DIR"
425
+ echo "โ–ถ๏ธ Starting SpecGen with PM2..."
299
426
 
300
- PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
427
+ NODE_ENV=production PORT=8080 $PM2_CMD start "$PROJECT_DIR/ecosystem.config.js"
301
428
 
302
- echo ""
303
- echo "๐ŸŽ‰ SpecGen deployment completed!"
304
- echo ""
305
- echo "๐ŸŒ Access your application at:"
306
- echo " - Main page: http://$PUBLIC_IP:8080/"
307
- echo " - User app: http://$PUBLIC_IP:8080/app"
308
- echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
309
- echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
310
- echo " - Health check: http://$PUBLIC_IP:8080/api/health"
311
- echo ""
312
- echo "๐Ÿ“Š Management:"
313
- echo " npx pm2 status # Check status"
314
- echo " npx pm2 logs specgen # View logs"
315
- echo " npx pm2 restart specgen # Restart"
316
- echo ""
317
- echo "๐Ÿ”ง Troubleshooting:"
318
- echo " curl http://localhost:8080/api/health # Test API"
319
- echo " curl -I http://localhost:8080/ # Test main page"
320
- echo " ls -la */build/ # Check builds"
321
- echo ""
429
+ # Wait for startup and verify
430
+ sleep 5
322
431
 
323
- else
324
- echo ""
325
- echo "โŒ Deployment failed!"
326
- echo "๐Ÿ“ Check logs: npx pm2 logs specgen"
327
- echo "๐Ÿ“Š Check status: npx pm2 status"
328
- echo ""
329
- echo "Recent logs:"
330
- npx pm2 logs specgen --lines 10
331
- exit 1
432
+ # Verify deployment
433
+ echo "๐Ÿ” Verifying deployment..."
434
+
435
+ if $PM2_CMD list | grep -q "online"; then
436
+ echo "Testing endpoints:"
437
+
438
+ if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
439
+ echo "โœ… Health endpoint: OK"
440
+ else
441
+ echo "โŒ Health endpoint: FAILED"
442
+ fi
443
+
444
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
445
+ echo "๐Ÿ“„ Main page: HTTP $HTTP_CODE"
446
+
447
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null)
448
+ echo "โš™๏ธ Admin page: HTTP $HTTP_CODE"
449
+
450
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null)
451
+ echo "๐Ÿ‘ค User page: HTTP $HTTP_CODE"
452
+
453
+ PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
454
+
455
+ echo ""
456
+ echo "๐ŸŽ‰ SpecGen deployment completed!"
457
+ echo ""
458
+ echo "๐ŸŒ Access your application at:"
459
+ echo " - Main page: http://$PUBLIC_IP:8080/"
460
+ echo " - User app: http://$PUBLIC_IP:8080/app"
461
+ echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
462
+ echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
463
+ echo " - Health check: http://$PUBLIC_IP:8080/api/health"
464
+ echo ""
465
+ echo "๐Ÿ“Š Management commands:"
466
+ echo " $PM2_CMD status # Check status"
467
+ echo " $PM2_CMD logs specgen # View logs"
468
+ echo " $PM2_CMD restart specgen # Restart"
469
+
470
+ else
471
+ echo ""
472
+ echo "โŒ Deployment failed!"
473
+ echo "๐Ÿ“ Check logs: $PM2_CMD logs specgen"
474
+ echo "๐Ÿ“Š Check status: $PM2_CMD status"
475
+ exit 1
476
+ fi
332
477
  fi