@gv-sh/specgen-app 0.7.1 โ†’ 0.9.0

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.7.1-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.9.0-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 80 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.7.1",
3
+ "version": "0.9.0",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -11,14 +11,10 @@
11
11
  "dev": "chmod +x scripts/dev.sh && ./scripts/dev.sh",
12
12
  "build": "cd admin && npm run build && cd ../user && npm run build",
13
13
  "start": "cd server && npm start",
14
- "production": "chmod +x scripts/production.sh && ./scripts/production.sh",
15
14
  "deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
16
15
  "deploy:dry-run": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
17
16
  "test:deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
18
17
  "make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
19
- "deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
20
- "deploy:restart": "chmod +x scripts/restart.sh && ./scripts/restart.sh",
21
- "deploy:status": "chmod +x scripts/status.sh && ./scripts/status.sh",
22
18
  "postinstall": "chmod +x bin/cli.js"
23
19
  },
24
20
  "dependencies": {
package/scripts/deploy.sh CHANGED
@@ -37,15 +37,61 @@ PLATFORM=$(uname -s)
37
37
  if [ "$PLATFORM" = "Darwin" ]; then
38
38
  echo "๐ŸŽ Detected macOS"
39
39
  PM2_CMD="npx pm2"
40
- BIND_HOST="127.0.0.1" # macOS - bind to localhost for testing
40
+ DEFAULT_BIND_HOST="127.0.0.1" # macOS - default to localhost
41
41
  elif [ "$PLATFORM" = "Linux" ]; then
42
42
  echo "๐Ÿง Detected Linux"
43
43
  PM2_CMD="npx pm2"
44
- BIND_HOST="0.0.0.0" # Linux - bind to all interfaces for public access
44
+ DEFAULT_BIND_HOST="0.0.0.0" # Linux - default to public access
45
45
  else
46
46
  echo "โš ๏ธ Unknown platform: $PLATFORM"
47
47
  PM2_CMD="npx pm2"
48
- BIND_HOST="0.0.0.0"
48
+ DEFAULT_BIND_HOST="0.0.0.0"
49
+ fi
50
+
51
+ # Let user choose host binding unless in dry-run mode
52
+ if [ "$DRY_RUN" = true ]; then
53
+ BIND_HOST="$DEFAULT_BIND_HOST"
54
+ echo "๐Ÿงช DRY RUN: Using default host binding ($BIND_HOST)"
55
+ else
56
+ echo ""
57
+ echo "๐ŸŒ Choose server binding option:"
58
+ echo " 1) 0.0.0.0 - Public access (accessible from any IP)"
59
+ echo " 2) 127.0.0.1 - Local only (localhost access only)"
60
+ echo " 3) Custom IP address"
61
+ echo ""
62
+ echo "Default for $PLATFORM: $DEFAULT_BIND_HOST"
63
+ echo -n "Enter choice (1-3) or press Enter for default: "
64
+ read -r HOST_CHOICE
65
+
66
+ case "$HOST_CHOICE" in
67
+ 1)
68
+ BIND_HOST="0.0.0.0"
69
+ echo "โœ… Selected: Public access (0.0.0.0)"
70
+ ;;
71
+ 2)
72
+ BIND_HOST="127.0.0.1"
73
+ echo "โœ… Selected: Local only (127.0.0.1)"
74
+ ;;
75
+ 3)
76
+ echo -n "Enter custom IP address: "
77
+ read -r CUSTOM_HOST
78
+ if [ -n "$CUSTOM_HOST" ]; then
79
+ BIND_HOST="$CUSTOM_HOST"
80
+ echo "โœ… Selected: Custom host ($BIND_HOST)"
81
+ else
82
+ BIND_HOST="$DEFAULT_BIND_HOST"
83
+ echo "โœ… Using default: $BIND_HOST"
84
+ fi
85
+ ;;
86
+ "")
87
+ BIND_HOST="$DEFAULT_BIND_HOST"
88
+ echo "โœ… Using default: $BIND_HOST"
89
+ ;;
90
+ *)
91
+ echo "โš ๏ธ Invalid choice, using default: $DEFAULT_BIND_HOST"
92
+ BIND_HOST="$DEFAULT_BIND_HOST"
93
+ ;;
94
+ esac
49
95
  fi
50
96
 
51
97
  echo "๐ŸŒ Server will bind to: $BIND_HOST"
@@ -350,9 +396,9 @@ for component in admin user; do
350
396
  fi
351
397
  done
352
398
 
