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

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.5-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.5",
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,8 +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..."
7
- echo "๐Ÿ“ฆ This is a complete deployment - no separate setup needed!"
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
+ echo "๐Ÿ“ฆ This is a complete deployment - no separate setup needed!"
15
+ fi
8
16
 
9
17
  # Function to check if port is available
10
18
  check_port() {
@@ -17,34 +25,62 @@ check_port() {
17
25
  }
18
26
 
19
27
  # Get absolute path of current working directory
20
- PROJECT_DIR=$(pwd)
28
+ # In dry-run, use the actual working directory, not NPX cache
29
+ if [ "$DRY_RUN" = true ]; then
30
+ PROJECT_DIR=$(pwd)
31
+ else
32
+ PROJECT_DIR=$(pwd)
33
+ fi
34
+
21
35
  echo "๐Ÿ“‚ Project directory: $PROJECT_DIR"
22
36
 
23
37
  # ========================================
24
- # FULL CLEANUP
38
+ # PLATFORM-SPECIFIC SETUP
25
39
  # ========================================
26
40
 
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
41
+ # Detect platform
42
+ PLATFORM=$(uname -s)
43
+ if [ "$PLATFORM" = "Darwin" ]; then
44
+ echo "๐ŸŽ Detected macOS"
45
+ PM2_CMD="npx pm2"
46
+ elif [ "$PLATFORM" = "Linux" ]; then
47
+ echo "๐Ÿง Detected Linux"
48
+ PM2_CMD="npx pm2"
49
+ else
50
+ echo "โš ๏ธ Unknown platform: $PLATFORM"
51
+ PM2_CMD="npx pm2"
52
+ fi
36
53
 
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
54
+ # ========================================
55
+ # CLEANUP (Skip in dry-run for safety)
56
+ # ========================================
45
57
 
46
- # Clean up old files
47
- rm -rf logs/* 2>/dev/null || true
58
+ if [ "$DRY_RUN" = false ]; then
59
+ echo "๐Ÿงน Cleaning up existing installations..."
60
+
61
+ # Stop and remove all PM2 processes
62
+ $PM2_CMD stop all 2>/dev/null || true
63
+ $PM2_CMD delete all 2>/dev/null || true
64
+ $PM2_CMD kill 2>/dev/null || true
65
+
66
+ # Remove old PM2 config files
67
+ rm -f ecosystem.config.js 2>/dev/null || true
68
+
69
+ # Kill processes on all relevant ports
70
+ for port in 8080 3000 3001 3002; do
71
+ if ! check_port $port; then
72
+ echo "Killing processes on port $port..."
73
+ lsof -ti:$port | xargs kill -9 2>/dev/null || true
74
+ sleep 1
75
+ fi
76
+ done
77
+
78
+ # Clean up old files
79
+ rm -rf logs/* 2>/dev/null || true
80
+ else
81
+ echo "๐Ÿงช DRY RUN: Skipping cleanup (existing processes will remain)"
82
+ echo " This is a safe test that won't affect your system"
83
+ fi
48
84
 
49
85
  # ========================================
50
86
  # VERIFY PREREQUISITES
@@ -52,22 +88,75 @@ rm -rf logs/* 2>/dev/null || true
52
88
 
53
89
  echo "๐Ÿ” Checking prerequisites..."
54
90
 
55
- # Check Node.js version
91
+ # Check Node.js version (more lenient for dry-run)
56
92
  NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
57
- if [ "$NODE_VERSION" -lt 20 ]; then
58
- 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"
60
- exit 1
93
+ if [ "$DRY_RUN" = true ]; then
94
+ # More lenient for dry-run testing
95
+ if [ "$NODE_VERSION" -lt 18 ]; then
96
+ echo "โŒ Node.js 18+ required for testing. Current version: $(node --version)"
97
+ if [ "$PLATFORM" = "Darwin" ]; then
98
+ echo "Install with: brew install node"
99
+ fi
100
+ exit 1
101
+ else
102
+ echo "โœ… Node.js version: $(node --version) (sufficient for testing)"
103
+ if [ "$NODE_VERSION" -lt 20 ]; then
104
+ echo " โš ๏ธ Note: Production deployment requires Node.js 20+"
105
+ fi
106
+ fi
107
+ else
108
+ # Strict for production
109
+ if [ "$NODE_VERSION" -lt 20 ]; then
110
+ echo "โŒ Node.js 20+ required for production. Current version: $(node --version)"
111
+ if [ "$PLATFORM" = "Darwin" ]; then
112
+ echo "Install with: brew install node@20"
113
+ else
114
+ echo "Install with: curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs"
115
+ fi
116
+ exit 1
117
+ else
118
+ echo "โœ… Node.js version: $(node --version)"
119
+ fi
120
+ fi
121
+
122
+ # Check npm
123
+ echo "โœ… npm version: $(npm --version)"
124
+
125
+ # Check available memory
126
+ if [ "$PLATFORM" = "Darwin" ]; then
127
+ MEMORY_GB=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024)}')
128
+ echo "โœ… Available memory: ${MEMORY_GB}GB"
129
+ if [ "$MEMORY_GB" -lt 4 ]; then
130
+ echo "โš ๏ธ Warning: Less than 4GB RAM detected. Builds may be slow."
131
+ fi
132
+ elif [ "$PLATFORM" = "Linux" ]; then
133
+ MEMORY_GB=$(free -g | awk '/^Mem:/{print $2}')
134
+ echo "โœ… Available memory: ${MEMORY_GB}GB"
135
+ if [ "$MEMORY_GB" -lt 1 ]; then
136
+ echo "โš ๏ธ Warning: Less than 1GB RAM detected. Consider adding swap space."
137
+ fi
61
138
  fi
62
139
 
140
+ # Check if we have required tools
141
+ echo "โœ… Platform tools:"
142
+ echo " curl: $(which curl >/dev/null && echo "available" || echo "missing")"
143
+ echo " tar: $(which tar >/dev/null && echo "available" || echo "missing")"
144
+ echo " lsof: $(which lsof >/dev/null && echo "available" || echo "missing")"
145
+
63
146
  # ========================================
64
147
  # SETUP OPENAI API KEY
65
148
  # ========================================
66
149
 
67
150
  echo "๐Ÿ”‘ Setting up OpenAI API key..."
68
151
 
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
152
+ # In dry-run mode, always use a test key
153
+ if [ "$DRY_RUN" = true ]; then
154
+ echo "๐Ÿงช DRY RUN: Using test API key"
155
+ mkdir -p "$PROJECT_DIR/server"
156
+ echo "OPENAI_API_KEY=sk-test1234567890abcdef" > "$PROJECT_DIR/server/.env"
157
+ echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
158
+ echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
159
+ elif [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
71
160
  if [ "$CI" = "true" ]; then
72
161
  echo "CI mode - using test API key"
73
162
  mkdir -p "$PROJECT_DIR/server"
@@ -76,12 +165,12 @@ if [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$P
76
165
  echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
77
166
  else
78
167
  echo "โš ๏ธ OpenAI API key required for SpecGen to work."
79
- echo "Enter your OpenAI API key: "
168
+ echo "Enter your OpenAI API key (or press Enter to use test key): "
80
169
  read -r OPENAI_KEY
81
170
 
82
171
  if [ -z "$OPENAI_KEY" ]; then
83
- echo "โŒ No API key provided. SpecGen needs an OpenAI API key to function."
84
- exit 1
172
+ OPENAI_KEY="sk-test1234567890abcdef"
173
+ echo "Using test API key for this deployment"
85
174
  fi
86
175
 
87
176
  mkdir -p "$PROJECT_DIR/server"
@@ -101,35 +190,80 @@ echo "๐Ÿ—๏ธ Building application components..."
101
190
  # Navigate to project directory
102
191
  cd "$PROJECT_DIR"
103
192
 
104
- # Install and build server
105
- if [ ! -d "server" ] || [ ! -d "server/node_modules" ]; then
193
+ # Install and build server with better extraction
194
+ if [ ! -f "server/index.js" ]; then
106
195
  echo "๐Ÿ“ฆ Setting up server..."
107
- npm pack @gv-sh/specgen-server
196
+
197
+ # Clean up any existing server directory
198
+ rm -rf server
199
+
200
+ # Download and extract server
201
+ echo " Downloading server package..."
202
+ npm pack @gv-sh/specgen-server --loglevel=warn
203
+
204
+ echo " Extracting server package..."
108
205
  tar -xzf gv-sh-specgen-server-*.tgz
109
- mv package server
206
+
207
+ # Move the extracted package to server directory
208
+ if [ -d "package" ]; then
209
+ mv package server
210
+ echo "โœ… Server extracted successfully"
211
+ else
212
+ echo "โŒ Failed to extract server package"
213
+ ls -la
214
+ exit 1
215
+ fi
216
+
217
+ # Clean up the tar file
110
218
  rm gv-sh-specgen-server-*.tgz
111
219
 
220
+ # Install server dependencies
221
+ echo " Installing server dependencies..."
112
222
  cd server
113
223
  echo "engine-strict=false" > .npmrc
114
224
  npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
225
+
226
+ # Verify server files
227
+ if [ ! -f "index.js" ]; then
228
+ echo "โŒ Server index.js not found after installation"
229
+ echo "Server directory contents:"
230
+ ls -la
231
+ exit 1
232
+ fi
233
+
115
234
  cd "$PROJECT_DIR"
116
235
  fi
117
236
 
118
237
  # Install and build admin
119
238
  if [ ! -d "admin/build" ]; then
120
239
  echo "๐Ÿ“ฑ Building admin interface..."
240
+
121
241
  if [ ! -d "admin" ]; then
122
- npm pack @gv-sh/specgen-admin
242
+ # Clean up any existing admin directory
243
+ rm -rf admin
244
+
245
+ echo " Downloading admin package..."
246
+ npm pack @gv-sh/specgen-admin --loglevel=warn
123
247
  tar -xzf gv-sh-specgen-admin-*.tgz
124
- mv package admin
248
+
249
+ if [ -d "package" ]; then
250
+ mv package admin
251
+ echo "โœ… Admin extracted successfully"
252
+ else
253
+ echo "โŒ Failed to extract admin package"
254
+ exit 1
255
+ fi
256
+
125
257
  rm gv-sh-specgen-admin-*.tgz
126
258
  fi
127
259
 
260
+ echo " Installing admin dependencies..."
128
261
  cd admin
129
262
  echo "engine-strict=false" > .npmrc
130
263
  # Install ALL dependencies for build process
131
264
  npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
132
- # Build with proper environment variables (no cross-env needed on Linux)
265
+ echo " Building admin interface..."
266
+ # Build with proper environment variables
133
267
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
134
268
  cd "$PROJECT_DIR"
135
269
  fi
@@ -137,18 +271,33 @@ fi
137
271
  # Install and build user
138
272
  if [ ! -d "user/build" ]; then
139
273
  echo "๐Ÿ‘ค Building user interface..."
274
+
140
275
  if [ ! -d "user" ]; then
141
- npm pack @gv-sh/specgen-user
276
+ # Clean up any existing user directory
277
+ rm -rf user
278
+
279
+ echo " Downloading user package..."
280
+ npm pack @gv-sh/specgen-user --loglevel=warn
142
281
  tar -xzf gv-sh-specgen-user-*.tgz
143
- mv package user
282
+
283
+ if [ -d "package" ]; then
284
+ mv package user
285
+ echo "โœ… User extracted successfully"
286
+ else
287
+ echo "โŒ Failed to extract user package"
288
+ exit 1
289
+ fi
290
+
144
291
  rm gv-sh-specgen-user-*.tgz
145
292
  fi
146
293
 
294
+ echo " Installing user dependencies..."
147
295
  cd user
148
296
  echo "engine-strict=false" > .npmrc
149
297
  # Install ALL dependencies for build process
150
298
  npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
151
- # Build with proper environment variables (no cross-env needed on Linux)
299
+ echo " Building user interface..."
300
+ # Build with proper environment variables
152
301
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
153
302
  cd "$PROJECT_DIR"
154
303
  fi
@@ -158,20 +307,25 @@ fi
158
307
  # ========================================
159
308
 
160
309
  echo "โœ… Verifying builds..."
310
+
311
+ # Check admin build
161
312
  if [ ! -d "$PROJECT_DIR/admin/build" ]; then
162
313
  echo "โŒ Admin build failed"
163
314
  ls -la "$PROJECT_DIR/admin/" || echo "Admin directory not found"
164
315
  exit 1
165
316
  fi
166
317
 
318
+ # Check user build
167
319
  if [ ! -d "$PROJECT_DIR/user/build" ]; then
168
320
  echo "โŒ User build failed"
169
321
  ls -la "$PROJECT_DIR/user/" || echo "User directory not found"
170
322
  exit 1
171
323
  fi
172
324
 
325
+ # Check server
173
326
  if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
174
327
  echo "โŒ Server index.js not found"
328
+ echo "Server directory contents:"
175
329
  ls -la "$PROJECT_DIR/server/" || echo "Server directory not found"
176
330
  exit 1
177
331
  fi
@@ -179,23 +333,106 @@ fi
179
333
  echo "๐Ÿ“ Build verification:"
180
334
  echo " Admin build: $(ls -la "$PROJECT_DIR/admin/build/" | wc -l) files"
181
335
  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"
336
+ echo " Server files: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
337
+ echo " โœ… Server script: $PROJECT_DIR/server/index.js"
184
338
 
185
339
  # 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
340
+ echo "๐Ÿ“„ Key files found:"
341
+ echo " Admin: $(ls "$PROJECT_DIR/admin/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
342
+ echo " User: $(ls "$PROJECT_DIR/user/build/" | grep -E '\.(html|js|css)$' | head -3 | tr '\n' ' ')"
343
+ echo " Server: $(ls "$PROJECT_DIR/server/" | grep -E '\.(js|json)$' | head -3 | tr '\n' ' ')"
190
344
 
191
345
  # ========================================
192
- # PM2 DEPLOYMENT
346
+ # DEPLOYMENT / TEST SERVER
193
347
  # ========================================
194
348
 
195
- echo "๐Ÿš€ Starting PM2 deployment..."
196
-
197
- # Create PM2 ecosystem configuration with absolute paths
198
- cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
349
+ if [ "$DRY_RUN" = true ]; then
350
+ echo ""
351
+ echo "๐Ÿงช DRY RUN: Testing server startup..."
352
+
353
+ # Test if the server can start
354
+ cd "$PROJECT_DIR"
355
+
356
+ # Copy environment
357
+ cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
358
+
359
+ # Check if port 8080 is available for testing
360
+ if ! check_port 8080; then
361
+ echo " โš ๏ธ Port 8080 is in use, testing on port 8081 instead"
362
+ TEST_PORT=8081
363
+ sed -i.bak 's/PORT=8080/PORT=8081/' "$PROJECT_DIR/server/.env"
364
+ else
365
+ TEST_PORT=8080
366
+ fi
367
+
368
+ echo " Starting test server on port $TEST_PORT for 10 seconds..."
369
+
370
+ # Start server in background
371
+ (cd server && NODE_ENV=production PORT=$TEST_PORT node index.js) &
372
+ SERVER_PID=$!
373
+
374
+ # Wait a bit for server to start
375
+ sleep 3
376
+
377
+ # Test the endpoints
378
+ echo " Testing endpoints on port $TEST_PORT:"
379
+
380
+ if curl -s http://localhost:$TEST_PORT/api/health >/dev/null 2>&1; then
381
+ echo " โœ… Health endpoint: OK"
382
+ HEALTH_RESPONSE=$(curl -s http://localhost:$TEST_PORT/api/health)
383
+ echo " Status: $(echo $HEALTH_RESPONSE | grep -o '"status":"[^"]*"' | cut -d'"' -f4)"
384
+ else
385
+ echo " โŒ Health endpoint: FAILED"
386
+ fi
387
+
388
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/ 2>/dev/null || echo "000")
389
+ echo " ๐Ÿ“„ Main page: HTTP $HTTP_CODE"
390
+
391
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/admin 2>/dev/null || echo "000")
392
+ echo " โš™๏ธ Admin page: HTTP $HTTP_CODE"
393
+
394
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$TEST_PORT/app 2>/dev/null || echo "000")
395
+ echo " ๐Ÿ‘ค User page: HTTP $HTTP_CODE"
396
+
397
+ # Stop test server
398
+ sleep 2
399
+ kill $SERVER_PID 2>/dev/null || true
400
+ wait $SERVER_PID 2>/dev/null || true
401
+
402
+ # Restore original .env if we changed it
403
+ if [ -f "$PROJECT_DIR/server/.env.bak" ]; then
404
+ mv "$PROJECT_DIR/server/.env.bak" "$PROJECT_DIR/server/.env"
405
+ fi
406
+
407
+ echo ""
408
+ echo "๐ŸŽ‰ DRY RUN COMPLETED!"
409
+ echo ""
410
+ echo "๐Ÿ“Š Summary:"
411
+ echo " โœ… All packages downloaded and extracted"
412
+ echo " โœ… All dependencies installed"
413
+ echo " โœ… React apps built successfully"
414
+ echo " โœ… Server can start and respond"
415
+ echo ""
416
+ if [ "$NODE_VERSION" -lt 20 ]; then
417
+ echo "โš ๏ธ Note for AWS deployment:"
418
+ echo " Your Mac has Node.js $(node --version)"
419
+ echo " AWS deployment requires Node.js 20+"
420
+ echo " Make sure your AWS server has the right version"
421
+ echo ""
422
+ fi
423
+ echo "๐Ÿš€ Ready for production deployment!"
424
+ echo " Deploy to AWS with: npx @gv-sh/specgen-app deploy"
425
+ echo ""
426
+ echo "๐Ÿ”ง To test locally right now:"
427
+ echo " cd server && npm start"
428
+ echo " Open http://localhost:8080/"
429
+
430
+ else
431
+ # Real deployment with PM2
432
+ echo "๐Ÿš€ Starting PM2 deployment..."
433
+
434
+ # Create PM2 ecosystem configuration with absolute paths
435
+ cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
199
436
  module.exports = {
200
437
  apps: [{
201
438
  name: 'specgen',
@@ -220,113 +457,72 @@ module.exports = {
220
457
  }]
221
458
  }
222
459
  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
460
 
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
461
+ # Create logs directory
462
+ mkdir -p "$PROJECT_DIR/logs"
272
463
 
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
464
+ # Copy .env to project root for PM2
465
+ cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
283
466
 
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"
467
+ # Final port check
468
+ if ! check_port 8080; then
469
+ echo "Port 8080 occupied, force cleaning..."
470
+ lsof -ti:8080 | xargs kill -9 2>/dev/null || true
471
+ sleep 2
290
472
  fi
291
473
 
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
474
+ # Start with PM2
475
+ cd "$PROJECT_DIR"
476
+ echo "โ–ถ๏ธ Starting SpecGen with PM2..."
299
477
 
300
- PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
478
+ NODE_ENV=production PORT=8080 $PM2_CMD start "$PROJECT_DIR/ecosystem.config.js"
301
479
 
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 ""
480
+ # Wait for startup and verify
481
+ sleep 5
322
482
 
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
483
+ # Verify deployment
484
+ echo "๐Ÿ” Verifying deployment..."
485
+
486
+ if $PM2_CMD list | grep -q "online"; then
487
+ echo "Testing endpoints:"
488
+
489
+ if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
490
+ echo "โœ… Health endpoint: OK"
491
+ else
492
+ echo "โŒ Health endpoint: FAILED"
493
+ fi
494
+
495
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
496
+ echo "๐Ÿ“„ Main page: HTTP $HTTP_CODE"
497
+
498
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null)
499
+ echo "โš™๏ธ Admin page: HTTP $HTTP_CODE"
500
+
501
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null)
502
+ echo "๐Ÿ‘ค User page: HTTP $HTTP_CODE"
503
+
504
+ PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
505
+
506
+ echo ""
507
+ echo "๐ŸŽ‰ SpecGen deployment completed!"
508
+ echo ""
509
+ echo "๐ŸŒ Access your application at:"
510
+ echo " - Main page: http://$PUBLIC_IP:8080/"
511
+ echo " - User app: http://$PUBLIC_IP:8080/app"
512
+ echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
513
+ echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
514
+ echo " - Health check: http://$PUBLIC_IP:8080/api/health"
515
+ echo ""
516
+ echo "๐Ÿ“Š Management commands:"
517
+ echo " $PM2_CMD status # Check status"
518
+ echo " $PM2_CMD logs specgen # View logs"
519
+ echo " $PM2_CMD restart specgen # Restart"
520
+
521
+ else
522
+ echo ""
523
+ echo "โŒ Deployment failed!"
524
+ echo "๐Ÿ“ Check logs: $PM2_CMD logs specgen"
525
+ echo "๐Ÿ“Š Check status: $PM2_CMD status"
526
+ exit 1
527
+ fi
332
528
  fi