@gv-sh/specgen-app 0.6.2 โ†’ 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.2-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.2",
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
@@ -16,31 +25,56 @@ check_port() {
16
25
  fi
17
26
  }
18
27
 
28
+ # Get absolute path of current working directory
29
+ PROJECT_DIR=$(pwd)
30
+ echo "๐Ÿ“‚ Project directory: $PROJECT_DIR"
31
+
19
32
  # ========================================
20
- # FULL CLEANUP
33
+ # PLATFORM-SPECIFIC SETUP
21
34
  # ========================================
22
35
 
23
- echo "๐Ÿงน Cleaning up existing installations..."
24
-
25
- # Stop and remove all PM2 processes
26
- npx pm2 stop all 2>/dev/null || true
27
- npx pm2 delete all 2>/dev/null || true
28
- npx pm2 kill 2>/dev/null || true
29
-
30
- # Remove old PM2 config files
31
- 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
32
48
 
33
- # Kill processes on all relevant ports
34
- for port in 8080 3000 3001 3002; do
35
- if ! check_port $port; then
36
- echo "Killing processes on port $port..."
37
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
38
- sleep 1
39
- fi
40
- done
49
+ # ========================================
50
+ # CLEANUP (Skip in dry-run for safety)
51
+ # ========================================
41
52
 
42
- # Clean up old files
43
- 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
44
78
 
45
79
  # ========================================
46
80
  # VERIFY PREREQUISITES
@@ -52,18 +86,32 @@ echo "๐Ÿ” Checking prerequisites..."
52
86
  NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
53
87
  if [ "$NODE_VERSION" -lt 20 ]; then
54
88
  echo "โŒ Node.js 20+ required. Current version: $(node --version)"
55
- 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
56
94
  exit 1
95
+ else
96
+ echo "โœ… Node.js version: $(node --version)"
57
97
  fi
58
98
 
59
- # Check if we have the required directories and files
60
- echo "๐Ÿ“‚ Checking project structure..."
61
- if [ ! -f "package.json" ]; then
62
- echo "โŒ package.json not found. This script must be run from the SpecGen project directory."
63
- echo "๐Ÿ’ก Create a directory and run this script from there:"
64
- echo " mkdir specgen && cd specgen"
65
- echo " npx @gv-sh/specgen-app deploy"
66
- exit 1
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
67
115
  fi
68
116
 
69
117
  # ========================================
@@ -72,28 +120,34 @@ fi
72
120
 
73
121
  echo "๐Ÿ”‘ Setting up OpenAI API key..."
74
122
 
75
- # Check if .env exists and has API key
76
- if [ ! -f "server/.env" ] || grep -q "your_openai_api_key_here" 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
77
131
  if [ "$CI" = "true" ]; then
78
132
  echo "CI mode - using test API key"
79
- mkdir -p server
80
- echo "OPENAI_API_KEY=sk-test1234" > server/.env
81
- echo "NODE_ENV=production" >> server/.env
82
- echo "PORT=8080" >> server/.env
133
+ mkdir -p "$PROJECT_DIR/server"
134
+ echo "OPENAI_API_KEY=sk-test1234" > "$PROJECT_DIR/server/.env"
135
+ echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
136
+ echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
83
137
  else
84
138
  echo "โš ๏ธ OpenAI API key required for SpecGen to work."
85
- echo "Enter your OpenAI API key: "
139
+ echo "Enter your OpenAI API key (or press Enter to use test key for dry-run): "
86
140
  read -r OPENAI_KEY
87
141
 
88
142
  if [ -z "$OPENAI_KEY" ]; then
89
- echo "โŒ No API key provided. SpecGen needs an OpenAI API key to function."
90
- exit 1
143
+ OPENAI_KEY="sk-test1234567890abcdef"
144
+ echo "Using test API key for this deployment"
91
145
  fi
92
146
 
93
- mkdir -p server
94
- echo "OPENAI_API_KEY=$OPENAI_KEY" > server/.env
95
- echo "NODE_ENV=production" >> server/.env
96
- echo "PORT=8080" >> server/.env
147
+ mkdir -p "$PROJECT_DIR/server"
148
+ echo "OPENAI_API_KEY=$OPENAI_KEY" > "$PROJECT_DIR/server/.env"
149
+ echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
150
+ echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
97
151
  echo "โœ… API key saved"
98
152
  fi
99
153
  fi
@@ -104,56 +158,119 @@ fi
104
158
 
105
159
  echo "๐Ÿ—๏ธ Building application components..."
106
160
 
107
- # Install and build server
108
- if [ ! -d "server" ] || [ ! -d "server/node_modules" ]; then
161
+ # Navigate to project directory
162
+ cd "$PROJECT_DIR"
163
+
164
+ # Install and build server with better extraction
165
+ if [ ! -f "server/index.js" ]; then
109
166
  echo "๐Ÿ“ฆ Setting up server..."
