@gv-sh/specgen-app 0.8.0 โ†’ 0.13.1

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.8.0-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.13.1-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.8.0",
3
+ "version": "0.13.1",
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,130 @@
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' 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
+
51
+ echo "๐Ÿ—๏ธ Building applications..."
52
+ run_on_ec2 "
53
+ cd '$APP_DIR'
54
+
55
+ # Build admin interface with correct public URL
56
+ echo 'Building admin interface...'
57
+ cd admin && PUBLIC_URL=/admin npm run build && cd ..
58
+
59
+ # Build user interface with production API URL
60
+ echo 'Building user interface...'
61
+ cd user && npm run build && cd ..
62
+
63
+ echo 'โœ… Builds completed'
64
+ "
65
+
66
+ echo "๐Ÿ”ง Configuring environment..."
67
+
68
+ # Get OpenAI API key from local environment
69
+ OPENAI_KEY=""
70
+ if [ -f "../specgen-server/.env" ]; then
71
+ OPENAI_KEY=$(grep "OPENAI_API_KEY=" ../specgen-server/.env | cut -d'=' -f2- | tr -d '"'"'"'')
72
+ echo "โœ… Found OpenAI API key in local specgen-server/.env"
73
+ elif [ -f "server/.env" ]; then
74
+ OPENAI_KEY=$(grep "OPENAI_API_KEY=" server/.env | cut -d'=' -f2- | tr -d '"'"'"'')
75
+ echo "โœ… Found OpenAI API key in local server/.env"
76
+ else
77
+ echo "โš ๏ธ No OpenAI API key found locally, will use test key"
78
+ OPENAI_KEY="sk-test1234"
79
+ fi
80
+
81
+ run_on_ec2 "
82
+ cd '$APP_DIR'
83
+
84
+ # Create logs directory
85
+ mkdir -p logs
86
+
87
+ # Configure server environment
88
+ cat > server/.env << 'EOF'
89
+ NODE_ENV=production
90
+ PORT=80
91
+ HOST=0.0.0.0
92
+ EOF
93
+
94
+ # Add OpenAI key securely
95
+ echo 'OPENAI_API_KEY=$OPENAI_KEY' >> server/.env
96
+
97
+ echo 'Environment configured with OpenAI API key'
98
+ "
99
+
100
+ echo "๐Ÿš€ Starting application..."
101
+ run_on_ec2 "
102
+ cd '$APP_DIR'
103
+ npx pm2 start ecosystem.config.js
104
+ "
105
+
106
+ echo "โณ Waiting for startup..."
107
+ sleep 5
108
+
109
+ echo "๐Ÿงช Testing deployment..."
110
+ HEALTH_CHECK=$(run_on_ec2 "curl -s http://localhost:80/api/health | jq -r '.status' 2>/dev/null || echo 'failed'")
111
+
112
+ if [ "$HEALTH_CHECK" = "healthy" ]; then
113
+ echo "โœ… Deployment successful!"
114
+ echo ""
115
+ echo "๐ŸŒ Access your application:"
116
+ echo " User Interface: http://52.66.251.12/"
117
+ echo " Admin Panel: http://52.66.251.12/admin"
118
+ echo " API Documentation: http://52.66.251.12/api-docs"
119
+ echo " Health Check: http://52.66.251.12/api/health"
120
+ echo ""
121
+ echo "๐Ÿ“Š Server status:"
122
+ run_on_ec2 "npx pm2 status"
123
+ else
124
+ echo "โŒ Deployment failed - health check returned: $HEALTH_CHECK"
125
+ echo "๐Ÿ“‹ Checking logs..."
126
+ run_on_ec2 "npx pm2 logs specgen --lines 10"
127
+ exit 1
128
+ fi
129
+
130
+ echo "๐ŸŽ‰ SpecGen deployment completed successfully!"
package/scripts/deploy.sh CHANGED
@@ -1,490 +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
- BIND_HOST="127.0.0.1" # macOS - bind to localhost for testing
41
- elif [ "$PLATFORM" = "Linux" ]; then
42
- echo "๐Ÿง Detected Linux"
43
- PM2_CMD="npx pm2"
44
- BIND_HOST="0.0.0.0" # Linux - bind to all interfaces for public access
45
- else
46
- echo "โš ๏ธ Unknown platform: $PLATFORM"
47
- PM2_CMD="npx pm2"
48
- BIND_HOST="0.0.0.0"
49
- fi
50
-
51
- echo "๐ŸŒ Server will bind to: $BIND_HOST"
52
-
53
- # ========================================
54
- # CLEANUP (Skip in dry-run for safety)
55
- # ========================================
56
-
57
- if [ "$DRY_RUN" = false ]; then
58
- echo "๐Ÿงน Cleaning up existing installations..."
59
-
60
- # Stop and remove all PM2 processes
61
- $PM2_CMD stop all 2>/dev/null || true
62
- $PM2_CMD delete all 2>/dev/null || true
63
- $PM2_CMD kill 2>/dev/null || true
64
-
65
- # Remove old PM2 config files
66
- rm -f ecosystem.config.js 2>/dev/null || true
67
-
68
- # Kill processes on all relevant ports
69
- for port in 80 3000 3001 3002; do
70
- if ! check_port $port; then
71
- echo "Killing processes on port $port..."
72
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
73
- sleep 1
74
- fi
75
- done
76
-
77
- # Clean up old files
78
- rm -rf logs/* 2>/dev/null || true
79
- else
80
- echo "๐Ÿงช DRY RUN: Skipping cleanup (existing processes will remain)"
81
- fi
82
-
83
- # ========================================
84
- # VERIFY PREREQUISITES
85
- # ========================================
86
-
87
- echo "๐Ÿ” Checking prerequisites..."
88
-
89
- # Check Node.js version
90
- NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
91
- if [ "$DRY_RUN" = true ]; then
92
- if [ "$NODE_VERSION" -lt 18 ]; then
93
- echo "โŒ Node.js 18+ required for testing. Current version: $(node --version)"
94
- exit 1
95
- else
96
- echo "โœ… Node.js version: $(node --version)"
97
- fi
98
- else
99
- if [ "$NODE_VERSION" -lt 20 ]; then
100
- echo "โŒ Node.js 20+ required for production. Current version: $(node --version)"
101
- exit 1
102
- else
103
- echo "โœ… Node.js version: $(node --version)"
104
- fi
105
- fi
106
-
107
- echo "โœ… npm version: $(npm --version)"
108
-
109
- # ========================================
110
- # SETUP OPENAI API KEY
111
- # ========================================
112
-
113
- echo "๐Ÿ”‘ Setting up OpenAI API key..."
4
+ echo "๐Ÿš€ Deploying SpecGen..."
114
5
 
115
- if [ "$DRY_RUN" = true ]; then
116
- echo "๐Ÿงช DRY RUN: Using test API key"
117
- mkdir -p "$PROJECT_DIR/server"
118
- echo "OPENAI_API_KEY=sk-test1234567890abcdef" > "$PROJECT_DIR/server/.env"
119
- echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
120
- echo "PORT=80" >> "$PROJECT_DIR/server/.env"
121
- echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
122
- elif [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
123
- if [ "$CI" = "true" ]; then
124
- echo "CI mode - using test API key"
125
- mkdir -p "$PROJECT_DIR/server"
126
- echo "OPENAI_API_KEY=sk-test1234" > "$PROJECT_DIR/server/.env"
127
- echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
128
- echo "PORT=80" >> "$PROJECT_DIR/server/.env"
129
- echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
130
- else
131
- echo "โš ๏ธ OpenAI API key required for SpecGen to work."
132
- echo "Enter your OpenAI API key (or press Enter to use test key): "
133
- read -r OPENAI_KEY
134
-
135
- if [ -z "$OPENAI_KEY" ]; then
136
- OPENAI_KEY="sk-test1234567890abcdef"
137
- echo "Using test API key for this deployment"
138
- fi
139
-
140
- mkdir -p "$PROJECT_DIR/server"
141
- echo "OPENAI_API_KEY=$OPENAI_KEY" > "$PROJECT_DIR/server/.env"
142
- echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
143
- echo "PORT=80" >> "$PROJECT_DIR/server/.env"
144
- echo "HOST=$BIND_HOST" >> "$PROJECT_DIR/server/.env"
145
- echo "โœ… API key saved"
146
- fi
147
- fi
6
+ # Build React apps with production configuration
7
+ echo "๐Ÿ“ฆ Building applications..."
148
8
 
149
- # ========================================
150
- # BUILD APPLICATION
151
- # ========================================
9
+ # Build admin with correct public URL
10
+ echo "Building admin interface..."
11
+ cd admin && PUBLIC_URL=/admin npm run build && cd ..
152
12
 
153
- echo "๐Ÿ—๏ธ Building application components..."
154
- cd "$PROJECT_DIR"
13
+ # Build user with production API URL
14
+ echo "Building user interface..."
15
+ cd user && npm run build && cd ..
155
16
 
156
- # Install and build server
157
- if [ ! -f "server/index.js" ]; then
158
- echo "๐Ÿ“ฆ Setting up server..."
159
-
160
- rm -rf server
161
- npm pack @gv-sh/specgen-server --loglevel=warn
162
- tar -xzf gv-sh-specgen-server-*.tgz
163
-
164
- if [ -d "package" ]; then
165
- mv package server
166
- rm gv-sh-specgen-server-*.tgz
167
- echo "โœ… Server extracted successfully"
168
- else
169
- echo "โŒ Failed to extract server package"
170
- exit 1
171
- fi
172
-
173
- cd server
174
- echo "engine-strict=false" > .npmrc
175
- npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
176
- cd "$PROJECT_DIR"
177
-
178
- # Install unified server that binds to 0.0.0.0
179
- echo " ๐Ÿ”ง Installing unified server (binds to all interfaces)..."
180
- cat > server/index.js << 'EOF'
181
- // index.js - Unified server for port 80 with public binding
182
- /* global process */
183
- require('dotenv').config();
184
- const express = require('express');
185
- const cors = require('cors');
186
- const path = require('path');
187
- const errorHandler = require('./middleware/errorHandler');
17
+ # Create logs directory
18
+ mkdir -p logs
188
19
 
