@gv-sh/specgen-app 0.6.2 → 0.6.3
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 +1 -1
- package/package.json +1 -1
- package/scripts/deploy.sh +63 -44
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. **Optimized for port 8080 deployment with low memory usage.**
|
6
6
|
|
package/package.json
CHANGED
package/scripts/deploy.sh
CHANGED
@@ -16,6 +16,10 @@ check_port() {
|
|
16
16
|
fi
|
17
17
|
}
|
18
18
|
|
19
|
+
# Get absolute path of current working directory
|
20
|
+
PROJECT_DIR=$(pwd)
|
21
|
+
echo "📂 Project directory: $PROJECT_DIR"
|
22
|
+
|
19
23
|
# ========================================
|
20
24
|
# FULL CLEANUP
|
21
25
|
# ========================================
|
@@ -56,16 +60,6 @@ if [ "$NODE_VERSION" -lt 20 ]; then
|
|
56
60
|
exit 1
|
57
61
|
fi
|
58
62
|
|
59
|
-
# Check if we have the required directories and files
|
60
|
-
echo "📂 Checking project structure..."
|
61
|
-
if [ ! -f "package.json" ]; then
|
62
|
-
echo "❌ package.json not found. This script must be run from the SpecGen project directory."
|
63
|
-
echo "💡 Create a directory and run this script from there:"
|
64
|
-
echo " mkdir specgen && cd specgen"
|
65
|
-
echo " npx @gv-sh/specgen-app deploy"
|
66
|
-
exit 1
|
67
|
-
fi
|
68
|
-
|
69
63
|
# ========================================
|
70
64
|
# SETUP OPENAI API KEY
|
71
65
|
# ========================================
|
@@ -73,13 +67,13 @@ fi
|
|
73
67
|
echo "🔑 Setting up OpenAI API key..."
|
74
68
|
|
75
69
|
# Check if .env exists and has API key
|
76
|
-
if [ ! -f "server/.env" ] || grep -q "your_openai_api_key_here" server/.env 2>/dev/null; then
|
70
|
+
if [ ! -f "$PROJECT_DIR/server/.env" ] || grep -q "your_openai_api_key_here" "$PROJECT_DIR/server/.env" 2>/dev/null; then
|
77
71
|
if [ "$CI" = "true" ]; then
|
78
72
|
echo "CI mode - using test API key"
|
79
|
-
mkdir -p server
|
80
|
-
echo "OPENAI_API_KEY=sk-test1234" > server/.env
|
81
|
-
echo "NODE_ENV=production" >> server/.env
|
82
|
-
echo "PORT=8080" >> server/.env
|
73
|
+
mkdir -p "$PROJECT_DIR/server"
|
74
|
+
echo "OPENAI_API_KEY=sk-test1234" > "$PROJECT_DIR/server/.env"
|
75
|
+
echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
|
76
|
+
echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
|
83
77
|
else
|
84
78
|
echo "⚠️ OpenAI API key required for SpecGen to work."
|
85
79
|
echo "Enter your OpenAI API key: "
|
@@ -90,10 +84,10 @@ if [ ! -f "server/.env" ] || grep -q "your_openai_api_key_here" server/.env 2>/d
|
|
90
84
|
exit 1
|
91
85
|
fi
|
92
86
|
|
93
|
-
mkdir -p server
|
94
|
-
echo "OPENAI_API_KEY=$OPENAI_KEY" > server/.env
|
95
|
-
echo "NODE_ENV=production" >> server/.env
|
96
|
-
echo "PORT=8080" >> server/.env
|
87
|
+
mkdir -p "$PROJECT_DIR/server"
|
88
|
+
echo "OPENAI_API_KEY=$OPENAI_KEY" > "$PROJECT_DIR/server/.env"
|
89
|
+
echo "NODE_ENV=production" >> "$PROJECT_DIR/server/.env"
|
90
|
+
echo "PORT=8080" >> "$PROJECT_DIR/server/.env"
|
97
91
|
echo "✅ API key saved"
|
98
92
|
fi
|
99
93
|
fi
|
@@ -104,6 +98,9 @@ fi
|
|
104
98
|
|
105
99
|
echo "🏗️ Building application components..."
|
106
100
|
|
101
|
+
# Navigate to project directory
|
102
|
+
cd "$PROJECT_DIR"
|
103
|
+
|
107
104
|
# Install and build server
|
108
105
|
if [ ! -d "server" ] || [ ! -d "server/node_modules" ]; then
|
109
106
|
echo "📦 Setting up server..."
|
@@ -115,7 +112,7 @@ if [ ! -d "server" ] || [ ! -d "server/node_modules" ]; then
|
|
115
112
|
cd server
|
116
113
|
echo "engine-strict=false" > .npmrc
|
117
114
|
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
118
|
-
cd
|
115
|
+
cd "$PROJECT_DIR"
|
119
116
|
fi
|
120
117
|
|
121
118
|
# Install and build admin
|
@@ -134,7 +131,7 @@ if [ ! -d "admin/build" ]; then
|
|
134
131
|
npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
|
135
132
|
# Build with proper environment variables (no cross-env needed on Linux)
|
136
133
|
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
|
137
|
-
cd
|
134
|
+
cd "$PROJECT_DIR"
|
138
135
|
fi
|
139
136
|
|
140
137
|
# Install and build user
|
@@ -153,7 +150,7 @@ if [ ! -d "user/build" ]; then
|
|
153
150
|
npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
|
154
151
|
# Build with proper environment variables (no cross-env needed on Linux)
|
155
152
|
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
|
156
|
-
cd
|
153
|
+
cd "$PROJECT_DIR"
|
157
154
|
fi
|
158
155
|
|
159
156
|
# ========================================
|
@@ -161,28 +158,35 @@ fi
|
|
161
158
|
# ========================================
|
162
159
|
|
163
160
|
echo "✅ Verifying builds..."
|
164
|
-
if [ ! -d "admin/build" ]; then
|
161
|
+
if [ ! -d "$PROJECT_DIR/admin/build" ]; then
|
165
162
|
echo "❌ Admin build failed"
|
166
|
-
ls -la admin/ || echo "Admin directory not found"
|
163
|
+
ls -la "$PROJECT_DIR/admin/" || echo "Admin directory not found"
|
167
164
|
exit 1
|
168
165
|
fi
|
169
166
|
|
170
|
-
if [ ! -d "user/build" ]; then
|
167
|
+
if [ ! -d "$PROJECT_DIR/user/build" ]; then
|
171
168
|
echo "❌ User build failed"
|
172
|
-
ls -la user/ || echo "User directory not found"
|
169
|
+
ls -la "$PROJECT_DIR/user/" || echo "User directory not found"
|
170
|
+
exit 1
|
171
|
+
fi
|
172
|
+
|
173
|
+
if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
|
174
|
+
echo "❌ Server index.js not found"
|
175
|
+
ls -la "$PROJECT_DIR/server/" || echo "Server directory not found"
|
173
176
|
exit 1
|
174
177
|
fi
|
175
178
|
|
176
179
|
echo "📁 Build verification:"
|
177
|
-
echo " Admin build: $(ls -la admin/build/ | wc -l) files"
|
178
|
-
echo " User build: $(ls -la user/build/ | wc -l) files"
|
179
|
-
echo " Server: $(ls -la server/ | wc -l) files"
|
180
|
+
echo " Admin build: $(ls -la "$PROJECT_DIR/admin/build/" | wc -l) files"
|
181
|
+
echo " User build: $(ls -la "$PROJECT_DIR/user/build/" | wc -l) files"
|
182
|
+
echo " Server: $(ls -la "$PROJECT_DIR/server/" | wc -l) files"
|
183
|
+
echo " Server script: $PROJECT_DIR/server/index.js"
|
180
184
|
|
181
185
|
# Show some sample files to verify builds
|
182
186
|
echo "📄 Admin build files:"
|
183
|
-
ls admin/build/ | head -5
|
187
|
+
ls "$PROJECT_DIR/admin/build/" | head -5
|
184
188
|
echo "📄 User build files:"
|
185
|
-
ls user/build/ | head -5
|
189
|
+
ls "$PROJECT_DIR/user/build/" | head -5
|
186
190
|
|
187
191
|
# ========================================
|
188
192
|
# PM2 DEPLOYMENT
|
@@ -190,13 +194,13 @@ ls user/build/ | head -5
|
|
190
194
|
|
191
195
|
echo "🚀 Starting PM2 deployment..."
|
192
196
|
|
193
|
-
# Create PM2 ecosystem configuration
|
194
|
-
cat > ecosystem.config.js <<
|
197
|
+
# Create PM2 ecosystem configuration with absolute paths
|
198
|
+
cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
|
195
199
|
module.exports = {
|
196
200
|
apps: [{
|
197
201
|
name: 'specgen',
|
198
|
-
script: '
|
199
|
-
cwd:
|
202
|
+
script: '$PROJECT_DIR/server/index.js',
|
203
|
+
cwd: '$PROJECT_DIR',
|
200
204
|
env: {
|
201
205
|
NODE_ENV: 'production',
|
202
206
|
PORT: 8080
|
@@ -204,9 +208,9 @@ module.exports = {
|
|
204
208
|
instances: 1,
|
205
209
|
exec_mode: 'fork',
|
206
210
|
max_memory_restart: '500M',
|
207
|
-
error_file: '
|
208
|
-
out_file: '
|
209
|
-
log_file: '
|
211
|
+
error_file: '$PROJECT_DIR/logs/err.log',
|
212
|
+
out_file: '$PROJECT_DIR/logs/out.log',
|
213
|
+
log_file: '$PROJECT_DIR/logs/combined.log',
|
210
214
|
time: true,
|
211
215
|
watch: false,
|
212
216
|
ignore_watch: ['node_modules', 'logs', '*.log'],
|
@@ -218,10 +222,10 @@ module.exports = {
|
|
218
222
|
EOF
|
219
223
|
|
220
224
|
# Create logs directory
|
221
|
-
mkdir -p logs
|
225
|
+
mkdir -p "$PROJECT_DIR/logs"
|
222
226
|
|
223
|
-
# Copy .env to
|
224
|
-
cp server/.env
|
227
|
+
# Copy .env to project root for PM2
|
228
|
+
cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
|
225
229
|
|
226
230
|
# Final port check
|
227
231
|
if ! check_port 8080; then
|
@@ -230,9 +234,21 @@ if ! check_port 8080; then
|
|
230
234
|
sleep 2
|
231
235
|
fi
|
232
236
|
|
233
|
-
#
|
237
|
+
# Change to project directory and start with PM2
|
238
|
+
cd "$PROJECT_DIR"
|
234
239
|
echo "▶️ Starting SpecGen with PM2..."
|
235
|
-
|
240
|
+
echo " Script: $PROJECT_DIR/server/index.js"
|
241
|
+
echo " Working Directory: $PROJECT_DIR"
|
242
|
+
|
243
|
+
# Verify the script exists before starting PM2
|
244
|
+
if [ ! -f "$PROJECT_DIR/server/index.js" ]; then
|
245
|
+
echo "❌ ERROR: Server script not found at $PROJECT_DIR/server/index.js"
|
246
|
+
echo "Contents of server directory:"
|
247
|
+
ls -la "$PROJECT_DIR/server/"
|
248
|
+
exit 1
|
249
|
+
fi
|
250
|
+
|
251
|
+
NODE_ENV=production PORT=8080 npx pm2 start "$PROJECT_DIR/ecosystem.config.js"
|
236
252
|
|
237
253
|
# Wait for startup and verify
|
238
254
|
sleep 5
|
@@ -259,7 +275,10 @@ if npx pm2 list | grep -q "online"; then
|
|
259
275
|
if [ "$HTTP_CODE" = "200" ]; then
|
260
276
|
echo "✅ Main page: OK (HTTP $HTTP_CODE)"
|
261
277
|
else
|
262
|
-
echo "⚠️ Main page: HTTP $HTTP_CODE
|
278
|
+
echo "⚠️ Main page: HTTP $HTTP_CODE"
|
279
|
+
# Show what the server is actually serving
|
280
|
+
echo "Response preview:"
|
281
|
+
curl -s http://localhost:8080/ | head -3
|
263
282
|
fi
|
264
283
|
|
265
284
|
# Test admin
|