@gv-sh/specgen-app 0.5.1 → 0.6.2

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.
Files changed (3) hide show
  1. package/README.md +236 -179
  2. package/package.json +2 -2
  3. package/scripts/deploy.sh +197 -64
package/README.md CHANGED
@@ -1,263 +1,320 @@
1
1
  # SpecGen App - Complete Platform
2
2
 
3
- [![Version](https://img.shields.io/badge/version-0.5.1-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.6.2-blue.svg)](https://github.com/gv-sh/specgen-app)
4
4
 
5
- A unified deployment package for the SpecGen speculative fiction generator platform. **Now optimized for low-memory servers and unified on port 8080!**
5
+ A unified deployment package for the SpecGen speculative fiction generator platform. **Optimized for port 8080 deployment with low memory usage.**
6
6
 
7
- ## 🚀 What's New
7
+ ## 🚀 Quick Start
8
8
 
9
- - **Single Port Deployment**: Everything runs on port 8080 with clean URL paths
10
- - **Low Memory Default**: Optimized for small servers and EC2 instances
11
- - **Automatic Cleanup**: Smart setup that cleans existing installations
12
- - **Unified Interface**: All services accessible through one port
9
+ ### One-Command Deployment (Recommended)
13
10
 
14
- ## Components
11
+ ```bash
12
+ # Create project directory
13
+ mkdir specgen && cd specgen
15
14
 
16
- - **Server**: Node.js API with OpenAI integration (Port 8080)
17
- - **Admin**: React admin interface at `/admin`
18
- - **User**: React user interface at `/app` (also default at `/`)
15
+ # Deploy everything in one command
16
+ npx @gv-sh/specgen-app deploy
17
+ ```
19
18
 
20
- ## Quick Start
19
+ **What this does:**
20
+ - Downloads and sets up server, admin, and user components
21
+ - Builds React frontends optimized for production
22
+ - Configures everything for port 8080
23
+ - Starts with PM2 for process management
24
+ - Prompts for OpenAI API key
21
25
 
22
- ### Using NPX (Recommended)
26
+ ## 🌐 Access URLs
23
27
 
24
- ```bash
25
- # Create and enter your project directory
26
- mkdir specgen-project
27
- cd specgen-project
28
+ Once deployed, access your application at:
28
29
 
29
- # Run setup (automatically includes low-memory optimizations and cleanup)
30
- npx @gv-sh/specgen-app setup
30
+ - **Main Application**: http://your-server:8080/
31
+ - **User Interface**: http://your-server:8080/app
32
+ - **Admin Panel**: http://your-server:8080/admin
33
+ - **API Documentation**: http://your-server:8080/api-docs
34
+ - **Health Check**: http://your-server:8080/api/health
35
+ - **API Endpoints**: http://your-server:8080/api/*
31
36
 
32
- # Start in development mode (traditional separate ports)
33
- npx @gv-sh/specgen-app dev
37
+ ## 🖥️ Server Requirements
34
38
 
35
- # Or start in production mode (unified port 8080)
36
- npx @gv-sh/specgen-app production
39
+ ### Minimum Requirements
40
+ - **Node.js**: 20.0.0 or higher
41
+ - **RAM**: 1GB minimum (2GB recommended)
42
+ - **Storage**: 2GB free space
43
+ - **OS**: Ubuntu 20.04+ (or similar Linux distribution)
37
44
 
38
- # Or deploy with PM2 (recommended for servers)
39
- npx @gv-sh/specgen-app deploy
40
- ```
45
+ ### Quick Server Setup (Ubuntu)
41
46
 
42
- ## 🌐 Access URLs
47
+ ```bash
48
+ # Install Node.js 20+
49
+ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
50
+ sudo apt-get install -y nodejs
43
51
 
44
- ### Production Mode (Port 8080 - Unified)
45
- - **Main Application**: http://localhost:8080/
46
- - **User Interface**: http://localhost:8080/app
47
- - **Admin Panel**: http://localhost:8080/admin
48
- - **API Documentation**: http://localhost:8080/api-docs
49
- - **Health Check**: http://localhost:8080/api/health
50
- - **API Endpoints**: http://localhost:8080/api/*
52
+ # Verify installation
53
+ node --version # Should show v20.x.x or higher
54
+ npm --version
55
+ ```
51
56
 
52
- ### Development Mode (Separate Ports)
53
- - **User Interface**: http://localhost:3002
54
- - **Admin Interface**: http://localhost:3001
55
- - **API Server**: http://localhost:8080
57
+ ## 📋 Deployment Methods
56
58
 
57
- ## 🖥️ Server Deployment
59
+ ### Method 1: Direct NPX Deployment (Easiest)
58
60
 
59
- ### Option 1: Quick AWS/VPS Deployment
61
+ ```bash
62
+ # SSH into your server
63
+ ssh -i "your-key.pem" ubuntu@your-server-ip
64
+
65
+ # Create project and deploy
66
+ mkdir specgen && cd specgen
67
+ npx @gv-sh/specgen-app deploy
68
+ ```
60
69
 
61
- Perfect for EC2, DigitalOcean, or any Ubuntu server:
70
+ ### Method 2: Development Mode
62
71
 
63
- 1. **SSH into your server**:
64
- ```bash
65
- ssh -i "key.pem" ubuntu@your-server-ip
66
- ```
72
+ For local development with separate ports:
67
73
 
68
- 2. **Install Node.js 20+** (required):
69
- ```bash
70
- curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
71
- sudo apt-get install -y nodejs
72
- ```
74
+ ```bash
75
+ mkdir specgen-dev && cd specgen-dev
76
+ npx @gv-sh/specgen-app setup
77
+ npx @gv-sh/specgen-app dev
78
+ ```
73
79
 
74
- 3. **Deploy SpecGen** (one command setup with cleanup):
75
- ```bash
76
- mkdir specgen && cd specgen
77
- npx @gv-sh/specgen-app setup
78
- npx @gv-sh/specgen-app deploy
79
- ```
80
+ **Development URLs:**
81
+ - User Interface: http://localhost:3002
82
+ - Admin Interface: http://localhost:3001
83
+ - API Server: http://localhost:8080
80
84
 
81
- 4. **Access your application**:
82
- - **Main**: http://your-server-ip:8080/
83
- - **User App**: http://your-server-ip:8080/app
84
- - **Admin Panel**: http://your-server-ip:8080/admin
85
+ ### Method 3: Manual Deployment
85
86
 
86
- ### Option 2: Manual Setup
87
+ If you prefer more control:
87
88
 
88
89
  ```bash
89
- # Clone and setup manually
90
+ # Clone repository
90
91
  git clone https://github.com/gv-sh/specgen-app.git
91
92
  cd specgen-app
93
+
94
+ # Setup and deploy
92
95
  npm run setup
93
96
  npm run deploy
94
97
  ```
95
98
 
96
- ## 🛠️ Setup Features
97
-
98
- The setup script now includes **comprehensive cleanup**:
99
+ ## 🔧 Configuration
99
100
 
100
- - **PM2 Process Cleanup**: Stops and removes existing PM2 processes
101
- - ✅ **Port Liberation**: Frees up ports 8080, 3000, 3001, 3002
102
- - ✅ **Nginx Cleanup**: Removes conflicting nginx configurations
103
- - ✅ **Docker Cleanup**: Removes any existing SpecGen containers
104
- - ✅ **Service Cleanup**: Removes systemd services
105
- - ✅ **File Cleanup**: Removes old installations and log files
106
- - ✅ **Low Memory Optimization**: Optimized for servers with limited RAM
101
+ ### OpenAI API Key Setup
107
102
 
108
- ## 📋 Available Commands
103
+ During deployment, you'll be prompted for your OpenAI API key. You can also set it manually:
109
104
 
110
- ### Core Commands
111
105
  ```bash
112
- # Setup with cleanup (one-time)
113
- npx @gv-sh/specgen-app setup
106
+ # Create/edit the environment file
107
+ echo "OPENAI_API_KEY=your_openai_api_key_here" > server/.env
108
+ echo "NODE_ENV=production" >> server/.env
109
+ echo "PORT=8080" >> server/.env
114
110
 
115
- # Development mode (separate ports)
116
- npx @gv-sh/specgen-app dev
111
+ # Restart the service
112
+ npx pm2 restart specgen --update-env
113
+ ```
117
114
 
118
- # Production mode (direct run on port 8080)
119
- npx @gv-sh/specgen-app production
115
+ ### Environment Variables
120
116
 
121
- # Production deployment with PM2 (recommended)
122
- npx @gv-sh/specgen-app deploy
123
- ```
117
+ The deployment creates these configuration files:
118
+ - `server/.env` - Server configuration (port 8080, API key)
119
+ - `admin/.env.development` - Admin development settings
120
+ - `user/.env.development` - User development settings
121
+
122
+ ## 📊 Process Management
123
+
124
+ The deployment uses PM2 for process management:
124
125
 
125
- ### Management Commands
126
126
  ```bash
127
- # Check deployment status
128
- npx @gv-sh/specgen-app deploy:status
127
+ # Check status
128
+ npx pm2 status
129
129
 
130
- # Stop all services
131
- npx @gv-sh/specgen-app deploy:stop
130
+ # View logs
131
+ npx pm2 logs specgen
132
+
133
+ # Restart application
134
+ npx pm2 restart specgen
132
135
 
133
- # Restart services
134
- npx @gv-sh/specgen-app deploy:restart
136
+ # Stop application
137
+ npx pm2 stop specgen
138
+
139
+ # Monitor resources
140
+ npx pm2 monit
135
141
  ```
136
142
 
137
- ### Using NPM Scripts (if you cloned the repo)
143
+ ## 🔍 Troubleshooting
144
+
145
+ ### Common Issues and Solutions
146
+
147
+ #### 1. Port 8080 Already in Use
138
148
  ```bash
139
- npm run setup # Setup with cleanup
140
- npm run dev # Development mode
141
- npm run production # Production mode
142
- npm run deploy # Deploy with PM2
149
+ # Check what's using the port
150
+ sudo lsof -i :8080
151
+
152
+ # Kill the process
153
+ sudo lsof -ti:8080 | xargs kill -9
154
+
155
+ # Redeploy
156
+ npx @gv-sh/specgen-app deploy
143
157
  ```
144
158
 
145
- ## 🔧 Configuration
159
+ #### 2. Frontend Not Loading (404 Errors)
160
+ ```bash
161
+ # Check if builds exist
162
+ ls -la admin/build/
163
+ ls -la user/build/
146
164
 
147
- ### OpenAI API Key
148
- You'll be prompted for your OpenAI API key during setup. If you skip it, add it later to `server/.env`:
165
+ # If missing, manually rebuild
166
+ cd admin && npm install && GENERATE_SOURCEMAP=false PUBLIC_URL=/admin npm run build
167
+ cd ../user && npm install && GENERATE_SOURCEMAP=false REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
149
168
 
150
- ```env
151
- OPENAI_API_KEY=your_openai_api_key_here
152
- NODE_ENV=production
153
- PORT=8080
169
+ # Restart server
170
+ npx pm2 restart specgen
154
171
  ```
155
172
 
156
- ### Environment Files
157
- The setup automatically creates optimized environment files:
158
- - `server/.env` - Server configuration (port 8080)
159
- - `admin/.env.development` - Admin dev settings
160
- - `user/.env.development` - User dev settings
173
+ #### 3. OpenAI API Key Issues
174
+ ```bash
175
+ # Check current environment
176
+ npx pm2 env 0
161
177
 
162
- ## 🐳 Docker Alternative
178
+ # Update API key
179
+ echo "OPENAI_API_KEY=your_new_key_here" > server/.env
180
+ echo "NODE_ENV=production" >> server/.env
181
+ echo "PORT=8080" >> server/.env
163
182
 
164
- If you prefer Docker:
183
+ # Restart with new environment
184
+ npx pm2 restart specgen --update-env
185
+ ```
165
186
 
187
+ #### 4. Out of Memory Errors
166
188
  ```bash
167
- # Quick Docker setup
168
- docker run -d \
169
- --name specgen \
170
- -p 8080:8080 \
171
- -e OPENAI_API_KEY=your_key_here \
172
- gvsh/specgen-app:latest
189
+ # Add swap space (2GB recommended)
190
+ sudo fallocate -l 2G /swapfile
191
+ sudo chmod 600 /swapfile
192
+ sudo mkswap /swapfile
193
+ sudo swapon /swapfile
194
+ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
195
+
196
+ # Verify swap is active
197
+ free -h
173
198
  ```
174
199
 
175
- ## 📊 Management with PM2
200
+ #### 5. Node.js Version Issues
201
+ ```bash
202
+ # Check current version
203
+ node --version
204
+
205
+ # If less than v20, update:
206
+ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
207
+ sudo apt-get install -y nodejs
208
+ ```
176
209
 
177
- When deployed with `npm run deploy`, you get PM2 process management:
210
+ ### Debugging Commands
178
211
 
179
212
  ```bash
180
- # Check status
181
- npx pm2 status
213
+ # Test API health
214
+ curl http://localhost:8080/api/health
182
215
 
183
- # View logs
184
- npx pm2 logs specgen
216
+ # Test main page response
217
+ curl -I http://localhost:8080/
185
218
 
186
- # Restart
187
- npx pm2 restart specgen
219
+ # Check server logs
220
+ npx pm2 logs specgen --lines 50
188
221
 
189
- # Stop
190
- npx pm2 stop specgen
222
+ # Check build status
223
+ ls -la */build/ 2>/dev/null || echo "No builds found"
191
224
 
192
- # Monitor
193
- npx pm2 monit
225
+ # Check processes listening on port 8080
226
+ sudo netstat -tlnp | grep :8080
194
227
  ```
195
228
 
196
- ## 🔍 Troubleshooting
229
+ ### Manual Build Process
230
+
231
+ If automatic builds fail, try manual building:
197
232
 
198
- ### Common Issues
199
-
200
- 1. **Port 8080 Already in Use**:
201
- ```bash
202
- # The setup script handles this automatically, but if needed:
203
- sudo lsof -ti:8080 | xargs kill -9
204
- ```
205
-
206
- 2. **Out of Memory on Small Servers**:
207
- ```bash
208
- # Add swap space (setup script suggests this)
209
- sudo fallocate -l 2G /swapfile
210
- sudo chmod 600 /swapfile
211
- sudo mkswap /swapfile
212
- sudo swapon /swapfile
213
- ```
214
-
215
- 3. **Node.js Version Issues**:
216
- ```bash
217
- # Ensure Node.js 20+ is installed
218
- node --version # Should be v20+
219
- ```
220
-
221
- 4. **SQLite3 Binding Errors**:
222
- ```bash
223
- # The setup script includes engine-strict=false
224
- # If issues persist, run setup again - it includes full cleanup
225
- npx @gv-sh/specgen-app setup
226
- ```
227
-
228
- ### Health Check
229
- Test if your deployment is working:
230
233
  ```bash
231
- curl http://localhost:8080/api/health
232
- # Should return: {"status":"ok","port":8080}
234
+ # Stop current deployment
235
+ npx pm2 stop specgen
236
+
237
+ # Manual server setup
238
+ npm pack @gv-sh/specgen-server
239
+ tar -xzf gv-sh-specgen-server-*.tgz
240
+ mv package server
241
+ cd server && npm install && cd ..
242
+
243
+ # Manual admin build
244
+ npm pack @gv-sh/specgen-admin
245
+ tar -xzf gv-sh-specgen-admin-*.tgz
246
+ mv package admin
247
+ cd admin && npm install && GENERATE_SOURCEMAP=false PUBLIC_URL=/admin npm run build && cd ..
248
+
249
+ # Manual user build
250
+ npm pack @gv-sh/specgen-user
251
+ tar -xzf gv-sh-specgen-user-*.tgz
252
+ mv package user
253
+ cd user && npm install && GENERATE_SOURCEMAP=false REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build && cd ..
254
+
255
+ # Restart deployment
256
+ npx pm2 start server/index.js --name specgen
233
257
  ```
234
258
 
235
- ## 🚨 Breaking Changes from Previous Versions
259
+ ## 🚨 Known Issues
236
260
 
237
- - **Port Change**: Default port changed from 3000 → 8080
238
- - **URL Structure**: Admin at `/admin`, User at `/app`
239
- - **Simplified Scripts**: Single `setup` and `production` commands
240
- - **Automatic Cleanup**: Setup now cleans existing installations
261
+ ### Current Limitations
262
+ - **Memory Usage**: Requires at least 1GB RAM for builds
263
+ - **Build Time**: Initial deployment can take 5-10 minutes
264
+ - **SQLite Dependencies**: May require build tools on some systems
265
+ - **Static File Serving**: Builds must complete successfully for frontend access
266
+
267
+ ### AWS EC2 Specific
268
+ - **Security Groups**: Ensure port 8080 is open in your security group
269
+ - **Instance Type**: t2.micro may struggle with builds (t2.small recommended)
270
+ - **Storage**: Ensure at least 2GB free space for node_modules and builds
241
271
 
242
272
  ## 📚 API Documentation
243
273
 
244
- Once deployed, access the interactive API documentation at:
274
+ Once deployed, access interactive API documentation at:
245
275
  - **Swagger UI**: http://your-server:8080/api-docs
246
276
 
247
- ## 🤝 Contributing
277
+ ### Key API Endpoints
278
+ - `GET /api/health` - Health check and system status
279
+ - `POST /api/generate` - Generate speculative fiction content
280
+ - `GET /api/categories` - List available story categories
281
+ - `GET /api/parameters` - Get generation parameters
248
282
 
249
- 1. Fork the repository
250
- 2. Create your feature branch
251
- 3. Commit your changes
252
- 4. Push to the branch
253
- 5. Create a Pull Request
283
+ ## 🔄 Updates and Maintenance
254
284
 
255
- ## 📄 License
285
+ ### Updating SpecGen
286
+ ```bash
287
+ # Stop current deployment
288
+ npx pm2 stop specgen
256
289
 
257
- This project is licensed under the ISC License.
290
+ # Clean up old installation
291
+ rm -rf admin user server node_modules
258
292
 
259
- ## 🆘 Support
293
+ # Deploy latest version
294
+ npx @gv-sh/specgen-app deploy
295
+ ```
296
+
297
+ ### Backup Important Data
298
+ ```bash
299
+ # Backup database and configurations
300
+ tar -czf specgen-backup-$(date +%Y%m%d).tar.gz server/data server/.env logs/
301
+ ```
302
+
303
+ ## 🤝 Support
260
304
 
305
+ ### Getting Help
306
+ - **Health Check**: Visit http://your-server:8080/api/health
307
+ - **Logs**: Run `npx pm2 logs specgen`
261
308
  - **Issues**: [GitHub Issues](https://github.com/gv-sh/specgen-app/issues)
262
- - **Documentation**: Check `/api-docs` when running
263
- - **Health Check**: Visit `/api/health` to verify installation
309
+ - **Status**: Run `npx pm2 status` to check process status
310
+
311
+ ### Reporting Bugs
312
+ When reporting issues, please include:
313
+ - Output of `npx pm2 logs specgen`
314
+ - Output of `curl http://localhost:8080/api/health`
315
+ - Your server specifications (RAM, OS version, Node.js version)
316
+ - Any error messages from the deployment process
317
+
318
+ ## 📄 License
319
+
320
+ This project is licensed under the ISC License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gv-sh/specgen-app",
3
- "version": "0.5.1",
3
+ "version": "0.6.2",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -12,8 +12,8 @@
12
12
  "build": "cd admin && npm run build && cd ../user && npm run build",
13
13
  "start": "cd server && npm start",
14
14
  "production": "chmod +x scripts/production.sh && ./scripts/production.sh",
15
- "make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
16
15
  "deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
16
+ "make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
17
17
  "deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
18
18
  "deploy:restart": "chmod +x scripts/restart.sh && ./scripts/restart.sh",
19
19
  "deploy:status": "chmod +x scripts/status.sh && ./scripts/status.sh",
package/scripts/deploy.sh CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/bin/bash
2
2
 
3
- # SpecGen Deploy Script - Simple PM2 Deployment on Port 8080 with Full Cleanup
3
+ # SpecGen Deploy Script - Self-Contained Deployment on Port 8080
4
4
  set -e
5
5
 
6
6
  echo "🚀 Deploying SpecGen to production on port 8080..."
7
- echo "🧹 Performing full cleanup before deployment..."
7
+ echo "📦 This is a complete deployment - no separate setup needed!"
8
8
 
9
9
  # Function to check if port is available
10
10
  check_port() {
@@ -20,18 +20,17 @@ check_port() {
20
20
  # FULL CLEANUP
21
21
  # ========================================
22
22
 
23
+ echo "🧹 Cleaning up existing installations..."
24
+
23
25
  # Stop and remove all PM2 processes
24
- echo "Stopping all PM2 processes..."
25
26
  npx pm2 stop all 2>/dev/null || true
26
27
  npx pm2 delete all 2>/dev/null || true
27
28
  npx pm2 kill 2>/dev/null || true
28
29
 
29
30
  # Remove old PM2 config files
30
31
  rm -f ecosystem.config.js 2>/dev/null || true
31
- rm -f pm2.config.js 2>/dev/null || true
32
32
 
33
33
  # Kill processes on all relevant ports
34
- echo "Freeing all ports..."
35
34
  for port in 8080 3000 3001 3002; do
36
35
  if ! check_port $port; then
37
36
  echo "Killing processes on port $port..."
@@ -40,62 +39,158 @@ for port in 8080 3000 3001 3002; do
40
39
  fi
41
40
  done
42
41
 
43
- # Clean up logs
42
+ # Clean up old files
44
43
  rm -rf logs/* 2>/dev/null || true
45
44
 
46
- # Check for nginx conflicts
47
- if command -v nginx &> /dev/null && systemctl is-active --quiet nginx 2>/dev/null; then
48
- if nginx -T 2>/dev/null | grep -q ":8080"; then
49
- echo "⚠️ WARNING: Nginx is configured to use port 8080"
50
- echo " You may need to stop nginx or reconfigure it"
51
- echo " Run: sudo systemctl stop nginx"
45
+ # ========================================
46
+ # VERIFY PREREQUISITES
47
+ # ========================================
48
+
49
+ echo "🔍 Checking prerequisites..."
50
+
51
+ # Check Node.js version
52
+ NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
53
+ if [ "$NODE_VERSION" -lt 20 ]; then
54
+ 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"
56
+ exit 1
57
+ fi
58
+
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
67
+ fi
68
+
69
+ # ========================================
70
+ # SETUP OPENAI API KEY
71
+ # ========================================
72
+
73
+ echo "🔑 Setting up OpenAI API key..."
74
+
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
77
+ if [ "$CI" = "true" ]; then
78
+ 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
83
+ else
84
+ echo "⚠️ OpenAI API key required for SpecGen to work."
85
+ echo "Enter your OpenAI API key: "
86
+ read -r OPENAI_KEY
87
+
88
+ if [ -z "$OPENAI_KEY" ]; then
89
+ echo "❌ No API key provided. SpecGen needs an OpenAI API key to function."
90
+ exit 1
91
+ fi
92
+
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
97
+ echo "✅ API key saved"
52
98
  fi
53
99
  fi
54
100
 
55
101
  # ========================================
56
- # RUN PRODUCTION SETUP
102
+ # BUILD APPLICATION
57
103
  # ========================================
58
104
 
59
- echo "Running production setup..."
60
- npm run production &
61
- SETUP_PID=$!
62
-
63
- # Wait for setup to complete or timeout
64
- TIMEOUT=90
65
- COUNT=0
66
- while [ $COUNT -lt $TIMEOUT ]; do
67
- if ! kill -0 $SETUP_PID 2>/dev/null; then
68
- echo "Production setup completed"
69
- break
105
+ echo "🏗️ Building application components..."
106
+
107
+ # Install and build server
108
+ if [ ! -d "server" ] || [ ! -d "server/node_modules" ]; then
109
+ echo "📦 Setting up server..."
110
+ npm pack @gv-sh/specgen-server
111
+ tar -xzf gv-sh-specgen-server-*.tgz
112
+ mv package server
113
+ rm gv-sh-specgen-server-*.tgz
114
+
115
+ cd server
116
+ echo "engine-strict=false" > .npmrc
117
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
118
+ cd ..
119
+ fi
120
+
121
+ # Install and build admin
122
+ if [ ! -d "admin/build" ]; then
123
+ echo "📱 Building admin interface..."
124
+ if [ ! -d "admin" ]; then
125
+ npm pack @gv-sh/specgen-admin
126
+ tar -xzf gv-sh-specgen-admin-*.tgz
127
+ mv package admin
128
+ rm gv-sh-specgen-admin-*.tgz
70
129
  fi
71
- sleep 1
72
- COUNT=$((COUNT + 1))
73
130
 
74
- # Show progress every 15 seconds
75
- if [ $((COUNT % 15)) -eq 0 ]; then
76
- echo "Setup still running... ($COUNT/$TIMEOUT seconds)"
131
+ cd admin
132
+ echo "engine-strict=false" > .npmrc
133
+ # Install ALL dependencies for build process
134
+ npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
135
+ # Build with proper environment variables (no cross-env needed on Linux)
136
+ GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
137
+ cd ..
138
+ fi
139
+
140
+ # Install and build user
141
+ if [ ! -d "user/build" ]; then
142
+ echo "👤 Building user interface..."
143
+ if [ ! -d "user" ]; then
144
+ npm pack @gv-sh/specgen-user
145
+ tar -xzf gv-sh-specgen-user-*.tgz
146
+ mv package user
147
+ rm gv-sh-specgen-user-*.tgz
77
148
  fi
78
- done
149
+
150
+ cd user
151
+ echo "engine-strict=false" > .npmrc
152
+ # Install ALL dependencies for build process
153
+ npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
154
+ # Build with proper environment variables (no cross-env needed on Linux)
155
+ GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
156
+ cd ..
157
+ fi
79
158
 
80
- # Kill setup process if it's still running
81
- if kill -0 $SETUP_PID 2>/dev/null; then
82
- echo "Setup taking too long, terminating and continuing with PM2 deployment..."
83
- kill $SETUP_PID 2>/dev/null || true
84
- # Force kill any remaining processes
85
- for port in 8080 3000; do
86
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
87
- done
159
+ # ========================================
160
+ # VERIFY BUILDS
161
+ # ========================================
162
+
163
+ echo "✅ Verifying builds..."
164
+ if [ ! -d "admin/build" ]; then
165
+ echo "❌ Admin build failed"
166
+ ls -la admin/ || echo "Admin directory not found"
167
+ exit 1
88
168
  fi
89
169
 
90
- # Wait a moment for cleanup
91
- sleep 3
170
+ if [ ! -d "user/build" ]; then
171
+ echo "❌ User build failed"
172
+ ls -la user/ || echo "User directory not found"
173
+ exit 1
174
+ fi
175
+
176
+ 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"
180
+
181
+ # 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
92
186
 
93
187
  # ========================================
94
188
  # PM2 DEPLOYMENT
95
189
  # ========================================
96
190
 
191
+ echo "🚀 Starting PM2 deployment..."
192
+
97
193
  # Create PM2 ecosystem configuration
98
- echo "Creating PM2 ecosystem configuration..."
99
194
  cat > ecosystem.config.js << 'EOF'
100
195
  module.exports = {
101
196
  apps: [{
@@ -116,7 +211,7 @@ module.exports = {
116
211
  watch: false,
117
212
  ignore_watch: ['node_modules', 'logs', '*.log'],
118
213
  restart_delay: 1000,
119
- max_restarts: 3,
214
+ max_restarts: 10,
120
215
  min_uptime: '10s'
121
216
  }]
122
217
  }
@@ -125,29 +220,68 @@ EOF
125
220
  # Create logs directory
126
221
  mkdir -p logs
127
222
 
223
+ # Copy .env to ensure PM2 picks it up
224
+ cp server/.env .env 2>/dev/null || true
225
+
128
226
  # Final port check
129
- echo "Final port check..."
130
227
  if ! check_port 8080; then
131
- echo "Port 8080 still occupied, force cleaning..."
228
+ echo "Port 8080 occupied, force cleaning..."
132
229
  lsof -ti:8080 | xargs kill -9 2>/dev/null || true
133
230
  sleep 2
134
231
  fi
135
232
 
136
233
  # Start with PM2
137
- echo "Starting SpecGen with PM2 on port 8080..."
234
+ echo "▶️ Starting SpecGen with PM2..."
138
235
  NODE_ENV=production PORT=8080 npx pm2 start ecosystem.config.js
139
236
 
140
237
  # Wait for startup and verify
141
238
  sleep 5
142
239
 
143
- # Check if the process is actually running
240
+ # ========================================
241
+ # DEPLOYMENT VERIFICATION
242
+ # ========================================
243
+
244
+ echo "🔍 Verifying deployment..."
245
+
144
246
  if npx pm2 list | grep -q "online"; then
145
- echo ""
146
- echo " SpecGen deployment completed successfully!"
247
+ # Test endpoints
248
+ echo "Testing endpoints:"
249
+
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
256
+
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
264
+
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"
271
+ fi
272
+
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
147
280
 
148
- # Get public IP
149
281
  PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
150
282
 
283
+ echo ""
284
+ echo "🎉 SpecGen deployment completed!"
151
285
  echo ""
152
286
  echo "🌐 Access your application at:"
153
287
  echo " - Main page: http://$PUBLIC_IP:8080/"
@@ -156,25 +290,24 @@ if npx pm2 list | grep -q "online"; then
156
290
  echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
157
291
  echo " - Health check: http://$PUBLIC_IP:8080/api/health"
158
292
  echo ""
159
- echo "📊 Management commands:"
160
- echo " - Check status: npx pm2 status"
161
- echo " - View logs: npx pm2 logs specgen"
162
- echo " - Restart: npx pm2 restart specgen"
163
- echo " - Stop: npx pm2 stop specgen"
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"
164
302
  echo ""
165
-
166
- # Test the health endpoint
167
- echo "🔍 Testing health endpoint..."
168
- if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
169
- echo "✅ Health check passed!"
170
- else
171
- echo "⚠️ Health check failed - check logs with: npx pm2 logs specgen"
172
- fi
173
303
 
174
304
  else
175
305
  echo ""
176
306
  echo "❌ Deployment failed!"
177
- echo "📝 Check logs with: npx pm2 logs specgen"
178
- echo "📊 Check status with: npx pm2 status"
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
179
312
  exit 1
180
313
  fi