110
- 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..."
111
176
  tar -xzf gv-sh-specgen-server-*.tgz
112
- 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
113
189
  rm gv-sh-specgen-server-*.tgz
114
190
 
191
+ # Install server dependencies
192
+ echo " Installing server dependencies..."
115
193
  cd server
116
194
  echo "engine-strict=false" > .npmrc
117
195
  npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
118
- cd ..
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
+
205
+ cd "$PROJECT_DIR"
119
206
  fi
120
207
 
121
208
  # Install and build admin
122
209
  if [ ! -d "admin/build" ]; then
123
210
  echo "๐Ÿ“ฑ Building admin interface..."
211
+
124
212
  if [ ! -d "admin" ]; then
125
- 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
126
218
  tar -xzf gv-sh-specgen-admin-*.tgz
127
- 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
+
128
228
  rm gv-sh-specgen-admin-*.tgz
129
229
  fi
130
230
 
231
+ echo " Installing admin dependencies..."
131
232
  cd admin
132
233
  echo "engine-strict=false" > .npmrc
133
234
  # Install ALL dependencies for build process
134
235
  npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
135
- # Build with proper environment variables (no cross-env needed on Linux)
236
+ echo " Building admin interface..."
237
+ # Build with proper environment variables
136
238
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
137
- cd ..
239
+ cd "$PROJECT_DIR"
138
240
  fi
139
241
 
140
242
  # Install and build user
141
243
  if [ ! -d "user/build" ]; then
142
244
  echo "๐Ÿ‘ค Building user interface..."
245
+
143
246
  if [ ! -d "user" ]; then
144
- 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
145
252
  tar -xzf gv-sh-specgen-user-*.tgz
146
- 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
+
147
262
  rm gv-sh-specgen-user-*.tgz
148
263
  fi
149
264
 
265
+ echo " Installing user dependencies..."
150
266
  cd user
151
267
  echo "engine-strict=false" > .npmrc
152
268
  # Install ALL dependencies for build process
153
269
  npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
154
- # Build with proper environment variables (no cross-env needed on Linux)
270
+ echo " Building user interface..."
271
+ # Build with proper environment variables
155
272
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
156
- cd ..
273
+ cd "$PROJECT_DIR"
157
274
  fi
158
275
 
159
276
  # ========================================
@@ -161,42 +278,115 @@ fi
161
278
  # ========================================
162
279
 
163
280
  echo "โœ… Verifying builds..."
164
- if [ ! -d "admin/build" ]; then
281
+
282
+ # Check admin build
283
+ if [ ! -d "$PROJECT_DIR/admin/build" ]; then
165
284
  echo "โŒ Admin build failed"
166
- ls -la admin/ || echo "Admin directory not found"
285
+ ls -la "$PROJECT_DIR/admin/" || echo "Admin directory not found"
167
286
  exit 1
168
287
  fi
169
288
 
170
- if [ ! -d "user/build" ]; then
289
+ # Check user build
290
+ if [ ! -d "$PROJECT_DIR/user/build" ]; then
171
291
  echo "โŒ User build failed"
172
- ls -la user/ || echo "User directory not found"
292
+ ls -la "$PROJECT_DIR/user/" || echo "User directory not found"
293
+ exit 1
294
+ fi
295
+
296
+ # Check server
297
+ if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
298
+ echo "โŒ Server index.js not found"
299
+ echo "Server directory contents:"
300
+ ls -la "$PROJECT_DIR/server/" || echo "Server directory not found"
173
301
  exit 1
174
302
  fi
175
303
 
176
304
  echo "๐Ÿ“ Build verification:"
177
- echo " Admin build: $(ls -la admin/build/ | wc -l) files"
178
- echo " User build: $(ls -la user/build/ | wc -l) files"
179
- echo " Server: $(ls -la server/ | wc -l) files"
305
+ echo " Admin build: $(ls -la "$PROJECT_DIR/admin/build/" | wc -l) files"
306
+ echo " User build: $(ls -la "$PROJECT_DIR/user/build/" | wc -l) files"
307
+ echo " Server files: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
308
+ echo " โœ… Server script: $PROJECT_DIR/server/index.js"
180
309
 
181
310
  # Show some sample files to verify builds
182
- echo "๐Ÿ“„ Admin build files:"
183
- ls admin/build/ | head -5
184
- echo "๐Ÿ“„ User build files:"
185
- ls 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' ' ')"
186
315
 
187
316
  # ========================================
188
- # PM2 DEPLOYMENT
317
+ # DEPLOYMENT / TEST SERVER
189
318
  # ========================================
190
319
 