189
- // Initialize Express app
190
- const app = express();
191
- const PORT = process.env.PORT || 80;
192
- const HOST = process.env.HOST || '0.0.0.0'; // Bind to all interfaces by default
193
-
194
- // Middleware
195
- app.use(cors());
196
- app.use(express.json());
197
- app.use(express.urlencoded({ extended: true }));
198
-
199
- // Serve static files for admin interface at /admin
200
- const adminBuildPath = path.join(__dirname, '../admin/build');
201
- const fs = require('fs');
202
- if (fs.existsSync(adminBuildPath)) {
203
- app.use('/admin', express.static(adminBuildPath));
204
- app.get('/admin/*', (req, res) => {
205
- res.sendFile(path.join(adminBuildPath, 'index.html'));
206
- });
207
- console.log('โœ… Admin interface available at /admin');
208
- } else {
209
- console.log('โš ๏ธ Admin build not found');
210
- }
211
-
212
- // Serve static files for user interface at /app
213
- const userBuildPath = path.join(__dirname, '../user/build');
214
- if (fs.existsSync(userBuildPath)) {
215
- app.use('/app', express.static(userBuildPath));
216
- app.get('/app/*', (req, res) => {
217
- res.sendFile(path.join(userBuildPath, 'index.html'));
218
- });
219
- console.log('โœ… User interface available at /app');
220
- } else {
221
- console.log('โš ๏ธ User build not found');
222
- }
223
-
224
- // Serve user interface as default at root
225
- if (fs.existsSync(userBuildPath)) {
226
- app.use('/', express.static(userBuildPath, { index: false }));
227
- }
228
-
229
- // API Routes
230
- const categoryRoutes = require('./routes/categories');
231
- const parameterRoutes = require('./routes/parameters');
232
- const generateRoutes = require('./routes/generate');
233
- const databaseRoutes = require('./routes/database');
234
- const contentRoutes = require('./routes/content');
235
- const settingsRoutes = require('./routes/settings');
236
-
237
- app.use('/api/categories', categoryRoutes);
238
- app.use('/api/parameters', parameterRoutes);
239
- app.use('/api/generate', generateRoutes);
240
- app.use('/api/database', databaseRoutes);
241
- app.use('/api/content', contentRoutes);
242
- app.use('/api/settings', settingsRoutes);
243
-
244
- if (process.env.NODE_ENV !== 'test') {
245
- const swaggerRoutes = require('./routes/swagger');
246
- app.use('/api-docs', swaggerRoutes);
247
- }
248
-
249
- const healthRoutes = require('./routes/health');
250
- app.use('/api/health', healthRoutes);
251
-
252
- // Root route
253
- app.get('/', (req, res) => {
254
- if (fs.existsSync(userBuildPath)) {
255
- res.sendFile(path.join(userBuildPath, 'index.html'));
256
- } else {
257
- const html = `
258
- <!DOCTYPE html>
259
- <html>
260
- <head>
261
- <title>SpecGen - Running on ${HOST}:${PORT}</title>
262
- <style>
263
- body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; background: #f8f9fa; }
264
- .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); }
265
- .nav-card:hover { background-color: #f8f9fa; transform: translateY(-2px); transition: all 0.2s; }
266
- a { text-decoration: none; color: #007bff; }
267
- h1 { color: #343a40; text-align: center; }
268
- .status { color: #28a745; font-weight: bold; text-align: center; background: #d4edda; padding: 10px; border-radius: 5px; margin: 20px 0; }
269
- .binding { background: #e3f2fd; border: 1px solid #2196f3; padding: 15px; border-radius: 5px; margin: 20px 0; }
270
- </style>
271
- </head>
272
- <body>
273
- <h1>๐Ÿš€ SpecGen Platform</h1>
274
- <div class="status">โœ… Server running on ${HOST}:${PORT}</div>
275
-
276
- <div class="binding">
277
- <strong>๐ŸŒ Network Binding:</strong> ${HOST === '0.0.0.0' ? 'Public access enabled (0.0.0.0)' : 'Local access only (' + HOST + ')'}
278
- </div>
279
-
280
- <div class="nav-card">
281
- <h3><a href="/app">๐Ÿ“ฑ User Application</a></h3>
282
- <p>Main SpecGen user interface</p>
283
- </div>
284
-
285
- <div class="nav-card">
286
- <h3><a href="/admin">โš™๏ธ Admin Panel</a></h3>
287
- <p>Administrative interface</p>
288
- </div>
289
-
290
- <div class="nav-card">
291
- <h3><a href="/api-docs">๐Ÿ“š API Documentation</a></h3>
292
- <p>Interactive API documentation</p>
293
- </div>
294
-
295
- <div class="nav-card">
296
- <h3><a href="/api/health">โค๏ธ Health Check</a></h3>
297
- <p>System health monitoring</p>
298
- </div>
299
- </body>
300
- </html>`;
301
- res.send(html);
302
- }
303
- });
304
-
305
- app.use(errorHandler);
306
-
307
- if (require.main === module) {
308
- app.listen(PORT, HOST, () => {
309
- console.log(`๐Ÿš€ SpecGen server running on ${HOST}:${PORT}`);
310
- console.log(`๐Ÿ“ฑ User App: http://${HOST}:${PORT}/app`);
311
- console.log(`โš™๏ธ Admin Panel: http://${HOST}:${PORT}/admin`);
312
- console.log(`๐Ÿ“š API Docs: http://${HOST}:${PORT}/api-docs`);
313
- console.log(`โค๏ธ Health Check: http://${HOST}:${PORT}/api/health`);
314
-
315
- if (HOST === '0.0.0.0') {
316
- console.log(`๐ŸŒ Accessible from any IP address`);
317
- } else {
318
- console.log(`๐Ÿ  Local access only (${HOST})`);
319
- }
320
- });
321
- }
322
-
323
- 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
324
26
  EOF
