@gv-sh/specgen-app 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -23
- package/bin/cli.js +89 -0
- package/index.js +14 -0
- package/package.json +8 -2
- package/scripts/make-executable.sh +13 -3
- package/scripts/production-low-memory.sh +119 -0
- package/scripts/setup-low-memory.sh +203 -0
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SpecGen App - Complete Platform
|
2
2
|
|
3
|
-
[](https://github.com/gv-sh/specgen-app)
|
4
4
|
|
5
5
|
A unified deployment package for the SpecGen speculative fiction generator platform.
|
6
6
|
|
@@ -12,6 +12,42 @@ A unified deployment package for the SpecGen speculative fiction generator platf
|
|
12
12
|
|
13
13
|
## Quick Start
|
14
14
|
|
15
|
+
### Using NPX (Recommended)
|
16
|
+
|
17
|
+
```bash
|
18
|
+
# Create and enter your project directory
|
19
|
+
mkdir specgen-project
|
20
|
+
cd specgen-project
|
21
|
+
|
22
|
+
# Run setup directly with npx
|
23
|
+
npx @gv-sh/specgen-app setup
|
24
|
+
|
25
|
+
# Start in development mode
|
26
|
+
npx @gv-sh/specgen-app dev
|
27
|
+
|
28
|
+
# Or start in production mode
|
29
|
+
npx @gv-sh/specgen-app production
|
30
|
+
```
|
31
|
+
|
32
|
+
### Low Memory Mode for Small Servers
|
33
|
+
|
34
|
+
If you're deploying on a small EC2 instance or any server with limited RAM:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
# First, add swap space to prevent out-of-memory errors
|
38
|
+
sudo fallocate -l 2G /swapfile
|
39
|
+
sudo chmod 600 /swapfile
|
40
|
+
sudo mkswap /swapfile
|
41
|
+
sudo swapon /swapfile
|
42
|
+
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
|
43
|
+
|
44
|
+
# Then use the low-memory versions of the commands
|
45
|
+
npx @gv-sh/specgen-app setup-low-memory
|
46
|
+
npx @gv-sh/specgen-app production-low-memory
|
47
|
+
```
|
48
|
+
|
49
|
+
### Using NPM Scripts
|
50
|
+
|
15
51
|
1. **Setup**:
|
16
52
|
```bash
|
17
53
|
npm run setup
|
@@ -38,7 +74,7 @@ A unified deployment package for the SpecGen speculative fiction generator platf
|
|
38
74
|
|
39
75
|
## Deployment Options
|
40
76
|
|
41
|
-
### Option 1: Quick
|
77
|
+
### Option 1: Quick NPX Deployment to Remote Server
|
42
78
|
|
43
79
|
If you have SSH access to a server (like an EC2 instance), this is the fastest way to deploy:
|
44
80
|
|
@@ -60,33 +96,39 @@ If you have SSH access to a server (like an EC2 instance), this is the fastest w
|
|
60
96
|
|
61
97
|
4. **Install and run SpecGen**:
|
62
98
|
```bash
|
63
|
-
#
|
64
|
-
sudo
|
99
|
+
# Add swap space to prevent out-of-memory errors
|
100
|
+
sudo fallocate -l 2G /swapfile
|
101
|
+
sudo chmod 600 /swapfile
|
102
|
+
sudo mkswap /swapfile
|
103
|
+
sudo swapon /swapfile
|
104
|
+
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
|
65
105
|
|
66
106
|
# Create and enter project directory
|
67
107
|
mkdir specgen
|
68
108
|
cd specgen
|
69
109
|
|
70
|
-
# Run the setup
|
71
|
-
npx @gv-sh/specgen-app setup
|
110
|
+
# Run the setup with low memory optimization
|
111
|
+
npx @gv-sh/specgen-app setup-low-memory
|
72
112
|
|
73
|
-
# Start in production mode
|
74
|
-
npx @gv-sh/specgen-app production
|
113
|
+
# Start in production mode with low memory optimization
|
114
|
+
npx @gv-sh/specgen-app production-low-memory
|
75
115
|
```
|
76
116
|
|
77
117
|
5. **Keep the service running with PM2** (recommended):
|
78
118
|
```bash
|
79
119
|
sudo npm install -g pm2
|
80
|
-
|
120
|
+
# Use the low-memory production mode with PM2
|
121
|
+
pm2 start "npx @gv-sh/specgen-app production-low-memory" --name "specgen"
|
81
122
|
pm2 startup
|
82
123
|
pm2 save
|
83
124
|
```
|
84
125
|
|
85
126
|
6. **Access your application**:
|
86
|
-
- User Interface: http://your-server-ip:
|
87
|
-
- Admin Interface: http://your-server-ip:
|
127
|
+
- User Interface: http://your-server-ip:3002
|
128
|
+
- Admin Interface: http://your-server-ip:3001
|
129
|
+
- API: http://your-server-ip:3000
|
88
130
|
|
89
|
-
### Option 2: NPM Package Deployment
|
131
|
+
### Option 2: Global NPM Package Deployment
|
90
132
|
|
91
133
|
#### Local Machine Deployment
|
92
134
|
|
@@ -103,13 +145,13 @@ If you have SSH access to a server (like an EC2 instance), this is the fastest w
|
|
103
145
|
|
104
146
|
3. **Initialize and setup**:
|
105
147
|
```bash
|
106
|
-
|
148
|
+
specgen-app setup
|
107
149
|
```
|
108
150
|
During setup, you'll be prompted to enter your OpenAI API key.
|
109
151
|
|
110
152
|
4. **Start the application**:
|
111
|
-
- Development mode: `
|
112
|
-
- Production mode: `
|
153
|
+
- Development mode: `specgen-app dev`
|
154
|
+
- Production mode: `specgen-app production`
|
113
155
|
|
114
156
|
#### Remote Server Deployment
|
115
157
|
|
@@ -130,19 +172,19 @@ If you have SSH access to a server (like an EC2 instance), this is the fastest w
|
|
130
172
|
cd specgen
|
131
173
|
```
|
132
174
|
|
133
|
-
4. **Install SpecGen**:
|
175
|
+
4. **Install SpecGen globally**:
|
134
176
|
```bash
|
135
|
-
npm install @gv-sh/specgen-app
|
177
|
+
npm install -g @gv-sh/specgen-app
|
136
178
|
```
|
137
179
|
|
138
180
|
5. **Setup the application**:
|
139
181
|
```bash
|
140
|
-
|
182
|
+
specgen-app setup
|
141
183
|
```
|
142
184
|
|
143
185
|
6. **Start in production mode**:
|
144
186
|
```bash
|
145
|
-
|
187
|
+
specgen-app production
|
146
188
|
```
|
147
189
|
|
148
190
|
### Option 3: Manual Deployment
|
@@ -172,13 +214,22 @@ sudo ./deploy.sh
|
|
172
214
|
|
173
215
|
## Management Commands
|
174
216
|
|
175
|
-
When using
|
217
|
+
When using NPX or global installation:
|
176
218
|
```bash
|
177
219
|
# Check status
|
178
|
-
npx @gv-sh/specgen-app status
|
220
|
+
npx @gv-sh/specgen-app deploy:status
|
221
|
+
# or when installed globally
|
222
|
+
specgen-app deploy:status
|
179
223
|
|
180
224
|
# Stop services
|
181
|
-
npx @gv-sh/specgen-app stop
|
225
|
+
npx @gv-sh/specgen-app deploy:stop
|
226
|
+
# or
|
227
|
+
specgen-app deploy:stop
|
228
|
+
|
229
|
+
# Restart services
|
230
|
+
npx @gv-sh/specgen-app deploy:restart
|
231
|
+
# or
|
232
|
+
specgen-app deploy:restart
|
182
233
|
|
183
234
|
# Update to latest version
|
184
235
|
npm update -g @gv-sh/specgen-app
|
@@ -202,14 +253,34 @@ npm run deploy:status
|
|
202
253
|
npm run deploy:backup
|
203
254
|
```
|
204
255
|
|
256
|
+
## Available Commands
|
257
|
+
|
258
|
+
The following commands are available when using `npx @gv-sh/specgen-app` or `specgen-app` (if installed globally):
|
259
|
+
|
260
|
+
- `setup` - Set up the SpecGen application
|
261
|
+
- `setup-low-memory` - Set up the SpecGen application with memory optimizations
|
262
|
+
- `production` - Run the application in production mode
|
263
|
+
- `production-low-memory` - Run the application in production mode with memory optimizations
|
264
|
+
- `dev` - Run the application in development mode
|
265
|
+
- `deploy` - Deploy the application
|
266
|
+
- `deploy:stop` - Stop the deployed application
|
267
|
+
- `deploy:restart` - Restart the deployed application
|
268
|
+
- `deploy:update` - Update the deployed application
|
269
|
+
- `deploy:status` - Check the status of the deployed application
|
270
|
+
- `deploy:backup` - Create a backup of the deployed application
|
271
|
+
- `troubleshoot` - Run troubleshooting checks
|
272
|
+
|
205
273
|
## Troubleshooting
|
206
274
|
|
207
275
|
If you encounter issues:
|
208
276
|
|
209
277
|
```bash
|
210
|
-
#
|
278
|
+
# Using npx
|
211
279
|
npx @gv-sh/specgen-app troubleshoot
|
212
280
|
|
281
|
+
# Using global installation
|
282
|
+
specgen-app troubleshoot
|
283
|
+
|
213
284
|
# For repository installation
|
214
285
|
npm run troubleshoot
|
215
286
|
```
|
package/bin/cli.js
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const { execSync } = require('child_process');
|
4
|
+
const path = require('path');
|
5
|
+
const fs = require('fs');
|
6
|
+
|
7
|
+
// Find the root directory of the package
|
8
|
+
const findPackageRoot = () => {
|
9
|
+
// When installed as a dependency, the package will be in node_modules/@gv-sh/specgen-app
|
10
|
+
// When running directly from the package, we're already at the root
|
11
|
+
const packageJsonPath = path.resolve(__dirname, '../package.json');
|
12
|
+
|
13
|
+
if (fs.existsSync(packageJsonPath)) {
|
14
|
+
return path.dirname(packageJsonPath);
|
15
|
+
}
|
16
|
+
|
17
|
+
throw new Error('Could not locate package root directory');
|
18
|
+
};
|
19
|
+
|
20
|
+
const runScript = (scriptName) => {
|
21
|
+
try {
|
22
|
+
const packageRoot = findPackageRoot();
|
23
|
+
process.chdir(packageRoot);
|
24
|
+
|
25
|
+
console.log(`📦 Running ${scriptName} script...`);
|
26
|
+
execSync(`npm run ${scriptName}`, { stdio: 'inherit' });
|
27
|
+
|
28
|
+
console.log(`✅ ${scriptName} completed successfully`);
|
29
|
+
} catch (error) {
|
30
|
+
console.error(`❌ Error during ${scriptName}:`, error.message);
|
31
|
+
process.exit(1);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
|
35
|
+
const command = process.argv[2];
|
36
|
+
|
37
|
+
switch (command) {
|
38
|
+
case 'setup':
|
39
|
+
runScript('setup');
|
40
|
+
break;
|
41
|
+
case 'setup-low-memory':
|
42
|
+
runScript('setup-low-memory');
|
43
|
+
break;
|
44
|
+
case 'production':
|
45
|
+
runScript('production');
|
46
|
+
break;
|
47
|
+
case 'production-low-memory':
|
48
|
+
runScript('production-low-memory');
|
49
|
+
break;
|
50
|
+
case 'dev':
|
51
|
+
runScript('dev');
|
52
|
+
break;
|
53
|
+
case 'deploy':
|
54
|
+
runScript('deploy');
|
55
|
+
break;
|
56
|
+
case 'deploy:stop':
|
57
|
+
runScript('deploy:stop');
|
58
|
+
break;
|
59
|
+
case 'deploy:restart':
|
60
|
+
runScript('deploy:restart');
|
61
|
+
break;
|
62
|
+
case 'deploy:update':
|
63
|
+
runScript('deploy:update');
|
64
|
+
break;
|
65
|
+
case 'deploy:status':
|
66
|
+
runScript('deploy:status');
|
67
|
+
break;
|
68
|
+
case 'deploy:backup':
|
69
|
+
runScript('deploy:backup');
|
70
|
+
break;
|
71
|
+
case 'troubleshoot':
|
72
|
+
runScript('troubleshoot');
|
73
|
+
break;
|
74
|
+
default:
|
75
|
+
console.log('Usage: specgen-app <command>');
|
76
|
+
console.log('\nAvailable commands:');
|
77
|
+
console.log(' setup - Set up the SpecGen application');
|
78
|
+
console.log(' setup-low-memory - Set up the SpecGen application with memory optimizations');
|
79
|
+
console.log(' production - Run the application in production mode');
|
80
|
+
console.log(' production-low-memory - Run the application in production mode with memory optimizations');
|
81
|
+
console.log(' dev - Run the application in development mode');
|
82
|
+
console.log(' deploy - Deploy the application');
|
83
|
+
console.log(' deploy:stop - Stop the deployed application');
|
84
|
+
console.log(' deploy:restart - Restart the deployed application');
|
85
|
+
console.log(' deploy:update - Update the deployed application');
|
86
|
+
console.log(' deploy:status - Check the status of the deployed application');
|
87
|
+
console.log(' deploy:backup - Create a backup of the deployed application');
|
88
|
+
console.log(' troubleshoot - Run troubleshooting checks');
|
89
|
+
}
|
package/index.js
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
// This file makes the package importable
|
2
|
+
// The main functionality is provided through the CLI
|
3
|
+
|
4
|
+
module.exports = {
|
5
|
+
version: require('./package.json').version,
|
6
|
+
description: 'SpecGen Application Package',
|
7
|
+
|
8
|
+
// Export script paths for programmatic access
|
9
|
+
scripts: {
|
10
|
+
setup: require.resolve('./scripts/setup.sh'),
|
11
|
+
dev: require.resolve('./scripts/dev.sh'),
|
12
|
+
production: require.resolve('./scripts/production.sh')
|
13
|
+
}
|
14
|
+
};
|
package/package.json
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gv-sh/specgen-app",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0",
|
4
4
|
"description": "Complete SpecGen application with server, admin, and user interfaces",
|
5
5
|
"main": "index.js",
|
6
|
+
"bin": {
|
7
|
+
"specgen-app": "./bin/cli.js"
|
8
|
+
},
|
6
9
|
"scripts": {
|
7
10
|
"setup": "chmod +x scripts/setup.sh && ./scripts/setup.sh",
|
11
|
+
"setup-low-memory": "chmod +x scripts/setup-low-memory.sh && ./scripts/setup-low-memory.sh",
|
8
12
|
"dev": "chmod +x scripts/dev.sh && ./scripts/dev.sh",
|
9
13
|
"build": "cd admin && npm run build && cd ../user && npm run build",
|
10
14
|
"start": "cd server && npm start",
|
11
15
|
"production": "chmod +x scripts/production.sh && ./scripts/production.sh",
|
16
|
+
"production-low-memory": "chmod +x scripts/production-low-memory.sh && ./scripts/production-low-memory.sh",
|
12
17
|
"make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
|
13
18
|
"deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
|
14
19
|
"deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
|
@@ -16,7 +21,8 @@
|
|
16
21
|
"deploy:update": "chmod +x scripts/update.sh && ./scripts/update.sh",
|
17
22
|
"deploy:status": "chmod +x scripts/status.sh && ./scripts/status.sh",
|
18
23
|
"deploy:backup": "chmod +x scripts/backup.sh && ./scripts/backup.sh",
|
19
|
-
"troubleshoot": "chmod +x scripts/troubleshoot.sh && ./scripts/troubleshoot.sh"
|
24
|
+
"troubleshoot": "chmod +x scripts/troubleshoot.sh && ./scripts/troubleshoot.sh",
|
25
|
+
"postinstall": "chmod +x bin/cli.js"
|
20
26
|
},
|
21
27
|
"dependencies": {
|
22
28
|
"@gv-sh/specgen-server": "0.9.0",
|
@@ -1,6 +1,16 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
#
|
4
|
-
|
3
|
+
# SpecGen Package Deployment Script
|
4
|
+
echo "📦 Making files executable..."
|
5
5
|
|
6
|
-
|
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
|
+
# Make sure the low memory scripts are executable
|
13
|
+
chmod +x scripts/setup-low-memory.sh
|
14
|
+
chmod +x scripts/production-low-memory.sh
|
15
|
+
|
16
|
+
echo "✅ All scripts are now executable"
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# SpecGen Production Script - Low Memory Version
|
4
|
+
set -e
|
5
|
+
|
6
|
+
echo "🚀 Starting SpecGen in production mode (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
|
+
# Create production-ready .env for server
|
98
|
+
cat > server/.env.production << EOF
|
99
|
+
$(cat server/.env)
|
100
|
+
NODE_ENV=production
|
101
|
+
EOF
|
102
|
+
|
103
|
+
# Kill existing processes on required ports if needed
|
104
|
+
echo "Checking ports..."
|
105
|
+
for port in 3000 3001 3002; do
|
106
|
+
if ! check_port $port; then
|
107
|
+
echo "Port $port is in use. Attempting to free it..."
|
108
|
+
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
109
|
+
sleep 1
|
110
|
+
fi
|
111
|
+
done
|
112
|
+
|
113
|
+
# Start production server
|
114
|
+
echo "Starting production server..."
|
115
|
+
if [ "$CI" = "true" ]; then
|
116
|
+
echo "CI mode detected - skipping server start"
|
117
|
+
else
|
118
|
+
cd server && NODE_ENV=production npm start
|
119
|
+
fi
|
@@ -0,0 +1,203 @@
|
|
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"
|