191
- echo "๐Ÿš€ Starting PM2 deployment..."
192
-
193
- # Create PM2 ecosystem configuration
194
- cat > 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
195
385
  module.exports = {
196
386
  apps: [{
197
387
  name: 'specgen',
198
- script: './server/index.js',
199
- cwd: process.cwd(),
388
+ script: '$PROJECT_DIR/server/index.js',
389
+ cwd: '$PROJECT_DIR',
200
390
  env: {
201
391
  NODE_ENV: 'production',
202
392
  PORT: 8080
@@ -204,9 +394,9 @@ module.exports = {
204
394
  instances: 1,
205
395
  exec_mode: 'fork',
206
396
  max_memory_restart: '500M',
207
- error_file: './logs/err.log',
208
- out_file: './logs/out.log',
209
- log_file: './logs/combined.log',
397
+ error_file: '$PROJECT_DIR/logs/err.log',
398
+ out_file: '$PROJECT_DIR/logs/out.log',
399
+ log_file: '$PROJECT_DIR/logs/combined.log',
210
400
  time: true,
211
401
  watch: false,
212
402
  ignore_watch: ['node_modules', 'logs', '*.log'],
@@ -216,98 +406,72 @@ module.exports = {
216
406
  }]
217
407
  }
218
408
  EOF
219
-
220
- # Create logs directory
221
- mkdir -p logs
222
-
223
- # Copy .env to ensure PM2 picks it up
224
- cp server/.env .env 2>/dev/null || true
225
-
226
- # Final port check
227
- if ! check_port 8080; then
228
- echo "Port 8080 occupied, force cleaning..."
229
- lsof -ti:8080 | xargs kill -9 2>/dev/null || true
230
- sleep 2
231
- fi
232
-
233
- # Start with PM2
234
- echo "โ–ถ๏ธ Starting SpecGen with PM2..."
235
- NODE_ENV=production PORT=8080 npx pm2 start ecosystem.config.js
236
-
237
- # Wait for startup and verify
238
- sleep 5
239
-
240
- # ========================================
241
- # DEPLOYMENT VERIFICATION
242
- # ========================================
243
-
244
- echo "๐Ÿ” Verifying deployment..."
245
-
246
- if npx pm2 list | grep -q "online"; then
247
- # Test endpoints
248
- echo "Testing endpoints:"
249
409
 
250
- # Test health endpoint
251
- if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
252
- echo "โœ… Health endpoint: OK"
253
- else
254
- echo "โŒ Health endpoint: FAILED"
255
- fi
410
+ # Create logs directory
411
+ mkdir -p "$PROJECT_DIR/logs"
256
412
 
257
- # Test main page
258
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
259
- if [ "$HTTP_CODE" = "200" ]; then
260
- echo "โœ… Main page: OK (HTTP $HTTP_CODE)"
261
- else
262
- echo "โš ๏ธ Main page: HTTP $HTTP_CODE (check if builds are served correctly)"
263
- fi
413
+ # Copy .env to project root for PM2
414
+ cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
264
415
 
265
- # Test admin
266
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null)
267
- if [ "$HTTP_CODE" = "200" ]; then
268
- echo "โœ… Admin page: OK (HTTP $HTTP_CODE)"
269
- else
270
- 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
271
421
  fi
272
422
 
273
- # Test user app
274
- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null)
275
- if [ "$HTTP_CODE" = "200" ]; then
276
- echo "โœ… User app: OK (HTTP $HTTP_CODE)"
277
- else
278
- echo "โš ๏ธ User app: HTTP $HTTP_CODE"
279
- fi
423
+ # Start with PM2
424
+ cd "$PROJECT_DIR"
425
+ echo "โ–ถ๏ธ Starting SpecGen with PM2..."
280
426
 
281
- 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"
282
428
 
283
- echo ""
284
- echo "๐ŸŽ‰ SpecGen deployment completed!"
285
- echo ""
286
- echo "๐ŸŒ Access your application at:"
287
- echo " - Main page: http://$PUBLIC_IP:8080/"
288
- echo " - User app: http://$PUBLIC_IP:8080/app"
289
- echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
290
- echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
291
- echo " - Health check: http://$PUBLIC_IP:8080/api/health"
292
- echo ""
293
- echo "๐Ÿ“Š Management:"
294
- echo " npx pm2 status # Check status"
295
- echo " npx pm2 logs specgen # View logs"
296
- echo " npx pm2 restart specgen # Restart"
297
- echo ""
298
- echo "๐Ÿ”ง Troubleshooting:"
299
- echo " curl http://localhost:8080/api/health # Test API"
300
- echo " curl -I http://localhost:8080/ # Test main page"
301
- echo " ls -la */build/ # Check builds"
302
- echo ""
429
+ # Wait for startup and verify
430
+ sleep 5
303
431
 
304
- else
305
- echo ""
306
- echo "โŒ Deployment failed!"
307
- echo "๐Ÿ“ Check logs: npx pm2 logs specgen"
308
- echo "๐Ÿ“Š Check status: npx pm2 status"
309
- echo ""
310
- echo "Recent logs:"
311
- npx pm2 logs specgen --lines 10
312
- 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
313
477
  fi