@gv-sh/specgen-app 0.9.0 โ†’ 0.13.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.
package/.env ADDED
@@ -0,0 +1,4 @@
1
+ OPENAI_API_KEY=sk-test1234567890abcdef
2
+ NODE_ENV=production
3
+ PORT=80
4
+ HOST=127.0.0.1
@@ -41,20 +41,19 @@ jobs:
41
41
 
42
42
  - name: Test setup and production process
43
43
  run: |
44
- # Create an automated setup process for CI environment
45
- mkdir -p server
46
-
47
- # Create a CI-specific .env file with a dummy API key
48
- echo "OPENAI_API_KEY=sk-test1234\nNODE_ENV=test\nPORT=3000" > server/.env
44
+ # Clean any existing files that might conflict
45
+ rm -rf server admin user 2>/dev/null || true
49
46
 
50
47
  # Run normal setup with the environment variable to indicate CI mode
51
48
  CI=true npm run setup
52
49
 
53
- # Make scripts executable
54
- npm run make-executable
50
+ # Create a CI-specific .env file with a dummy API key after setup
51
+ echo "OPENAI_API_KEY=sk-test1234" > server/.env
52
+ echo "NODE_ENV=test" >> server/.env
53
+ echo "PORT=3000" >> server/.env
55
54
 
56
- # Test production script in CI mode
57
- CI=true timeout 10s ./scripts/production.sh || true
55
+ # Test that scripts are executable (they get chmod in their npm run commands)
56
+ ls -la scripts/
58
57
 
59
58
  # Verify all components are extracted
60
59
  if [ ! -d "server" ]; then
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.9.0-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.13.2-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.9.0",
3
+ "version": "0.13.2",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -9,18 +9,16 @@
9
9
  "scripts": {
10
10
  "setup": "chmod +x scripts/setup.sh && ./scripts/setup.sh",
11
11
  "dev": "chmod +x scripts/dev.sh && ./scripts/dev.sh",
12
- "build": "cd admin && npm run build && cd ../user && npm run build",
12
+ "build": "cd admin && PUBLIC_URL=/admin npm run build && cd ../user && npm run build",
13
13
  "start": "cd server && npm start",
14
14
  "deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
15
- "deploy:dry-run": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
16
- "test:deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh --dry-run",
17
- "make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
15
+ "deploy:ec2": "chmod +x scripts/deploy-ec2.sh && ./scripts/deploy-ec2.sh",
18
16
  "postinstall": "chmod +x bin/cli.js"
19
17
  },
20
18
  "dependencies": {
21
- "@gv-sh/specgen-server": "0.9.0",
22
- "@gv-sh/specgen-admin": "0.9.0",
23
- "@gv-sh/specgen-user": "0.9.0"
19
+ "@gv-sh/specgen-server": "0.10.1",
20
+ "@gv-sh/specgen-admin": "0.10.0",
21
+ "@gv-sh/specgen-user": "0.10.1"
24
22
  },