353
- npm install --no-save serve
399
+ # No need to install serve - using unified server only
354
400
 
355
- # ========================================
401
+ # ====================== ==================
356
402
  # VERIFY BUILDS
357
403
  # ========================================
358
404
 
@@ -404,8 +450,13 @@ else
404
450
  mkdir -p logs
405
451
  cp server/.env .env 2>/dev/null || true
406
452
 
407
- # Grant Node permission to bind to port 80
408
- sudo setcap 'cap_net_bind_service=+ep' "$(which node)"
453
+ # Grant Node permission to bind to port 80 (Linux only)
454
+ if [ "$PLATFORM" = "Linux" ]; then
455
+ echo "๐Ÿ” Granting Node.js permission to bind to port 80..."
456
+ sudo setcap 'cap_net_bind_service=+ep' "$(which node)" 2>/dev/null || {
457
+ echo "โš ๏ธ Could not set capabilities. You may need to run as root or use a port > 1024"
458
+ }
459
+ fi
409
460
 
410
461
  # Load environment variables from .env
411
462
  set -o allexport
@@ -433,24 +484,6 @@ module.exports = {
433
484
  log_file: '$PROJECT_DIR/logs/combined.log',
434
485
  time: true,
435
486
  watch: false
436
- },
437
- {
438
- name: 'specgen-admin',
439
- script: 'npx',
440
- args: 'serve -s admin/build -l 5001',
441
- cwd: '$PROJECT_DIR',
442
- env: {
443
- NODE_ENV: 'production'
444
- }
445
- },
446
- {
447
- name: 'specgen-user',
448
- script: 'npx',
449
- args: 'serve -s user/build -l 5002',
450
- cwd: '$PROJECT_DIR',
451
- env: {
452
- NODE_ENV: 'production'
453
- }
454
487
  }
455
488
  ]
456
489
  }
@@ -466,25 +499,60 @@ EOF
466
499
 
467
500
  NODE_ENV=production PORT=80 HOST=$BIND_HOST $PM2_CMD start ecosystem.config.js
468
501
 
469
- sleep 5
502
+ echo "โฑ๏ธ Waiting for server to start..."
503
+ sleep 8
504
+
505
+ # Verify the server is actually responding
506
+ echo "๐Ÿ” Verifying server health..."
507
+ HEALTH_CHECK=false
508
+ for i in {1..10}; do
509
+ if curl -s http://localhost:80/api/health >/dev/null 2>&1; then
510
+ HEALTH_CHECK=true
511
+ break
512
+ fi
513
+ echo " Attempt $i/10: Server not ready yet..."
514
+ sleep 2
515
+ done
470
516
 
471
- if $PM2_CMD list | grep -q "online"; then
517
+ if $PM2_CMD list | grep -q "online" && [ "$HEALTH_CHECK" = true ]; then
472
518
  PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || echo 'your-server')
473
519
 
474
520
  echo ""
475
521
  echo "๐ŸŽ‰ SpecGen deployment completed!"
476
522
  echo ""
477
523
  echo "๐ŸŒ Access your application at:"
478
- echo " - Main page: http://$PUBLIC_IP:80/"
479
- echo " - User app: http://$PUBLIC_IP:80/app/"
480
- echo " - Admin panel: http://$PUBLIC_IP:80/admin/"
524
+ if [ "$BIND_HOST" = "0.0.0.0" ]; then
525
+ echo " - Main page: http://$PUBLIC_IP/"
526
+ echo " - User app: http://$PUBLIC_IP/app"
527
+ echo " - Admin panel: http://$PUBLIC_IP/admin"
528
+ echo " - API docs: http://$PUBLIC_IP/api-docs"
529
+ echo " - Health check: http://$PUBLIC_IP/api/health"
530
+ else
531
+ echo " - Main page: http://localhost/"
532
+ echo " - User app: http://localhost/app"
533
+ echo " - Admin panel: http://localhost/admin"
534
+ echo " - API docs: http://localhost/api-docs"
535
+ echo " - Health check: http://localhost/api/health"
536
+ fi
481
537
  echo ""
482
- echo "๐Ÿ”ง Binding: Server is bound to $BIND_HOST (${BIND_HOST:+publicly accessible})"
538
+ echo "๐Ÿ”ง Binding: Server is bound to $BIND_HOST"
483
539
  echo "๐Ÿ“Š Management: npx pm2 status | npx pm2 logs specgen"
540
+ echo ""
541
+ echo "โœ… All services are running and responding!"
484
542
 
485
543
  else