325
- echo "โœ… Unified server installed with public binding"
326
- fi
327
27
 
328
- # Build admin and user (shortened for brevity)
329
- for component in admin user; do
330
- if [ ! -d "$component/build" ]; then
331
- echo "๐Ÿ“ฑ Building $component interface..."
332
-
333
- if [ ! -d "$component" ]; then
334
- npm pack @gv-sh/specgen-$component --loglevel=warn
335
- tar -xzf gv-sh-specgen-$component-*.tgz
336
- mv package $component
337
- rm gv-sh-specgen-$component-*.tgz
338
- fi
339
-
340
- cd $component
341
- echo "engine-strict=false" > .npmrc
342
- npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
343
-
344
- if [ "$component" = "admin" ]; then
345
- GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
346
- else
347
- GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
348
- fi
349
- 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"
350
34
  fi
351
- done
352
-
353
- npm install --no-save serve
354
-
355
- # ========================================
356
- # VERIFY BUILDS
357
- # ========================================
358
-
359
- echo "โœ… Verifying builds..."
360
- if [ ! -d "admin/build" ] || [ ! -d "user/build" ] || [ ! -f "server/index.js" ]; then
361
- echo "โŒ Build verification failed"
362
- exit 1
35
+ echo "OPENAI_API_KEY=$OPENAI_KEY" >> server/.env
363
36
  fi