25
23
  "devDependencies": {
26
24
  "concurrently": "^8.2.2"
@@ -0,0 +1,133 @@
1
+ #!/bin/bash
2
+
3
+ # SpecGen EC2 Remote Deployment Script
4
+ # Run from your Mac to deploy to EC2
5
+
6
+ set -e
7
+
8
+ # Configuration
9
+ EC2_HOST="ubuntu@ec2-52-66-251-12.ap-south-1.compute.amazonaws.com"
10
+ EC2_KEY="debanshu.pem"
11
+ REPO_URL="https://github.com/gv-sh/specgen-app.git"
12
+ APP_DIR="/home/ubuntu/specgen-app"
13
+
14
+ echo "๐Ÿš€ SpecGen EC2 Remote Deployment Starting..."
15
+ echo "๐Ÿ“ก Target: $EC2_HOST"
16
+
17
+ # Check if key file exists
18
+ if [ ! -f "$EC2_KEY" ]; then
19
+ echo "โŒ SSH key file '$EC2_KEY' not found!"
20
+ echo "Please ensure the key file is in the current directory."
21
+ exit 1
22
+ fi
23
+
24
+ # Function to run commands on EC2
25
+ run_on_ec2() {
26
+ ssh -i "$EC2_KEY" "$EC2_HOST" "$1"
27
+ }
28
+
29
+ echo "๐Ÿงน Stopping existing services..."
30
+ run_on_ec2 "
31
+ cd '$APP_DIR/server' 2>/dev/null || true
32
+ npx pm2 stop specgen 2>/dev/null || true
33
+ npx pm2 delete specgen 2>/dev/null || true
34
+ "
35
+
36
+ echo "๐Ÿ“ฅ Updating repository..."
37
+ run_on_ec2 "
38
+ if [ -d '$APP_DIR' ]; then
39
+ cd '$APP_DIR' && git pull origin main
40
+ else
41
+ git clone '$REPO_URL' '$APP_DIR'
42
+ fi
43
+ "
44
+
45
+ echo "๐Ÿ“ฆ Setting up dependencies..."
46
+ run_on_ec2 "
47
+ cd '$APP_DIR'
48
+ npm run setup
49
+
50
+ # Install cross-env in user directory
51
+ cd user && npm install cross-env --save-dev && cd ..
52
+ "
53
+
54
+ echo "๐Ÿ—๏ธ Building applications..."
55
+ run_on_ec2 "
56
+ cd '$APP_DIR'
57
+
58
+ # Build admin interface with correct public URL
59
+ echo 'Building admin interface...'
60
+ cd admin && PUBLIC_URL=/admin npm run build && cd ..
61
+
62
+ # Build user interface with production API URL
63
+ echo 'Building user interface...'
64
+ cd user && cross-env REACT_APP_API_URL=/api npm run build && cd ..
65
+
66
+ echo 'โœ… Builds completed'
67
+ "
68
+
69
+ echo "๐Ÿ”ง Configuring environment..."
70
+
71
+ # Get OpenAI API key from local environment
72
+ OPENAI_KEY=""
73
+ if [ -f "../specgen-server/.env" ]; then
74
+ OPENAI_KEY=$(grep "OPENAI_API_KEY=" ../specgen-server/.env | cut -d'=' -f2- | tr -d '"'"'"'')
75
+ echo "โœ… Found OpenAI API key in local specgen-server/.env"
76
+ elif [ -f "server/.env" ]; then
77
+ OPENAI_KEY=$(grep "OPENAI_API_KEY=" server/.env | cut -d'=' -f2- | tr -d '"'"'"'')
78
+ echo "โœ… Found OpenAI API key in local server/.env"
79
+ else
80
+ echo "โš ๏ธ No OpenAI API key found locally, will use test key"
81
+ OPENAI_KEY="sk-test1234"
82
+ fi
83
+
84
+ run_on_ec2 "
85
+ cd '$APP_DIR'
86
+
87
+ # Create logs directory
88
+ mkdir -p logs
89
+
90
+ # Configure server environment
91
+ cat > server/.env << 'EOF'
92
+ NODE_ENV=production
93
+ PORT=80
94
+ HOST=0.0.0.0
95
+ EOF
96
+
97
+ # Add OpenAI key securely
98
+ echo 'OPENAI_API_KEY=$OPENAI_KEY' >> server/.env
99
+
100
+ echo 'Environment configured with OpenAI API key'
101
+ "
102
+
103
+ echo "๐Ÿš€ Starting application..."
104
+ run_on_ec2 "
105
+ cd '$APP_DIR/server'
106
+ npx pm2 start ecosystem.config.js
107
+ "
108
+
109
+ echo "โณ Waiting for startup..."
110
+ sleep 5
111
+
112
+ echo "๐Ÿงช Testing deployment..."
113
+ HEALTH_CHECK=$(run_on_ec2 "curl -s http://localhost:80/api/health | jq -r '.status' 2>/dev/null || echo 'failed'")
114
+
115
+ if [ "$HEALTH_CHECK" = "healthy" ]; then
116
+ echo "โœ… Deployment successful!"
117
+ echo ""
118
+ echo "๐ŸŒ Access your application:"
119
+ echo " User Interface: http://52.66.251.12/"
120
+ echo " Admin Panel: http://52.66.251.12/admin"
121
+ echo " API Documentation: http://52.66.251.12/api-docs"
122
+ echo " Health Check: http://52.66.251.12/api/health"
123
+ echo ""
124
+ echo "๐Ÿ“Š Server status:"
125
+ run_on_ec2 "cd '$APP_DIR/server' && npx pm2 status"
126
+ else
127
+ echo "โŒ Deployment failed - health check returned: $HEALTH_CHECK"
128
+ echo "๐Ÿ“‹ Checking logs..."
129
+ run_on_ec2 "cd '$APP_DIR/server' && npx pm2 logs specgen --lines 10"
130
+ exit 1
131
+ fi
132
+
133
+ echo "๐ŸŽ‰ SpecGen deployment completed successfully!"
package/scripts/deploy.sh CHANGED
@@ -1,558 +1,47 @@
1
1
  #!/bin/bash
2
-
3
- # SpecGen Deploy Script - Self-Contained Deployment on Port 80
4
2
  set -e
5
3
 
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 80..."
14
- echo "๐Ÿ“ฆ This is a complete deployment - no separate setup needed!"
15
- fi
16
-
17
- # Function to check if port is available
18
- check_port() {
19
- local port=$1
20
- if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
21
- return 1 # Port in use
22
- else
23
- return 0 # Port available
24
- fi
25
- }
26
-
27
- # Get absolute path of current working directory
28
- PROJECT_DIR=$(pwd)
29
- echo "๐Ÿ“‚ Project directory: $PROJECT_DIR"
30
-
31
- # ========================================
32
- # PLATFORM-SPECIFIC SETUP
33
- # ========================================
34
-
35
- # Detect platform
36
- PLATFORM=$(uname -s)
37
- if [ "$PLATFORM" = "Darwin" ]; then
38
- echo "๐ŸŽ Detected macOS"
39
- PM2_CMD="npx pm2"
40
- DEFAULT_BIND_HOST="127.0.0.1" # macOS - default to localhost
41
- elif [ "$PLATFORM" = "Linux" ]; then
42
- echo "๐Ÿง Detected Linux"
43
- PM2_CMD="npx pm2"
44
- DEFAULT_BIND_HOST="0.0.0.0" # Linux - default to public access
45
- else
46
- echo "โš ๏ธ Unknown platform: $PLATFORM"
47
- PM2_CMD="npx pm2"
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
95
- fi
96
-
97
- echo "๐ŸŒ Server will bind to: $BIND_HOST"
98
-
99
- # ========================================
100
- # CLEANUP (Skip in dry-run for safety)
101
- # ========================================
102
-
103
- if [ "$DRY_RUN" = false ]; then
104
- echo "๐Ÿงน Cleaning up existing installations..."
105
-
106
- # Stop and remove all PM2 processes
107
- $PM2_CMD stop all 2>/dev/null || true
108
- $PM2_CMD delete all 2>/dev/null || true
109
- $PM2_CMD kill 2>/dev/null || true
110
-
111
- # Remove old PM2 config files
112
- rm -f ecosystem.config.js 2>/dev/null || true
113
-
114
- # Kill processes on all relevant ports
115
- for port in 80 3000 3001 3002; do
116
- if ! check_port $port; then
117
- echo "Killing processes on port $port..."
118
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
119
- sleep 1
120
- fi
121
- done
122
-
123
- # Clean up old files
124
- rm -rf logs/* 2>/dev/null || true
125
- else
126
- echo "๐Ÿงช DRY RUN: Skipping cleanup (existing processes will remain)"
127
- fi
128
-
129
- # ========================================
130
- # VERIFY PREREQUISITES
131
- # ========================================
132
-
133
- echo "๐Ÿ” Checking prerequisites..."
134
-
135
- # Check Node.js version
136
- NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
137
- if [ "$DRY_RUN" = true ]; then
138
- if [ "$NODE_VERSION" -lt 18 ]; then
139
- echo "โŒ Node.js 18+ required for testing. Current version: $(node --version)"
140
- exit 1
141
- else
142
- echo "โœ… Node.js version: $(node --version)"
143
- fi
144
- else
145
- if [ "$NODE_VERSION" -lt 20 ]; then
146
- echo "โŒ Node.js 20+ required for production. Current version: $(node --version)"
147
- exit 1
148
- else
149
- echo "โœ… Node.js version: $(node --version)"
150
- fi
151
- fi
152
-
153
- echo "โœ… npm version: $(npm --version)"
154
-
155
- # ========================================
156
- # SETUP OPENAI API KEY
157
- # ========================================
158
-
159
- echo "๐Ÿ”‘ Setting up OpenAI API key..."
160
-
161
- if [ "$DRY_RUN" = true ]; then
162
- echo "๐Ÿงช DRY RUN: Using test API key"
163
- mkdir -p "$PROJECT_DIR/server"
164
- echo "OPENAI_API_KEY=sk-test1234567890abcdef" > "$PROJECT_DIR/server/.env"
165
- echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
166
- echo "PORT=80" >> "$PROJECT_DIR/server/.env"
167
- echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
168
- elif [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
169
- if [ "$CI" = "true" ]; then
170
- echo "CI mode - using test API key"
171
- mkdir -p "$PROJECT_DIR/server"
172
- echo "OPENAI_API_KEY=sk-test1234" > "$PROJECT_DIR/server/.env"
173
- echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
174
- echo "PORT=80" >> "$PROJECT_DIR/server/.env"
175
- echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
176
- else
177
- echo "โš ๏ธ OpenAI API key required for SpecGen to work."
178
- echo "Enter your OpenAI API key (or press Enter to use test key): "
179
- read -r OPENAI_KEY
180
-
181
- if [ -z "$OPENAI_KEY" ]; then
182
- OPENAI_KEY="sk-test1234567890abcdef"
183
- echo "Using test API key for this deployment"
184
- fi
185
-
186
- mkdir -p "$PROJECT_DIR/server"
187
- echo "OPENAI_API_KEY=$OPENAI_KEY" > "$PROJECT_DIR/server/.env"
188
- echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
189
- echo "PORT=80" >> "$PROJECT_DIR/server/.env"
190
- echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
191
- echo "โœ… API key saved"
192
- fi
193
- fi
194
-
195
- # ========================================
196
- # BUILD APPLICATION
197
- # ========================================
198
-
199
- echo "๐Ÿ—๏ธ Building application components..."
200
- cd "$PROJECT_DIR"
201
-
202
- # Install and build server
203
- if [ ! -f "server/index.js" ]; then
204
- echo "๐Ÿ“ฆ Setting up server..."
205
-
206
- rm -rf server
207
- npm pack @gv-sh/specgen-server --loglevel=warn
208
- tar -xzf gv-sh-specgen-server-*.tgz
209
-
210
- if [ -d "package" ]; then
211
- mv package server
212
- rm gv-sh-specgen-server-*.tgz
213
- echo "โœ… Server extracted successfully"
214
- else
215
- echo "โŒ Failed to extract server package"
216
- exit 1
217
- fi
218
-
219
- cd server
220
- echo "engine-strict=false" > .npmrc
221
- npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
222
- cd "$PROJECT_DIR"
223
-
224
- # Install unified server that binds to 0.0.0.0
225
- echo " ๐Ÿ”ง Installing unified server (binds to all interfaces)..."
226
- cat > server/index.js << 'EOF'
227
- // index.js - Unified server for port 80 with public binding
228
- /* global process */
229
- require('dotenv').config();
230
- const express = require('express');
231
- const cors = require('cors');
232
- const path = require('path');
233
- const errorHandler = require('./middleware/errorHandler');
234
-
235
- // Initialize Express app
236
- const app = express();
237
- const PORT = process.env.PORT || 80;
238
- const HOST = process.env.HOST || '0.0.0.0'; // Bind to all interfaces by default
239
-
240
- // Middleware
241
- app.use(cors());
242
- app.use(express.json());
243
- app.use(express.urlencoded({ extended: true }));
244
-
245
- // Serve static files for admin interface at /admin
246
- const adminBuildPath = path.join(__dirname, '../admin/build');
247
- const fs = require('fs');
248
- if (fs.existsSync(adminBuildPath)) {
249
- app.use('/admin', express.static(adminBuildPath));
250
- app.get('/admin/*', (req, res) => {
251
- res.sendFile(path.join(adminBuildPath, 'index.html'));
252
- });
253
- console.log('โœ… Admin interface available at /admin');
254
- } else {
255
- console.log('โš ๏ธ Admin build not found');
256
- }
257
-
258
- // Serve static files for user interface at /app
259
- const userBuildPath = path.join(__dirname, '../user/build');
260
- if (fs.existsSync(userBuildPath)) {
261
- app.use('/app', express.static(userBuildPath));
262
- app.get('/app/*', (req, res) => {
263
- res.sendFile(path.join(userBuildPath, 'index.html'));
264
- });
265
- console.log('โœ… User interface available at /app');
266
- } else {
267
- console.log('โš ๏ธ User build not found');
268
- }
269
-
270
- // Serve user interface as default at root
271
- if (fs.existsSync(userBuildPath)) {
272
- app.use('/', express.static(userBuildPath, { index: false }));
273
- }
274
-
275
- // API Routes
276
- const categoryRoutes = require('./routes/categories');
277
- const parameterRoutes = require('./routes/parameters');
278
- const generateRoutes = require('./routes/generate');
279
- const databaseRoutes = require('./routes/database');
280
- const contentRoutes = require('./routes/content');
281
- const settingsRoutes = require('./routes/settings');
282
-
283
- app.use('/api/categories', categoryRoutes);
284
- app.use('/api/parameters', parameterRoutes);
285
- app.use('/api/generate', generateRoutes);
286
- app.use('/api/database', databaseRoutes);
287
- app.use('/api/content', contentRoutes);
288
- app.use('/api/settings', settingsRoutes);
289
-
290
- if (process.env.NODE_ENV !== 'test') {
291
- const swaggerRoutes = require('./routes/swagger');
292
- app.use('/api-docs', swaggerRoutes);
293
- }
4
+ echo "๐Ÿš€ Deploying SpecGen..."
294
5
 
295
- const healthRoutes = require('./routes/health');
296
- app.use('/api/health', healthRoutes);
6
+ # Build React apps with production configuration
7
+ echo "๐Ÿ“ฆ Building applications..."
297
8
 
298
- // Root route
299
- app.get('/', (req, res) => {
300
- if (fs.existsSync(userBuildPath)) {
301
- res.sendFile(path.join(userBuildPath, 'index.html'));
302
- } else {
303
- const html = `
304
- <!DOCTYPE html>
305
- <html>
306
- <head>
307
- <title>SpecGen - Running on ${HOST}:${PORT}</title>
308
- <style>
309
- body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; background: #f8f9fa; }
310
- .nav-card { border: 1px solid #dee2e6; border-radius: 8px; padding: 20px; margin: 15px 0; background: white; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
311
- .nav-card:hover { background-color: #f8f9fa; transform: translateY(-2px); transition: all 0.2s; }
312
- a { text-decoration: none; color: #007bff; }
313
- h1 { color: #343a40; text-align: center; }
314
- .status { color: #28a745; font-weight: bold; text-align: center; background: #d4edda; padding: 10px; border-radius: 5px; margin: 20px 0; }
315
- .binding { background: #e3f2fd; border: 1px solid #2196f3; padding: 15px; border-radius: 5px; margin: 20px 0; }
316
- </style>
317
- </head>
318
- <body>
319
- <h1>๐Ÿš€ SpecGen Platform</h1>
320
- <div class="status">โœ… Server running on ${HOST}:${PORT}</div>
321
-
322
- <div class="binding">
323
- <strong>๐ŸŒ Network Binding:</strong> ${HOST === '0.0.0.0' ? 'Public access enabled (0.0.0.0)' : 'Local access only (' + HOST + ')'}
324
- </div>
325
-
326
- <div class="nav-card">
327
- <h3><a href="/app">๐Ÿ“ฑ User Application</a></h3>
328
- <p>Main SpecGen user interface</p>
329
- </div>
330
-
331
- <div class="nav-card">
332
- <h3><a href="/admin">โš™๏ธ Admin Panel</a></h3>
333
- <p>Administrative interface</p>
334
- </div>
335
-
336
- <div class="nav-card">
337
- <h3><a href="/api-docs">๐Ÿ“š API Documentation</a></h3>
338
- <p>Interactive API documentation</p>
339
- </div>
340
-
341
- <div class="nav-card">
342
- <h3><a href="/api/health">โค๏ธ Health Check</a></h3>
343
- <p>System health monitoring</p>
344
- </div>
345
- </body>
346
- </html>`;
347
- res.send(html);
348
- }
349
- });
9
+ # Build admin with correct public URL
10
+ echo "Building admin interface..."
11
+ cd admin && PUBLIC_URL=/admin npm run build && cd ..
350
12
 
351
- app.use(errorHandler);
13
+ # Build user with production API URL
14
+ echo "Building user interface..."
15
+ cd user && npm run build && cd ..
352
16
 
353
- if (require.main === module) {
354
- app.listen(PORT, HOST, () => {
355
- console.log(`๐Ÿš€ SpecGen server running on ${HOST}:${PORT}`);
356
- console.log(`๐Ÿ“ฑ User App: http://${HOST}:${PORT}/app`);
357
- console.log(`โš™๏ธ Admin Panel: http://${HOST}:${PORT}/admin`);
358
- console.log(`๐Ÿ“š API Docs: http://${HOST}:${PORT}/api-docs`);
359
- console.log(`โค๏ธ Health Check: http://${HOST}:${PORT}/api/health`);
360
-
361
- if (HOST === '0.0.0.0') {
362
- console.log(`๐ŸŒ Accessible from any IP address`);
363
- } else {
364
- console.log(`๐Ÿ  Local access only (${HOST})`);
365
- }
366
- });
367
- }
17
+ # Create logs directory
18
+ mkdir -p logs
368
19
 
369
- module.exports = app;
20
+ # Set environment for production
21
+ echo "๐Ÿ”ง Configuring environment..."
22
+ cat > server/.env << 'EOF'
23
+ NODE_ENV=production
24
+ PORT=80
25
+ HOST=0.0.0.0
370
26
  EOF
371
- echo "โœ… Unified server installed with public binding"
372
- fi
373
27
 
374
- # Build admin and user (shortened for brevity)
375
- for component in admin user; do
376
- if [ ! -d "$component/build" ]; then
377
- echo "๐Ÿ“ฑ Building $component interface..."
378
-
379
- if [ ! -d "$component" ]; then
380
- npm pack @gv-sh/specgen-$component --loglevel=warn
381
- tar -xzf gv-sh-specgen-$component-*.tgz
382
- mv package $component
383
- rm gv-sh-specgen-$component-*.tgz
384
- fi
385
-
386
- cd $component
387
- echo "engine-strict=false" > .npmrc
388
- npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
389
-
390
- if [ "$component" = "admin" ]; then
391
- GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
392
- else
393
- GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
394
- fi
395
- cd "$PROJECT_DIR"
28
+ # Add OpenAI key if not set
29
+ if ! grep -q "OPENAI_API_KEY" server/.env 2>/dev/null; then
30
+ echo "Enter OpenAI API key (or press Enter for test key):"
31
+ read -r OPENAI_KEY
32
+ if [ -z "$OPENAI_KEY" ]; then
33
+ OPENAI_KEY="sk-test1234"
396
34
  fi
397
- done
398
-
399
- # No need to install serve - using unified server only
400
-
401
- # ====================== ==================
402
- # VERIFY BUILDS
403
- # ========================================
404
-
405
- echo "โœ… Verifying builds..."
406
- if [ ! -d "admin/build" ] || [ ! -d "user/build" ] || [ ! -f "server/index.js" ]; then
407
- echo "โŒ Build verification failed"
408
- exit 1
35
+ echo "OPENAI_API_KEY=$OPENAI_KEY" >> server/.env
409
36
  fi
410
37
 
411
- echo "๐Ÿ“ All builds completed successfully"
412
-
413
- # ========================================
414
- # DEPLOYMENT
415
- # ========================================
416
-
417
- if [ "$DRY_RUN" = true ]; then
418
- echo "๐Ÿงช DRY RUN: Testing server startup..."
419
- cd "$PROJECT_DIR"
420
- cp server/.env .env 2>/dev/null || true
421
-
422
- TEST_PORT=80
423
- if ! check_port $TEST_PORT; then
424
- TEST_PORT=8081
425
- fi
426
-
427
- echo " Starting test server on $BIND_HOST:$TEST_PORT for 10 seconds..."
428
- (cd server && NODE_ENV=production PORT=$TEST_PORT HOST=$BIND_HOST node index.js) &
429
- SERVER_PID=$!
430
-
431
- sleep 3
432
-
433
- echo " Testing endpoints:"
434
- if curl -s http://localhost:$TEST_PORT/api/health >/dev/null 2>&1; then
435
- echo " โœ… Health endpoint: OK"
436
- else
437
- echo " โŒ Health endpoint: FAILED"
438
- fi
439
-
440
- kill $SERVER_PID 2>/dev/null || true
441
- wait $SERVER_PID 2>/dev/null || true
442
-
443
- echo ""
444
- echo "๐ŸŽ‰ DRY RUN COMPLETED!"
445
- echo "๐Ÿš€ Ready for production deployment!"
446
-
447
- else
448
- echo "๐Ÿš€ Starting PM2 deployment..."
449
-
450
- mkdir -p logs
451
- cp server/.env .env 2>/dev/null || true
38
+ # Deploy with PM2 using ecosystem config
39
+ echo "๐Ÿš€ Starting with PM2..."
40
+ npx pm2 stop specgen 2>/dev/null || true
41
+ npx pm2 delete specgen 2>/dev/null || true
452
42
 
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
43
+ # Start with ecosystem config
44
+ npx pm2 start ecosystem.config.js
460
45
 
461
- # Load environment variables from .env
462
- set -o allexport
463
- source .env
464
- set +o allexport
465
-
466
- cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
467
- module.exports = {
468
- apps: [
469
- {
470
- name: 'specgen',
471
- script: '$PROJECT_DIR/server/index.js',
472
- cwd: '$PROJECT_DIR',
473
- env: {
474
- NODE_ENV: 'production',
475
- PORT: 80,
476
- HOST: '$BIND_HOST',
477
- OPENAI_API_KEY: process.env.OPENAI_API_KEY
478
- },
479
- instances: 1,
480
- exec_mode: 'fork',
481
- max_memory_restart: '500M',
482
- error_file: '$PROJECT_DIR/logs/err.log',
483
- out_file: '$PROJECT_DIR/logs/out.log',
484
- log_file: '$PROJECT_DIR/logs/combined.log',
485
- time: true,
486
- watch: false
487
- }
488
- ]
489
- }
490
- EOF
491
-
492
- mkdir -p logs
493
- cp server/.env .env 2>/dev/null || true
494
-
495
- if ! check_port 80; then
496
- lsof -ti:80 | xargs kill -9 2>/dev/null || true
497
- sleep 2
498
- fi
499
-
500
- NODE_ENV=production PORT=80 HOST=$BIND_HOST $PM2_CMD start ecosystem.config.js
501
-
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
516
-
517
- if $PM2_CMD list | grep -q "online" && [ "$HEALTH_CHECK" = true ]; then
518
- PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || echo 'your-server')
519
-
520
- echo ""
521
- echo "๐ŸŽ‰ SpecGen deployment completed!"
522
- echo ""
523
- echo "๐ŸŒ Access your application at:"
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
537
- echo ""
538
- echo "๐Ÿ”ง Binding: Server is bound to $BIND_HOST"
539
- echo "๐Ÿ“Š Management: npx pm2 status | npx pm2 logs specgen"
540
- echo ""
541
- echo "โœ… All services are running and responding!"
542
-
543
- else
544
- echo ""
545
- echo "โŒ Deployment failed!"
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"
556
- exit 1
557
- fi
558
- fi
46
+ echo "โœ… Deployed! Check with: npx pm2 status"
47
+ echo "๐ŸŒ Access at: http://localhost/ (admin: /admin)"
package/scripts/backup.sh DELETED
@@ -1,37 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Backup SpecGen application and database
4
- set -e
5
-
6
- BACKUP_DIR="/opt/backups/specgen"
7
- DATE=$(date +%Y%m%d-%H%M%S)
8
- BACKUP_NAME="specgen-backup-$DATE"
9
-
10
- echo "Creating backup: $BACKUP_NAME"
11
-
12
- # Create backup directory
13
- sudo mkdir -p $BACKUP_DIR
14
-
15
- # Stop services for consistent backup
16
- pm2 stop specgen-server
17
-
18
- # Create backup
19
- echo "Backing up application files..."
20
- sudo tar -czf "$BACKUP_DIR/$BACKUP_NAME.tar.gz" -C /opt specgen-app
21
-
22
- # Backup database separately if it exists
23
- if [ -f /opt/specgen-app/server/data/database.json ]; then
24
- echo "Backing up database..."
25
- sudo cp /opt/specgen-app/server/data/database.json "$BACKUP_DIR/database-$DATE.json"
26
- fi
27
-
28
- # Restart services
29
- pm2 start ecosystem.config.js
30
-
31
- # Clean old backups (keep last 5)
32
- echo "Cleaning old backups..."
33
- cd $BACKUP_DIR
34
- sudo ls -t *.tar.gz | tail -n +6 | sudo xargs rm -f || true
35
- sudo ls -t database-*.json | tail -n +6 | sudo xargs rm -f || true
36
-
37
- echo "Backup completed: $BACKUP_DIR/$BACKUP_NAME.tar.gz"
@@ -1,12 +0,0 @@
1
- #!/bin/bash
2
-
3
- # SpecGen Package Deployment Script
4
- echo "๐Ÿ“ฆ Making files executable..."
5
-
6
- # Make all shell scripts executable
7
- find scripts -name "*.sh" -exec chmod +x {} \;
8
-
9
- # Make CLI executable
10
- chmod +x bin/cli.js
11
-
12
- echo "โœ… All scripts are now executable"
@@ -1,88 +0,0 @@
1
- #!/bin/bash
2
-
3
- # SpecGen Troubleshooting Script
4
- echo "๐Ÿ” SpecGen Troubleshooting"
5
- echo "========================="
6
-
7
- # Check Node.js and npm
8
- echo "๐Ÿ“ฆ Node.js/npm versions:"
9
- node -v
10
- npm -v
11
- echo ""
12
-
13
- # Check if packages are extracted
14
- echo "๐Ÿ“ Component directories:"
15
- for dir in server admin user; do
16
- if [ -d "$dir" ]; then
17
- echo " โœ“ $dir exists"
18
- if [ -f "$dir/package.json" ]; then
19
- version=$(cat "$dir/package.json" | grep '"version"' | sed 's/.*"version": "\([^"]*\)".*/\1/')
20
- echo " Version: $version"
21
- fi
22
- else
23
- echo " โŒ $dir missing - run npm run setup"
24
- fi
25
- done
26
- echo ""
27
-
28
- # Check environment files
29
- echo "๐Ÿ”ง Environment files:"
30
- if [ -f "server/.env" ]; then
31
- if grep -q "your_openai_api_key_here" server/.env; then
32
- echo " โš ๏ธ server/.env needs OpenAI API key"
33
- else
34
- echo " โœ“ server/.env configured"
35
- fi
36
- else
37
- echo " โŒ server/.env missing"
38
- fi
39
-
40
- for dir in admin user; do
41
- if [ -f "$dir/.env.development" ]; then
42
- echo " โœ“ $dir/.env.development exists"
43
- else
44
- echo " โŒ $dir/.env.development missing"
45
- fi
46
- done
47
- echo ""
48
-
49
- # Check port availability
50
- echo "๐ŸŒ Port status:"
51
- for port in 3000 3001 3002; do
52
- if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
53
- process=$(lsof -Pi :$port -sTCP:LISTEN -t | xargs ps -o comm= -p)
54
- echo " โŒ Port $port in use by: $process"
55
- else
56
- echo " โœ“ Port $port available"
57
- fi
58
- done
59
- echo ""
60
-
61
- # Check dependencies
62
- echo "๐Ÿ“š Dependencies:"
63
- for dir in server admin user; do
64
- if [ -d "$dir/node_modules" ]; then
65
- echo " โœ“ $dir/node_modules exists"
66
- else
67
- echo " โŒ $dir/node_modules missing - run: cd $dir && npm install"
68
- fi
69
- done
70
- echo ""
71
-
72
- # Check for common CSS/styling issues
73
- echo "๐ŸŽจ CSS and Build files:"
74
- for dir in admin user; do
75
- if [ -d "$dir" ]; then
76
- echo " $dir:"
77
- if [ -f "$dir/src/index.css" ]; then
78
- echo " โœ“ index.css exists"
79
- else
80
- echo " โŒ index.css missing"
81
- fi
82
- if [ -f "$dir/tailwind.config.js" ]; then
83
- echo " โœ“ tailwind.config.js exists"
84
- else
85
- echo " โš ๏ธ tailwind.config.js missing (may be normal)"
86
- fi
87
- fi
88
- done
package/scripts/update.sh DELETED
@@ -1,72 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Update SpecGen to latest versions
4
- set -e
5
-
6
- echo "Updating SpecGen application..."
7
-
8
- # Backup current deployment
9
- echo "Creating backup..."
10
- sudo cp -r /opt/specgen-app /opt/specgen-app-backup-$(date +%Y%m%d-%H%M%S)
11
-
12
- # Stop services
13
- echo "Stopping services..."
14
- pm2 stop specgen-server
15
-
16
- # Navigate to app directory
17
- cd /opt/specgen-app
18
-
19
- # Download latest packages
20
- echo "Downloading latest packages..."
21
- npm pack @gv-sh/specgen-server
22
- npm pack @gv-sh/specgen-admin
23
- npm pack @gv-sh/specgen-user
24
-
25
- # Backup existing components
26
- sudo mv server server-backup || true
27
- sudo mv admin admin-backup || true
28
- sudo mv user user-backup || true
29
-
30
- # Extract new packages
31
- echo "Extracting new packages..."
32
- tar -xzf gv-sh-specgen-server-*.tgz && mv package server
33
- tar -xzf gv-sh-specgen-admin-*.tgz && mv package admin
34
- tar -xzf gv-sh-specgen-user-*.tgz && mv package user
35
-
36
- # Clean up tgz files
37
- rm -f *.tgz
38
-
39
- # Patch package.json files to fix scripts
40
- echo "Patching package scripts..."
41
- chmod +x scripts/patch-packages.sh
42
- ./scripts/patch-packages.sh
43
-
44
- # Copy environment files from backup
45
- echo "Restoring environment files..."
46
- sudo cp server-backup/.env server/.env || echo "No server .env to restore"
47
- sudo cp admin-backup/.env.production admin/.env.production || echo "No admin .env to restore"
48
- sudo cp user-backup/.env.production user/.env.production || echo "No user .env to restore"
49
-
50
- # Install dependencies
51
- echo "Installing dependencies..."
52
- cd server && npm install --production
53
- cd ../admin && npm install --production
54
- cd ../user && npm install --production
55
- cd ..
56
-
57
- # Build React apps
58
- echo "Building React applications..."
59
- cd admin && NODE_ENV=production npm run build
60
- cd ../user && NODE_ENV=production npm run build
61
- cd ..
62
-
63
- # Start services
64
- echo "Starting services..."
65
- pm2 start ecosystem.config.js
66
-
67
- # Clean up old backups (keep last 3)
68
- echo "Cleaning up old component backups..."
69
- sudo rm -rf server-backup admin-backup user-backup
70
-
71
- echo "Update completed successfully!"
72
- echo "Check logs with: pm2 logs specgen-server"