@gv-sh/specgen-app 0.6.8 → 0.7.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/README.md +24 -24
- package/package.json +1 -1
- package/scripts/deploy.sh +51 -17
- package/scripts/deploy-8080.sh.bak +0 -104
- package/scripts/production-low-memory.sh.bak +0 -129
- package/scripts/setup-low-memory.sh.bak +0 -203
package/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# SpecGen App - Complete Platform
|
2
2
|
|
3
|
-
[](https://github.com/gv-sh/specgen-app)
|
4
4
|
|
5
|
-
A unified deployment package for the SpecGen speculative fiction generator platform. **Optimized for port
|
5
|
+
A unified deployment package for the SpecGen speculative fiction generator platform. **Optimized for port 80 deployment with low memory usage.**
|
6
6
|
|
7
7
|
## 🚀 Quick Start
|
8
8
|
|
@@ -19,7 +19,7 @@ npx @gv-sh/specgen-app deploy
|
|
19
19
|
**What this does:**
|
20
20
|
- Downloads and sets up server, admin, and user components
|
21
21
|
- Builds React frontends optimized for production
|
22
|
-
- Configures everything for port
|
22
|
+
- Configures everything for port 80
|
23
23
|
- Starts with PM2 for process management
|
24
24
|
- Prompts for OpenAI API key
|
25
25
|
|
@@ -27,12 +27,12 @@ npx @gv-sh/specgen-app deploy
|
|
27
27
|
|
28
28
|
Once deployed, access your application at:
|
29
29
|
|
30
|
-
- **Main Application**: http://your-server:
|
31
|
-
- **User Interface**: http://your-server:
|
32
|
-
- **Admin Panel**: http://your-server:
|
33
|
-
- **API Documentation**: http://your-server:
|
34
|
-
- **Health Check**: http://your-server:
|
35
|
-
- **API Endpoints**: http://your-server:
|
30
|
+
- **Main Application**: http://your-server:80/
|
31
|
+
- **User Interface**: http://your-server:80/app
|
32
|
+
- **Admin Panel**: http://your-server:80/admin
|
33
|
+
- **API Documentation**: http://your-server:80/api-docs
|
34
|
+
- **Health Check**: http://your-server:80/api/health
|
35
|
+
- **API Endpoints**: http://your-server:80/api/*
|
36
36
|
|
37
37
|
## 🖥️ Server Requirements
|
38
38
|
|
@@ -80,7 +80,7 @@ npx @gv-sh/specgen-app dev
|
|
80
80
|
**Development URLs:**
|
81
81
|
- User Interface: http://localhost:3002
|
82
82
|
- Admin Interface: http://localhost:3001
|
83
|
-
- API Server: http://localhost:
|
83
|
+
- API Server: http://localhost:80
|
84
84
|
|
85
85
|
### Method 3: Manual Deployment
|
86
86
|
|
@@ -106,7 +106,7 @@ During deployment, you'll be prompted for your OpenAI API key. You can also set
|
|
106
106
|
# Create/edit the environment file
|
107
107
|
echo "OPENAI_API_KEY=your_openai_api_key_here" > server/.env
|
108
108
|
echo "NODE_ENV=production" >> server/.env
|
109
|
-
echo "PORT=
|
109
|
+
echo "PORT=80" >> server/.env
|
110
110
|
|
111
111
|
# Restart the service
|
112
112
|
npx pm2 restart specgen --update-env
|
@@ -115,7 +115,7 @@ npx pm2 restart specgen --update-env
|
|
115
115
|
### Environment Variables
|
116
116
|
|
117
117
|
The deployment creates these configuration files:
|
118
|
-
- `server/.env` - Server configuration (port
|
118
|
+
- `server/.env` - Server configuration (port 80, API key)
|
119
119
|
- `admin/.env.development` - Admin development settings
|
120
120
|
- `user/.env.development` - User development settings
|
121
121
|
|
@@ -144,13 +144,13 @@ npx pm2 monit
|
|
144
144
|
|
145
145
|
### Common Issues and Solutions
|
146
146
|
|
147
|
-
#### 1. Port
|
147
|
+
#### 1. Port 80 Already in Use
|
148
148
|
```bash
|
149
149
|
# Check what's using the port
|
150
|
-
sudo lsof -i :
|
150
|
+
sudo lsof -i :80
|
151
151
|
|
152
152
|
# Kill the process
|
153
|
-
sudo lsof -ti:
|
153
|
+
sudo lsof -ti:80 | xargs kill -9
|
154
154
|
|
155
155
|
# Redeploy
|
156
156
|
npx @gv-sh/specgen-app deploy
|
@@ -178,7 +178,7 @@ npx pm2 env 0
|
|
178
178
|
# Update API key
|
179
179
|
echo "OPENAI_API_KEY=your_new_key_here" > server/.env
|
180
180
|
echo "NODE_ENV=production" >> server/.env
|
181
|
-
echo "PORT=
|
181
|
+
echo "PORT=80" >> server/.env
|
182
182
|
|
183
183
|
# Restart with new environment
|
184
184
|
npx pm2 restart specgen --update-env
|
@@ -211,10 +211,10 @@ sudo apt-get install -y nodejs
|
|
211
211
|
|
212
212
|
```bash
|
213
213
|
# Test API health
|
214
|
-
curl http://localhost:
|
214
|
+
curl http://localhost:80/api/health
|
215
215
|
|
216
216
|
# Test main page response
|
217
|
-
curl -I http://localhost:
|
217
|
+
curl -I http://localhost:80/
|
218
218
|
|
219
219
|
# Check server logs
|
220
220
|
npx pm2 logs specgen --lines 50
|
@@ -222,8 +222,8 @@ npx pm2 logs specgen --lines 50
|
|
222
222
|
# Check build status
|
223
223
|
ls -la */build/ 2>/dev/null || echo "No builds found"
|
224
224
|
|
225
|
-
# Check processes listening on port
|
226
|
-
sudo netstat -tlnp | grep :
|
225
|
+
# Check processes listening on port 80
|
226
|
+
sudo netstat -tlnp | grep :80
|
227
227
|
```
|
228
228
|
|
229
229
|
### Manual Build Process
|
@@ -265,14 +265,14 @@ npx pm2 start server/index.js --name specgen
|
|
265
265
|
- **Static File Serving**: Builds must complete successfully for frontend access
|
266
266
|
|
267
267
|
### AWS EC2 Specific
|
268
|
-
- **Security Groups**: Ensure port
|
268
|
+
- **Security Groups**: Ensure port 80 is open in your security group
|
269
269
|
- **Instance Type**: t2.micro may struggle with builds (t2.small recommended)
|
270
270
|
- **Storage**: Ensure at least 2GB free space for node_modules and builds
|
271
271
|
|
272
272
|
## 📚 API Documentation
|
273
273
|
|
274
274
|
Once deployed, access interactive API documentation at:
|
275
|
-
- **Swagger UI**: http://your-server:
|
275
|
+
- **Swagger UI**: http://your-server:80/api-docs
|
276
276
|
|
277
277
|
### Key API Endpoints
|
278
278
|
- `GET /api/health` - Health check and system status
|
@@ -303,7 +303,7 @@ tar -czf specgen-backup-$(date +%Y%m%d).tar.gz server/data server/.env logs/
|
|
303
303
|
## 🤝 Support
|
304
304
|
|
305
305
|
### Getting Help
|
306
|
-
- **Health Check**: Visit http://your-server:
|
306
|
+
- **Health Check**: Visit http://your-server:80/api/health
|
307
307
|
- **Logs**: Run `npx pm2 logs specgen`
|
308
308
|
- **Issues**: [GitHub Issues](https://github.com/gv-sh/specgen-app/issues)
|
309
309
|
- **Status**: Run `npx pm2 status` to check process status
|
@@ -311,7 +311,7 @@ tar -czf specgen-backup-$(date +%Y%m%d).tar.gz server/data server/.env logs/
|
|
311
311
|
### Reporting Bugs
|
312
312
|
When reporting issues, please include:
|
313
313
|
- Output of `npx pm2 logs specgen`
|
314
|
-
- Output of `curl http://localhost:
|
314
|
+
- Output of `curl http://localhost:80/api/health`
|
315
315
|
- Your server specifications (RAM, OS version, Node.js version)
|
316
316
|
- Any error messages from the deployment process
|
317
317
|
|
package/package.json
CHANGED
package/scripts/deploy.sh
CHANGED
@@ -350,6 +350,8 @@ for component in admin user; do
|
|
350
350
|
fi
|
351
351
|
done
|
352
352
|
|
353
|
+
npm install --no-save serve
|
354
|
+
|
353
355
|
# ========================================
|
354
356
|
# VERIFY BUILDS
|
355
357
|
# ========================================
|
@@ -399,26 +401,58 @@ if [ "$DRY_RUN" = true ]; then
|
|
399
401
|
else
|
400
402
|
echo "🚀 Starting PM2 deployment..."
|
401
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
|
+
|
402
415
|
cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
|
403
416
|
module.exports = {
|
404
|
-
apps: [
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
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
|
412
436
|
},
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
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
|
+
]
|
422
456
|
}
|
423
457
|
EOF
|
424
458
|
|
@@ -1,104 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# SpecGen Deploy Script - Port 80 Production Deployment
|
4
|
-
set -e
|
5
|
-
|
6
|
-
echo "🚀 Deploying SpecGen to production on port 80..."
|
7
|
-
|
8
|
-
# Function to check if port is available
|
9
|
-
check_port() {
|
10
|
-
local port=$1
|
11
|
-
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
|
12
|
-
return 1 # Port in use
|
13
|
-
else
|
14
|
-
return 0 # Port available
|
15
|
-
fi
|
16
|
-
}
|
17
|
-
|
18
|
-
# Stop existing PM2 processes
|
19
|
-
echo "Stopping existing PM2 processes..."
|
20
|
-
npx pm2 stop all 2>/dev/null || true
|
21
|
-
npx pm2 delete all 2>/dev/null || true
|
22
|
-
|
23
|
-
# Kill any processes on port 80
|
24
|
-
echo "Freeing port 80..."
|
25
|
-
if ! check_port 80; then
|
26
|
-
echo "Port 80 is in use. Attempting to free it..."
|
27
|
-
lsof -ti:80 | xargs kill -9 2>/dev/null || true
|
28
|
-
sleep 2
|
29
|
-
fi
|
30
|
-
|
31
|
-
# Run the production setup
|
32
|
-
echo "Running production setup..."
|
33
|
-
npm run production-low-memory &
|
34
|
-
SETUP_PID=$!
|
35
|
-
|
36
|
-
# Wait for setup to complete or timeout
|
37
|
-
TIMEOUT=60
|
38
|
-
COUNT=0
|
39
|
-
while [ $COUNT -lt $TIMEOUT ]; do
|
40
|
-
if ! kill -0 $SETUP_PID 2>/dev/null; then
|
41
|
-
echo "Production setup completed"
|
42
|
-
break
|
43
|
-
fi
|
44
|
-
sleep 1
|
45
|
-
COUNT=$((COUNT + 1))
|
46
|
-
done
|
47
|
-
|
48
|
-
# Kill setup process if it's still running
|
49
|
-
if kill -0 $SETUP_PID 2>/dev/null; then
|
50
|
-
echo "Setup taking too long, continuing with PM2 deployment..."
|
51
|
-
kill $SETUP_PID 2>/dev/null || true
|
52
|
-
fi
|
53
|
-
|
54
|
-
# Wait a moment for cleanup
|
55
|
-
sleep 2
|
56
|
-
|
57
|
-
# Create PM2 ecosystem configuration
|
58
|
-
echo "Creating PM2 ecosystem configuration..."
|
59
|
-
cat > ecosystem.config.js << 'EOF'
|
60
|
-
module.exports = {
|
61
|
-
apps: [{
|
62
|
-
name: 'specgen',
|
63
|
-
script: './server/index.js',
|
64
|
-
cwd: process.cwd(),
|
65
|
-
env: {
|
66
|
-
NODE_ENV: 'production',
|
67
|
-
PORT: 80
|
68
|
-
},
|
69
|
-
instances: 1,
|
70
|
-
exec_mode: 'fork',
|
71
|
-
max_memory_restart: '500M',
|
72
|
-
error_file: './logs/err.log',
|
73
|
-
out_file: './logs/out.log',
|
74
|
-
log_file: './logs/combined.log',
|
75
|
-
time: true,
|
76
|
-
watch: false,
|
77
|
-
ignore_watch: ['node_modules', 'logs', '*.log']
|
78
|
-
}]
|
79
|
-
}
|
80
|
-
EOF
|
81
|
-
|
82
|
-
# Create logs directory
|
83
|
-
mkdir -p logs
|
84
|
-
|
85
|
-
# Start with PM2
|
86
|
-
echo "Starting SpecGen with PM2 on port 80..."
|
87
|
-
NODE_ENV=production PORT=80 npx pm2 start ecosystem.config.js
|
88
|
-
|
89
|
-
# Wait for startup
|
90
|
-
sleep 5
|
91
|
-
|
92
|
-
echo ""
|
93
|
-
echo "✅ SpecGen deployment completed!"
|
94
|
-
echo ""
|
95
|
-
echo "🌐 Access your application at:"
|
96
|
-
echo " - Main page: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/"
|
97
|
-
echo " - User app: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/app"
|
98
|
-
echo " - Admin panel: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/admin"
|
99
|
-
echo " - API docs: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/api-docs"
|
100
|
-
echo " - Health check: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):80/api/health"
|
101
|
-
echo ""
|
102
|
-
echo "📊 Check status with: npx pm2 status"
|
103
|
-
echo "📝 View logs with: npx pm2 logs specgen"
|
104
|
-
echo "🔄 Restart with: npx pm2 restart specgen"
|
@@ -1,129 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# SpecGen Production Script - Port 80 Low Memory Version
|
4
|
-
set -e
|
5
|
-
|
6
|
-
echo "🚀 Starting SpecGen in production mode on port 80 (Low Memory)..."
|
7
|
-
|
8
|
-
# Function to check if port is available
|
9
|
-
check_port() {
|
10
|
-
local port=$1
|
11
|
-
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
|
12
|
-
return 1 # Port in use
|
13
|
-
else
|
14
|
-
return 0 # Port available
|
15
|
-
fi
|
16
|
-
}
|
17
|
-
|
18
|
-
# Verify OpenAI API key
|
19
|
-
if [ -f "server/.env" ]; then
|
20
|
-
# In CI mode, skip API key validation
|
21
|
-
if [ "$CI" = "true" ]; then
|
22
|
-
echo "CI mode detected - skipping API key validation"
|
23
|
-
elif grep -q "OPENAI_API_KEY=your_openai_api_key_here" server/.env; then
|
24
|
-
echo "⚠️ No OpenAI API key detected!"
|
25
|
-
echo "Enter your OpenAI API key: "
|
26
|
-
read -r OPENAI_KEY
|
27
|
-
|
28
|
-
if [ -z "$OPENAI_KEY" ]; then
|
29
|
-
echo "❌ No API key provided. Cannot start in production mode."
|
30
|
-
exit 1
|
31
|
-
else
|
32
|
-
# Update the API key in the .env file
|
33
|
-
sed -i.bak "s/OPENAI_API_KEY=.*/OPENAI_API_KEY=$OPENAI_KEY/" server/.env
|
34
|
-
rm -f server/.env.bak
|
35
|
-
echo "✅ API key updated in server/.env"
|
36
|
-
fi
|
37
|
-
fi
|
38
|
-
else
|
39
|
-
echo "❌ server/.env file not found. Run 'npm run setup' first."
|
40
|
-
exit 1
|
41
|
-
fi
|
42
|
-
|
43
|
-
# Verify directories exist
|
44
|
-
for dir in server admin user; do
|
45
|
-
if [ ! -d "$dir" ]; then
|
46
|
-
echo "❌ $dir directory not found. Run 'npm run setup' first."
|
47
|
-
exit 1
|
48
|
-
fi
|
49
|
-
done
|
50
|
-
|
51
|
-
# Make sure node_modules exist in the server directory
|
52
|
-
if [ ! -d "server/node_modules" ]; then
|
53
|
-
echo "Installing server dependencies..."
|
54
|
-
cd server
|
55
|
-
# Create a .npmrc file that ignores engine requirements
|
56
|
-
echo "engine-strict=false" > .npmrc
|
57
|
-
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
58
|
-
cd ..
|
59
|
-
fi
|
60
|
-
|
61
|
-
# Set production environment
|
62
|
-
export NODE_ENV=production
|
63
|
-
|
64
|
-
# Check if we need to build
|
65
|
-
if [ ! -d "admin/build" ] || [ ! -d "user/build" ]; then
|
66
|
-
echo "Building web interfaces (optimized mode)..."
|
67
|
-
|
68
|
-
# Admin build
|
69
|
-
if [ ! -d "admin/build" ]; then
|
70
|
-
echo "Building admin..."
|
71
|
-
cd admin
|
72
|
-
echo "engine-strict=false" > .npmrc
|
73
|
-
# Install only production dependencies
|
74
|
-
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
75
|
-
# Set environment for smaller build
|
76
|
-
export GENERATE_SOURCEMAP=false
|
77
|
-
export SKIP_PREFLIGHT_CHECK=true
|
78
|
-
npm run build
|
79
|
-
cd ..
|
80
|
-
fi
|
81
|
-
|
82
|
-
# User build
|
83
|
-
if [ ! -d "user/build" ]; then
|
84
|
-
echo "Building user..."
|
85
|
-
cd user
|
86
|
-
echo "engine-strict=false" > .npmrc
|
87
|
-
# Install only production dependencies
|
88
|
-
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
89
|
-
# Set environment for smaller build
|
90
|
-
export GENERATE_SOURCEMAP=false
|
91
|
-
export SKIP_PREFLIGHT_CHECK=true
|
92
|
-
npm run build
|
93
|
-
cd ..
|
94
|
-
fi
|
95
|
-
fi
|
96
|
-
|
97
|
-
# Update server .env to use port 80
|
98
|
-
if [ -f "server/.env" ]; then
|
99
|
-
# Update or add PORT=80 to .env
|
100
|
-
if grep -q "^PORT=" server/.env; then
|
101
|
-
sed -i.bak "s/^PORT=.*/PORT=80/" server/.env
|
102
|
-
else
|
103
|
-
echo "PORT=80" >> server/.env
|
104
|
-
fi
|
105
|
-
rm -f server/.env.bak
|
106
|
-
fi
|
107
|
-
|
108
|
-
# Create production-ready .env for server
|
109
|
-
cat > server/.env.production << EOF
|
110
|
-
$(cat server/.env)
|
111
|
-
NODE_ENV=production
|
112
|
-
PORT=80
|
113
|
-
EOF
|
114
|
-
|
115
|
-
# Kill existing processes on port 80 if needed
|
116
|
-
echo "Checking port 80..."
|
117
|
-
if ! check_port 80; then
|
118
|
-
echo "Port 80 is in use. Attempting to free it..."
|
119
|
-
lsof -ti:80 | xargs kill -9 2>/dev/null || true
|
120
|
-
sleep 2
|
121
|
-
fi
|
122
|
-
|
123
|
-
# Start production server
|
124
|
-
echo "Starting production server on port 80..."
|
125
|
-
if [ "$CI" = "true" ]; then
|
126
|
-
echo "CI mode detected - skipping server start"
|
127
|
-
else
|
128
|
-
cd server && NODE_ENV=production PORT=80 npm start
|
129
|
-
fi
|
@@ -1,203 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# SpecGen Low-Memory Setup Script
|
4
|
-
set -e
|
5
|
-
|
6
|
-
echo "🚀 Setting up SpecGen App (Low Memory Mode)..."
|
7
|
-
|
8
|
-
# Check Node.js
|
9
|
-
if ! command -v npm &> /dev/null; then
|
10
|
-
echo "❌ npm not found. Please install Node.js from https://nodejs.org/"
|
11
|
-
exit 1
|
12
|
-
fi
|
13
|
-
|
14
|
-
# Function to safely remove directories with permission handling
|
15
|
-
safe_remove() {
|
16
|
-
if [ -d "$1" ]; then
|
17
|
-
echo "Removing $1..."
|
18
|
-
chmod -R u+w "$1" 2>/dev/null || true
|
19
|
-
rm -rf "$1" 2>/dev/null || true
|
20
|
-
# If still exists, try with sudo
|
21
|
-
if [ -d "$1" ]; then
|
22
|
-
echo "Using elevated permissions to remove $1..."
|
23
|
-
sudo rm -rf "$1" 2>/dev/null || true
|
24
|
-
fi
|
25
|
-
fi
|
26
|
-
}
|
27
|
-
|
28
|
-
# Clean existing directories with proper permission handling
|
29
|
-
echo "Cleaning existing directories..."
|
30
|
-
safe_remove "server"
|
31
|
-
safe_remove "admin"
|
32
|
-
safe_remove "user"
|
33
|
-
rm -f *.tgz package 2>/dev/null || true
|
34
|
-
|
35
|
-
# Install dependencies one at a time with reduced memory usage
|
36
|
-
echo "📦 Installing dependencies (low memory mode)..."
|
37
|
-
npm install --no-fund --no-audit --ignore-scripts --production=false --maxsockets=2 --loglevel=warn
|
38
|
-
|
39
|
-
# Create a .npmrc file that ignores engine requirements
|
40
|
-
echo "engine-strict=false" > .npmrc
|
41
|
-
|
42
|
-
# Download npm packages one at a time
|
43
|
-
echo "📦 Downloading packages..."
|
44
|
-
npm pack @gv-sh/specgen-server --loglevel=warn
|
45
|
-
npm pack @gv-sh/specgen-admin --loglevel=warn
|
46
|
-
npm pack @gv-sh/specgen-user --loglevel=warn
|
47
|
-
|
48
|
-
# Extract packages
|
49
|
-
echo "📁 Extracting packages..."
|
50
|
-
|
51
|
-
# Extract server
|
52
|
-
if [ -f "gv-sh-specgen-server-"*.tgz ]; then
|
53
|
-
echo "Extracting server..."
|
54
|
-
tar -xzf gv-sh-specgen-server-*.tgz
|
55
|
-
mv package server
|
56
|
-
rm gv-sh-specgen-server-*.tgz
|
57
|
-
fi
|
58
|
-
|
59
|
-
# Extract admin
|
60
|
-
if [ -f "gv-sh-specgen-admin-"*.tgz ]; then
|
61
|
-
echo "Extracting admin..."
|
62
|
-
tar -xzf gv-sh-specgen-admin-*.tgz
|
63
|
-
mv package admin
|
64
|
-
rm gv-sh-specgen-admin-*.tgz
|
65
|
-
fi
|
66
|
-
|
67
|
-
# Extract user
|
68
|
-
if [ -f "gv-sh-specgen-user-"*.tgz ]; then
|
69
|
-
echo "Extracting user..."
|
70
|
-
tar -xzf gv-sh-specgen-user-*.tgz
|
71
|
-
mv package user
|
72
|
-
rm gv-sh-specgen-user-*.tgz
|
73
|
-
fi
|
74
|
-
|
75
|
-
# Patch package.json files to fix React scripts
|
76
|
-
echo "🔧 Patching package scripts..."
|
77
|
-
|
78
|
-
# Fix user package start script
|
79
|
-
if [ -f "user/package.json" ]; then
|
80
|
-
echo "Fixing user package start script..."
|
81
|
-
# Replace the start script to use react-scripts instead of missing scripts/start.js
|
82
|
-
sed -i.bak 's|"start": "cross-env PORT=3002 REACT_APP_API_URL=http://localhost:3000 node scripts/start.js"|"start": "cross-env PORT=3002 REACT_APP_API_URL=http://localhost:3000 react-scripts start"|g' user/package.json
|
83
|
-
rm -f user/package.json.bak
|
84
|
-
fi
|
85
|
-
|
86
|
-
# Fix admin package start script if needed
|
87
|
-
if [ -f "admin/package.json" ]; then
|
88
|
-
echo "Checking admin package start script..."
|
89
|
-
# Check if admin has similar issue
|
90
|
-
if grep -q "node scripts/start.js" admin/package.json; then
|
91
|
-
echo "Fixing admin package start script..."
|
92
|
-
sed -i.bak 's|node scripts/start.js|react-scripts start|g' admin/package.json
|
93
|
-
rm -f admin/package.json.bak
|
94
|
-
fi
|
95
|
-
fi
|
96
|
-
|
97
|
-
# Create .npmrc files with engine-strict=false in each directory
|
98
|
-
echo "Creating .npmrc files to ignore engine requirements..."
|
99
|
-
for dir in server admin user; do
|
100
|
-
if [ -d "$dir" ]; then
|
101
|
-
echo "engine-strict=false" > "$dir/.npmrc"
|
102
|
-
fi
|
103
|
-
done
|
104
|
-
|
105
|
-
# Install dependencies for each component with memory optimizations
|
106
|
-
echo "📚 Installing dependencies (low memory mode)..."
|
107
|
-
for dir in server admin user; do
|
108
|
-
if [ -d "$dir" ]; then
|
109
|
-
echo "Installing $dir dependencies..."
|
110
|
-
(cd "$dir" && npm install --no-fund --no-audit --ignore-scripts --loglevel=warn --production=false --maxsockets=2 --force --omit=dev)
|
111
|
-
else
|
112
|
-
echo "⚠️ Warning: $dir directory not found"
|
113
|
-
fi
|
114
|
-
done
|
115
|
-
|
116
|
-
# Setup environment files
|
117
|
-
echo "🔧 Setting up environment files..."
|
118
|
-
|
119
|
-
# Server .env
|
120
|
-
if [ ! -f server/.env ] || [ "$CI" = "true" ]; then
|
121
|
-
# If in CI mode, use a dummy key
|
122
|
-
if [ "$CI" = "true" ]; then
|
123
|
-
# If in CI environment and .env already exists, just use it
|
124
|
-
if [ -f server/.env ]; then
|
125
|
-
echo "Using existing .env file for CI environment"
|
126
|
-
else
|
127
|
-
# Create a CI .env file
|
128
|
-
cat > server/.env << EOF
|
129
|
-
OPENAI_API_KEY=sk-test1234
|
130
|
-
NODE_ENV=test
|
131
|
-
PORT=3000
|
132
|
-
EOF
|
133
|
-
echo "Created test .env file for CI environment"
|
134
|
-
fi
|
135
|
-
KEY_PROVIDED=true
|
136
|
-
else
|
137
|
-
# Normal interactive mode
|
138
|
-
# Prompt for OpenAI API key
|
139
|
-
echo "To use SpecGen, you need an OpenAI API key."
|
140
|
-
echo "Enter your OpenAI API key (or press enter to set it later): "
|
141
|
-
read -r OPENAI_KEY
|
142
|
-
|
143
|
-
# If key is provided, use it, otherwise use placeholder
|
144
|
-
if [ -z "$OPENAI_KEY" ]; then
|
145
|
-
OPENAI_KEY="your_openai_api_key_here"
|
146
|
-
KEY_PROVIDED=false
|
147
|
-
else
|
148
|
-
KEY_PROVIDED=true
|
149
|
-
fi
|
150
|
-
|
151
|
-
cat > server/.env << EOF
|
152
|
-
# OpenAI API key
|
153
|
-
OPENAI_API_KEY=$OPENAI_KEY
|
154
|
-
NODE_ENV=development
|
155
|
-
PORT=3000
|
156
|
-
EOF
|
157
|
-
|
158
|
-
if [ "$KEY_PROVIDED" = true ]; then
|
159
|
-
echo "✅ OpenAI API key saved to server/.env"
|
160
|
-
else
|
161
|
-
echo "⚠️ No OpenAI API key provided. You'll need to add it later to server/.env"
|
162
|
-
fi
|
163
|
-
fi
|
164
|
-
fi
|
165
|
-
|
166
|
-
# Admin .env.development
|
167
|
-
if [ -d admin ]; then
|
168
|
-
cat > admin/.env.development << 'EOF'
|
169
|
-
REACT_APP_API_URL=http://localhost:3000
|
170
|
-
PORT=3001
|
171
|
-
SKIP_PREFLIGHT_CHECK=true
|
172
|
-
GENERATE_SOURCEMAP=false
|
173
|
-
EOF
|
174
|
-
fi
|
175
|
-
|
176
|
-
# User .env.development
|
177
|
-
if [ -d user ]; then
|
178
|
-
cat > user/.env.development << 'EOF'
|
179
|
-
REACT_APP_API_URL=http://localhost:3000
|
180
|
-
PORT=3002
|
181
|
-
SKIP_PREFLIGHT_CHECK=true
|
182
|
-
GENERATE_SOURCEMAP=false
|
183
|
-
EOF
|
184
|
-
fi
|
185
|
-
|
186
|
-
echo "✅ Low-memory setup complete!"
|
187
|
-
echo ""
|
188
|
-
echo "Next steps:"
|
189
|
-
if [ "$KEY_PROVIDED" = false ]; then
|
190
|
-
echo "1. Add your OpenAI API key to server/.env"
|
191
|
-
echo "2. Use 'npm run dev' to start all services"
|
192
|
-
else
|
193
|
-
echo "1. Use 'npm run dev' to start all services"
|
194
|
-
fi
|
195
|
-
echo ""
|
196
|
-
echo "If you're deploying on a low-memory system, we recommend:"
|
197
|
-
echo "1. npm run build (to create optimized bundles)"
|
198
|
-
echo "2. npm run production (to start in production mode)"
|
199
|
-
echo ""
|
200
|
-
echo "Access URLs:"
|
201
|
-
echo " 🌐 User Interface: http://localhost:3002"
|
202
|
-
echo " ⚙️ Admin Interface: http://localhost:3001"
|
203
|
-
echo " 🔧 API: http://localhost:3000"
|