364
37
 
365
- echo "๐Ÿ“ All builds completed successfully"
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
366
42
 
367
- # ========================================
368
- # DEPLOYMENT
369
- # ========================================
43
+ # Start with ecosystem config
44
+ npx pm2 start ecosystem.config.js
370
45
 
371
- if [ "$DRY_RUN" = true ]; then
372
- echo "๐Ÿงช DRY RUN: Testing server startup..."
373
- cd "$PROJECT_DIR"
374
- cp server/.env .env 2>/dev/null || true
375
-
376
- TEST_PORT=80
377
- if ! check_port $TEST_PORT; then
378
- TEST_PORT=8081
379
- fi
380
-
381
- echo " Starting test server on $BIND_HOST:$TEST_PORT for 10 seconds..."
382
- (cd server && NODE_ENV=production PORT=$TEST_PORT HOST=$BIND_HOST node index.js) &
383
- SERVER_PID=$!
384
-
385
- sleep 3
386
-
387
- echo " Testing endpoints:"
388
- if curl -s http://localhost:$TEST_PORT/api/health >/dev/null 2>&1; then
389
- echo " โœ… Health endpoint: OK"
390
- else
391
- echo " โŒ Health endpoint: FAILED"
392
- fi
393
-
394
- kill $SERVER_PID 2>/dev/null || true
395
- wait $SERVER_PID 2>/dev/null || true
396
-
397
- echo ""
398
- echo "๐ŸŽ‰ DRY RUN COMPLETED!"
399
- echo "๐Ÿš€ Ready for production deployment!"
400
-
401
- else
402
- echo "๐Ÿš€ Starting PM2 deployment..."
403
-
404
- mkdir -p logs
405
- cp server/.env .env 2>/dev/null || true
406
-
407
- # Grant Node permission to bind to port 80
408
- sudo setcap 'cap_net_bind_service=+ep' "$(which node)"
409
-
410
- # Load environment variables from .env
411
- set -o allexport
412
- source .env
413
- set +o allexport
414
-
415
- cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
416
- module.exports = {
417
- apps: [
418
- {
419
- name: 'specgen',
420
- script: '$PROJECT_DIR/server/index.js',
421
- cwd: '$PROJECT_DIR',
422
- env: {
423
- NODE_ENV: 'production',
424
- PORT: 80,
425
- HOST: '$BIND_HOST',
426
- OPENAI_API_KEY: process.env.OPENAI_API_KEY
427
- },
428
- instances: 1,
429
- exec_mode: 'fork',
430
- max_memory_restart: '500M',
431
- error_file: '$PROJECT_DIR/logs/err.log',
432
- out_file: '$PROJECT_DIR/logs/out.log',
433
- log_file: '$PROJECT_DIR/logs/combined.log',
434
- time: true,
435
- 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
- }
455
- ]
456
- }
457
- EOF
458
-
459
- mkdir -p logs
460
- cp server/.env .env 2>/dev/null || true
461
-
462
- if ! check_port 80; then
463
- lsof -ti:80 | xargs kill -9 2>/dev/null || true
464
- sleep 2
465
- fi
466
-
467
- NODE_ENV=production PORT=80 HOST=$BIND_HOST $PM2_CMD start ecosystem.config.js
468
-
469
- sleep 5
470
-
471
- if $PM2_CMD list | grep -q "online"; then
472
- PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || echo 'your-server')
473
-
474
- echo ""
475
- echo "๐ŸŽ‰ SpecGen deployment completed!"
476
- echo ""
477
- 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/"
481
- echo ""
482
- echo "๐Ÿ”ง Binding: Server is bound to $BIND_HOST (${BIND_HOST:+publicly accessible})"
483
- echo "๐Ÿ“Š Management: npx pm2 status | npx pm2 logs specgen"
484
-
485
- else
486
- echo "โŒ Deployment failed!"
487
- $PM2_CMD logs specgen --lines 10
488
- exit 1
489
- fi
490
- 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"