544
+ echo ""
486
545
  echo "โŒ Deployment failed!"
487
- $PM2_CMD logs specgen --lines 10
546
+ echo "๐Ÿ” Process status:"
547
+ $PM2_CMD list
548
+ echo ""
549
+ echo "๐Ÿ“ Recent logs:"
550
+ $PM2_CMD logs specgen --lines 20
551
+ echo ""
552
+ echo "๐Ÿ”ง Debug commands:"
553
+ echo " npx pm2 logs specgen"
554
+ echo " npx pm2 restart specgen"
555
+ echo " curl http://localhost:80/api/health"
488
556
  exit 1
489
557
  fi
490
558
  fi
package/cleanup.sh DELETED
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Remove backup scripts
4
- echo "๐Ÿงน Removing backup script files..."
5
- rm -f scripts/*.backup
6
- echo "โœ… Cleanup complete!"
@@ -1,180 +0,0 @@
1
- #!/bin/bash
2
-
3
- # SpecGen Production Script - Low Memory, Port 80 with Cleanup
4
- set -e
5
-
6
- echo "๐Ÿš€ Starting SpecGen in production mode on port 80..."
7
- echo "๐Ÿงน Cleaning up existing processes..."
8
-
9
- # Function to check if port is available
10
- check_port() {
11
- local port=$1
12
- if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
13
- return 1 # Port in use
14
- else
15
- return 0 # Port available
16
- fi
17
- }
18
-
19
- # ========================================
20
- # CLEANUP EXISTING PROCESSES
21
- # ========================================
22
-
23
- # Stop and cleanup PM2 processes
24
- echo "Stopping existing PM2 processes..."
25
- npx pm2 stop all 2>/dev/null || true
26
- npx pm2 delete all 2>/dev/null || true
27
-
28
- # Kill processes on ports we'll use
29
- echo "Freeing ports..."
30
- for port in 80 3000 3001 3002; do
31
- if ! check_port $port; then
32
- echo "Port $port is in use. Attempting to free it..."
33
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
34
- sleep 1
35
- fi
36
- done
37
-
38
- # Stop nginx if it might interfere
39
- if command -v nginx &> /dev/null && systemctl is-active --quiet nginx 2>/dev/null; then
40
- echo "Nginx is running, checking for conflicts..."
41
- if nginx -T 2>/dev/null | grep -q ":80"; then
42
- echo "โš ๏ธ Nginx is configured to use port 80. You may need to reconfigure nginx."
43
- fi
44
- fi
45
-
46
- # ========================================
47
- # VERIFY SETUP
48
- # ========================================
49
-
50
- # Verify OpenAI API key
51
- if [ -f "server/.env" ]; then
52
- # In CI mode, skip API key validation
53
- if [ "$CI" = "true" ]; then
54
- echo "CI mode detected - skipping API key validation"
55
- elif grep -q "OPENAI_API_KEY=your_openai_api_key_here" server/.env; then
56
- echo "โš ๏ธ No OpenAI API key detected!"
57
- echo "Enter your OpenAI API key: "
58
- read -r OPENAI_KEY
59
-
60
- if [ -z "$OPENAI_KEY" ]; then
61
- echo "โŒ No API key provided. Cannot start in production mode."
62
- exit 1
63
- else
64
- # Update the API key in the .env file
65
- sed -i.bak "s/OPENAI_API_KEY=.*/OPENAI_API_KEY=$OPENAI_KEY/" server/.env
66
- rm -f server/.env.bak
67
- echo "โœ… API key updated in server/.env"
68
- fi
69
- fi
70
- else
71
- echo "โŒ server/.env file not found. Run 'npm run setup' first."
72
- exit 1
73
- fi
74
-
75
- # Verify directories exist
76
- for dir in server admin user; do
77
- if [ ! -d "$dir" ]; then
78
- echo "โŒ $dir directory not found. Run 'npm run setup' first."
79
- exit 1
80
- fi
81
- done
82
-
83
- # ========================================
84
- # INSTALL DEPENDENCIES
85
- # ========================================
86
-
87
- # Make sure node_modules exist in the server directory
88
- if [ ! -d "server/node_modules" ]; then
89
- echo "Installing server dependencies..."
90
- cd server
91
- # Create a .npmrc file that ignores engine requirements
92
- echo "engine-strict=false" > .npmrc
93
- npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
94
- cd ..
95
- fi
96
-
97
- # Set production environment
98
- export NODE_ENV=production
99
-
100
- # ========================================
101
- # BUILD INTERFACES
102
- # ========================================
103
-
104
- # Check if we need to build
105
- if [ ! -d "admin/build" ] || [ ! -d "user/build" ]; then
106
- echo "Building web interfaces (optimized mode)..."
107
-
108
- # Admin build
109
- if [ ! -d "admin/build" ]; then
110
- echo "Building admin..."
111
- cd admin
112
- echo "engine-strict=false" > .npmrc
113
- # Install only production dependencies
114
- npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
115
- # Set environment for smaller build
116
- export GENERATE_SOURCEMAP=false
117
- export SKIP_PREFLIGHT_CHECK=true
118
- npm run build
119
- cd ..
120
- fi
121
-
122
- # User build
123
- if [ ! -d "user/build" ]; then
124
- echo "Building user..."
125
- cd user
126
- echo "engine-strict=false" > .npmrc
127
- # Install only production dependencies
128
- npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
129
- # Set environment for smaller build
130
- export GENERATE_SOURCEMAP=false
131
- export SKIP_PREFLIGHT_CHECK=true
132
- npm run build
133
- cd ..
134
- fi
135
- fi
136
-
137
- # ========================================
138
- # CONFIGURE ENVIRONMENT
139
- # ========================================
140
-
141
- # Update server .env to use port 80
142
- if [ -f "server/.env" ]; then
143
- # Update or add PORT=80 to .env
144
- if grep -q "^PORT=" server/.env; then
145
- sed -i.bak "s/^PORT=.*/PORT=80/" server/.env
146
- else
147
- echo "PORT=80" >> server/.env
148
- fi
149
- rm -f server/.env.bak
150
- fi
151
-
152
- # Create production-ready .env for server
153
- cat > server/.env.production << EOF
154
- $(cat server/.env)
155
- NODE_ENV=production
156
- PORT=80
157
- EOF
158
-
159
- # Create logs directory
160
- mkdir -p logs
161
-
162
- # ========================================
163
- # START SERVER
164
- # ========================================
165
-
166
- # Final port check
167
- echo "Final check for port 80..."
168
- if ! check_port 80; then
169
- echo "Port 80 is still in use after cleanup. Force killing..."
170
- lsof -ti:80 | xargs kill -9 2>/dev/null || true
171
- sleep 2
172
- fi
173
-
174
- # Start production server
175
- echo "Starting production server on port 80..."
176
- if [ "$CI" = "true" ]; then
177
- echo "CI mode detected - skipping server start"
178
- else
179
- cd server && NODE_ENV=production PORT=80 npm start
180
- fi
@@ -1,19 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Restart SpecGen services
4
- set -e
5
-
6
- echo "Restarting SpecGen services..."
7
-
8
- # Restart PM2 processes
9
- pm2 restart specgen-server || echo "Starting server..."
10
- pm2 start ecosystem.config.js || echo "Server started"
11
-
12
- # Restart Nginx
13
- sudo systemctl restart nginx
14
-
15
- # Show status
16
- pm2 status
17
- sudo systemctl status nginx --no-pager -l
18
-
19
- echo "SpecGen restarted successfully"
package/scripts/status.sh DELETED
@@ -1,30 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Show SpecGen application status
4
- set -e
5
-
6
- echo "=== SpecGen Application Status ==="
7
-
8
- # PM2 processes
9
- echo -e "\nPM2 Processes:"
10
- pm2 list
11
-
12
- # Nginx status
13
- echo -e "\nNginx Status:"
14
- sudo systemctl status nginx --no-pager -l
15
-
16
- # Server logs (last 20 lines)
17
- echo -e "\nServer Logs (last 20 lines):"
18
- pm2 logs specgen-server --lines 20
19
-
20
- # Disk usage of app directory
21
- echo -e "\nDisk Usage:"
22
- du -sh /opt/specgen-app
23
-
24
- # Memory usage
25
- echo -e "\nMemory Usage:"
26
- free -h
27
-
28
- # Port status
29
- echo -e "\nPort Status:"
30
- sudo netstat -tlpn | grep -E ':80|:3000|:443'
package/scripts/stop.sh DELETED
@@ -1,14 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Stop SpecGen services
4
- set -e
5
-
6
- echo "Stopping SpecGen services..."
7
-
8
- # Stop PM2 processes
9
- pm2 stop specgen-server || echo "Server not running"
10
-
11
- # Stop Nginx (optional - uncomment if needed)
12
- # sudo systemctl stop nginx
13
-
14
- echo "SpecGen stopped successfully"