@gv-sh/specgen-app 0.6.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # SpecGen App - Complete Platform
2
2
 
3
- [![Version](https://img.shields.io/badge/version-0.6.1-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.6.3-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 8080 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.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "bin": {
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
@@ -130,9 +127,11 @@ if [ ! -d "admin/build" ]; then
130
127
 
131
128
  cd admin
132
129
  echo "engine-strict=false" > .npmrc
133
- npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
130
+ # Install ALL dependencies for build process
131
+ npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
132
+ # Build with proper environment variables (no cross-env needed on Linux)
134
133
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
135
- cd ..
134
+ cd "$PROJECT_DIR"
136
135
  fi
137
136
 
138
137
  # Install and build user
@@ -147,9 +146,11 @@ if [ ! -d "user/build" ]; then
147
146
 
148
147
  cd user
149
148
  echo "engine-strict=false" > .npmrc
150
- npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
149
+ # Install ALL dependencies for build process
150
+ npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
151
+ # Build with proper environment variables (no cross-env needed on Linux)
151
152
  GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
152
- cd ..
153
+ cd "$PROJECT_DIR"
153
154
  fi
154
155
 
155
156
  # ========================================
@@ -157,20 +158,35 @@ fi
157
158
  # ========================================
158
159
 
159
160
  echo "✅ Verifying builds..."
160
- if [ ! -d "admin/build" ]; then
161
+ if [ ! -d "$PROJECT_DIR/admin/build" ]; then
161
162
  echo "❌ Admin build failed"
163
+ ls -la "$PROJECT_DIR/admin/" || echo "Admin directory not found"
162
164
  exit 1
163
165
  fi
164
166
 
165
- if [ ! -d "user/build" ]; then
167
+ if [ ! -d "$PROJECT_DIR/user/build" ]; then
166
168
  echo "❌ User build failed"
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"
167
176
  exit 1
168
177
  fi
169
178
 
170
179
  echo "📁 Build verification:"
171
- echo " Admin build: $(ls -la admin/build/ | wc -l) files"
172
- echo " User build: $(ls -la user/build/ | wc -l) files"
173
- 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"
184
+
185
+ # Show some sample files to verify builds
186
+ echo "📄 Admin build files:"
187
+ ls "$PROJECT_DIR/admin/build/" | head -5
188
+ echo "📄 User build files:"
189
+ ls "$PROJECT_DIR/user/build/" | head -5
174
190
 
175
191
  # ========================================
176
192
  # PM2 DEPLOYMENT
@@ -178,13 +194,13 @@ echo " Server: $(ls -la server/ | wc -l) files"
178
194
 
179
195
  echo "🚀 Starting PM2 deployment..."
180
196
 
181
- # Create PM2 ecosystem configuration
182
- cat > ecosystem.config.js << 'EOF'
197
+ # Create PM2 ecosystem configuration with absolute paths
198
+ cat > "$PROJECT_DIR/ecosystem.config.js" << EOF
183
199
  module.exports = {
184
200
  apps: [{
185
201
  name: 'specgen',
186
- script: './server/index.js',
187
- cwd: process.cwd(),
202
+ script: '$PROJECT_DIR/server/index.js',
203
+ cwd: '$PROJECT_DIR',
188
204
  env: {
189
205
  NODE_ENV: 'production',
190
206
  PORT: 8080
@@ -192,9 +208,9 @@ module.exports = {
192
208
  instances: 1,
193
209
  exec_mode: 'fork',
194
210
  max_memory_restart: '500M',
195
- error_file: './logs/err.log',
196
- out_file: './logs/out.log',
197
- log_file: './logs/combined.log',
211
+ error_file: '$PROJECT_DIR/logs/err.log',
212
+ out_file: '$PROJECT_DIR/logs/out.log',
213
+ log_file: '$PROJECT_DIR/logs/combined.log',
198
214
  time: true,
199
215
  watch: false,
200
216
  ignore_watch: ['node_modules', 'logs', '*.log'],
@@ -206,7 +222,10 @@ module.exports = {
206
222
  EOF
207
223
 
208
224
  # Create logs directory
209
- mkdir -p logs
225
+ mkdir -p "$PROJECT_DIR/logs"
226
+
227
+ # Copy .env to project root for PM2
228
+ cp "$PROJECT_DIR/server/.env" "$PROJECT_DIR/.env" 2>/dev/null || true
210
229
 
211
230
  # Final port check
212
231
  if ! check_port 8080; then
@@ -215,9 +234,21 @@ if ! check_port 8080; then
215
234
  sleep 2
216
235
  fi
217
236
 
218
- # Start with PM2
237
+ # Change to project directory and start with PM2
238
+ cd "$PROJECT_DIR"
219
239
  echo "▶️ Starting SpecGen with PM2..."
220
- NODE_ENV=production PORT=8080 npx pm2 start ecosystem.config.js
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"
221
252
 
222
253
  # Wait for startup and verify
223
254
  sleep 5
@@ -240,23 +271,36 @@ if npx pm2 list | grep -q "online"; then
240
271
  fi
241
272
 
242
273
  # Test main page
243
- if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ | grep -q "200"; then
244
- echo " Main page: OK"
274
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null)
275
+ if [ "$HTTP_CODE" = "200" ]; then
276
+ echo "✅ Main page: OK (HTTP $HTTP_CODE)"
245
277
  else
246
- echo "⚠️ Main page: Check logs"
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
247
282
  fi
248
283
 
249
284
  # Test admin
250
- if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin | grep -q "200"; then
251
- echo " Admin page: OK"
285
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin 2>/dev/null)
286
+ if [ "$HTTP_CODE" = "200" ]; then
287
+ echo "✅ Admin page: OK (HTTP $HTTP_CODE)"
252
288
  else
253
- echo "⚠️ Admin page: Check logs"
289
+ echo "⚠️ Admin page: HTTP $HTTP_CODE"
290
+ fi
291
+
292
+ # Test user app
293
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/app 2>/dev/null)
294
+ if [ "$HTTP_CODE" = "200" ]; then
295
+ echo "✅ User app: OK (HTTP $HTTP_CODE)"
296
+ else
297
+ echo "⚠️ User app: HTTP $HTTP_CODE"
254
298
  fi
255
299
 
256
300
  PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
257
301
 
258
302
  echo ""
259
- echo "🎉 SpecGen deployment completed successfully!"
303
+ echo "🎉 SpecGen deployment completed!"
260
304
  echo ""
261
305
  echo "🌐 Access your application at:"
262
306
  echo " - Main page: http://$PUBLIC_IP:8080/"
@@ -266,16 +310,23 @@ if npx pm2 list | grep -q "online"; then
266
310
  echo " - Health check: http://$PUBLIC_IP:8080/api/health"
267
311
  echo ""
268
312
  echo "📊 Management:"
269
- echo " npx pm2 status # Check status"
270
- echo " npx pm2 logs # View logs"
313
+ echo " npx pm2 status # Check status"
314
+ echo " npx pm2 logs specgen # View logs"
271
315
  echo " npx pm2 restart specgen # Restart"
272
316
  echo ""
317
+ echo "🔧 Troubleshooting:"
318
+ echo " curl http://localhost:8080/api/health # Test API"
319
+ echo " curl -I http://localhost:8080/ # Test main page"
320
+ echo " ls -la */build/ # Check builds"
321
+ echo ""
273
322
 
274
323
  else
275
324
  echo ""
276
325
  echo "❌ Deployment failed!"
277
326
  echo "📝 Check logs: npx pm2 logs specgen"
278
327
  echo "📊 Check status: npx pm2 status"
328
+ echo ""
329
+ echo "Recent logs:"
279
330
  npx pm2 logs specgen --lines 10
280
331
  exit 1
281
332
  fi