@gv-sh/specgen-app 0.5.0 → 0.6.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.
@@ -1,9 +1,10 @@
1
1
  #!/bin/bash
2
2
 
3
- # SpecGen Production Script
3
+ # SpecGen Production Script - Low Memory, Port 8080 with Cleanup
4
4
  set -e
5
5
 
6
- echo "🚀 Starting SpecGen in production mode..."
6
+ echo "🚀 Starting SpecGen in production mode on port 8080..."
7
+ echo "🧹 Cleaning up existing processes..."
7
8
 
8
9
  # Function to check if port is available
9
10
  check_port() {
@@ -15,6 +16,37 @@ check_port() {
15
16
  fi
16
17
  }
17
18
 
19
+ # ========================================
20
+ # CLEANUP EXISTING PROCESSES
21
+ # ========================================
22
+
23
+ # Stop and cleanup PM2 processes
24
+ echo "Stopping existing PM2 processes..."
25
+ npx pm2 stop all 2>/dev/null || true
26
+ npx pm2 delete all 2>/dev/null || true
27
+
28
+ # Kill processes on ports we'll use
29
+ echo "Freeing ports..."
30
+ for port in 8080 3000 3001 3002; do
31
+ if ! check_port $port; then
32
+ echo "Port $port is in use. Attempting to free it..."
33
+ lsof -ti:$port | xargs kill -9 2>/dev/null || true
34
+ sleep 1
35
+ fi
36
+ done
37
+
38
+ # Stop nginx if it might interfere
39
+ if command -v nginx &> /dev/null && systemctl is-active --quiet nginx 2>/dev/null; then
40
+ echo "Nginx is running, checking for conflicts..."
41
+ if nginx -T 2>/dev/null | grep -q ":8080"; then
42
+ echo "⚠️ Nginx is configured to use port 8080. You may need to reconfigure nginx."
43
+ fi
44
+ fi
45
+
46
+ # ========================================
47
+ # VERIFY SETUP
48
+ # ========================================
49
+
18
50
  # Verify OpenAI API key
19
51
  if [ -f "server/.env" ]; then
20
52
  # In CI mode, skip API key validation
@@ -48,43 +80,101 @@ for dir in server admin user; do
48
80
  fi
49
81
  done
50
82
 
51
- # Check if dependencies are installed
52
- for dir in server admin user; do
53
- if [ ! -d "$dir/node_modules" ]; then
54
- echo "Installing $dir dependencies..."
55
- cd "$dir" && npm install
56
- cd ..
57
- fi
58
- done
83
+ # ========================================
84
+ # INSTALL DEPENDENCIES
85
+ # ========================================
86
+
87
+ # Make sure node_modules exist in the server directory
88
+ if [ ! -d "server/node_modules" ]; then
89
+ echo "Installing server dependencies..."
90
+ cd server
91
+ # Create a .npmrc file that ignores engine requirements
92
+ echo "engine-strict=false" > .npmrc
93
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
94
+ cd ..
95
+ fi
59
96
 
60
97
  # Set production environment
61
98
  export NODE_ENV=production
62
99
 
63
- echo "Building web interfaces..."
64
- # Build React apps for production
65
- cd admin && npm run build && cd ..
66
- cd user && npm run build && cd ..
100
+ # ========================================
101
+ # BUILD INTERFACES
102
+ # ========================================
103
+
104
+ # Check if we need to build
105
+ if [ ! -d "admin/build" ] || [ ! -d "user/build" ]; then
106
+ echo "Building web interfaces (optimized mode)..."
107
+
108
+ # Admin build
109
+ if [ ! -d "admin/build" ]; then
110
+ echo "Building admin..."
111
+ cd admin
112
+ echo "engine-strict=false" > .npmrc
113
+ # Install only production dependencies
114
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
115
+ # Set environment for smaller build
116
+ export GENERATE_SOURCEMAP=false
117
+ export SKIP_PREFLIGHT_CHECK=true
118
+ npm run build
119
+ cd ..
120
+ fi
121
+
122
+ # User build
123
+ if [ ! -d "user/build" ]; then
124
+ echo "Building user..."
125
+ cd user
126
+ echo "engine-strict=false" > .npmrc
127
+ # Install only production dependencies
128
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
129
+ # Set environment for smaller build
130
+ export GENERATE_SOURCEMAP=false
131
+ export SKIP_PREFLIGHT_CHECK=true
132
+ npm run build
133
+ cd ..
134
+ fi
135
+ fi
136
+
137
+ # ========================================
138
+ # CONFIGURE ENVIRONMENT
139
+ # ========================================
140
+
141
+ # Update server .env to use port 8080
142
+ if [ -f "server/.env" ]; then
143
+ # Update or add PORT=8080 to .env
144
+ if grep -q "^PORT=" server/.env; then
145
+ sed -i.bak "s/^PORT=.*/PORT=8080/" server/.env
146
+ else
147
+ echo "PORT=8080" >> server/.env
148
+ fi
149
+ rm -f server/.env.bak
150
+ fi
67
151
 
68
152
  # Create production-ready .env for server
69
153
  cat > server/.env.production << EOF
70
154
  $(cat server/.env)
71
155
  NODE_ENV=production
156
+ PORT=8080
72
157
  EOF
73
158
 
74
- # Kill existing processes on required ports if needed
75
- echo "Checking ports..."
76
- for port in 3000 3001 3002; do
77
- if ! check_port $port; then
78
- echo "Port $port is in use. Attempting to free it..."
79
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
80
- sleep 1
81
- fi
82
- done
159
+ # Create logs directory
160
+ mkdir -p logs
161
+
162
+ # ========================================
163
+ # START SERVER
164
+ # ========================================
165
+
166
+ # Final port check
167
+ echo "Final check for port 8080..."
168
+ if ! check_port 8080; then
169
+ echo "Port 8080 is still in use after cleanup. Force killing..."
170
+ lsof -ti:8080 | xargs kill -9 2>/dev/null || true
171
+ sleep 2
172
+ fi
83
173
 
84
174
  # Start production server
85
- echo "Starting production server..."
175
+ echo "Starting production server on port 8080..."
86
176
  if [ "$CI" = "true" ]; then
87
177
  echo "CI mode detected - skipping server start"
88
178
  else
89
- cd server && NODE_ENV=production npm start
179
+ cd server && NODE_ENV=production PORT=8080 npm start
90
180
  fi
package/scripts/setup.sh CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/bin/bash
2
2
 
3
- # SpecGen App Setup Script
3
+ # SpecGen App Setup Script - Low Memory Default with Full Cleanup
4
4
  set -e
5
5
 
6
- echo "🚀 Setting up SpecGen App..."
6
+ echo "🚀 Setting up SpecGen App (Low Memory Mode)..."
7
+ echo "🧹 This will clean up any existing installations..."
7
8
 
8
9
  # Check Node.js
9
10
  if ! command -v npm &> /dev/null; then
@@ -25,16 +26,88 @@ safe_remove() {
25
26
  fi
26
27
  }
27
28
 
28
- # Clean existing directories with proper permission handling
29
- echo "Cleaning existing directories..."
29
+ # ========================================
30
+ # CLEANUP EXISTING INSTALLATIONS
31
+ # ========================================
32
+
33
+ echo "🧹 Cleaning up existing installations..."
34
+
35
+ # 1. Stop and remove all PM2 processes
36
+ echo "Stopping PM2 processes..."
37
+ npx pm2 stop all 2>/dev/null || true
38
+ npx pm2 delete all 2>/dev/null || true
39
+ npx pm2 kill 2>/dev/null || true
40
+
41
+ # Remove PM2 configuration files
42
+ rm -f ecosystem.config.js 2>/dev/null || true
43
+ rm -f pm2.config.js 2>/dev/null || true
44
+ rm -rf ~/.pm2/logs/* 2>/dev/null || true
45
+
46
+ # 2. Kill processes on ports we'll use
47
+ echo "Freeing up ports..."
48
+ for port in 8080 3000 3001 3002; do
49
+ if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
50
+ echo "Killing processes on port $port..."
51
+ lsof -ti:$port | xargs kill -9 2>/dev/null || true
52
+ sleep 1
53
+ fi
54
+ done
55
+
56
+ # 3. Stop nginx if running and remove specgen configs
57
+ echo "Cleaning up nginx..."
58
+ if command -v nginx &> /dev/null; then
59
+ sudo systemctl stop nginx 2>/dev/null || true
60
+
61
+ # Remove any specgen-related nginx configs
62
+ sudo rm -f /etc/nginx/sites-available/specgen* 2>/dev/null || true
63
+ sudo rm -f /etc/nginx/sites-enabled/specgen* 2>/dev/null || true
64
+ sudo rm -f /etc/nginx/conf.d/specgen* 2>/dev/null || true
65
+
66
+ # Test nginx config and restart if valid
67
+ if sudo nginx -t 2>/dev/null; then
68
+ sudo systemctl start nginx 2>/dev/null || true
69
+ else
70
+ echo "⚠️ Nginx config has issues, leaving it stopped"
71
+ fi
72
+ fi
73
+
74
+ # 4. Clean up any systemd services
75
+ echo "Cleaning up systemd services..."
76
+ if systemctl list-units --type=service | grep -q specgen; then
77
+ sudo systemctl stop specgen* 2>/dev/null || true
78
+ sudo systemctl disable specgen* 2>/dev/null || true
79
+ sudo rm -f /etc/systemd/system/specgen* 2>/dev/null || true
80
+ sudo systemctl daemon-reload 2>/dev/null || true
81
+ fi
82
+
83
+ # 5. Clean up Docker containers if any
84
+ if command -v docker &> /dev/null; then
85
+ echo "Cleaning up Docker containers..."
86
+ docker stop $(docker ps -q --filter "name=specgen") 2>/dev/null || true
87
+ docker rm $(docker ps -aq --filter "name=specgen") 2>/dev/null || true
88
+ fi
89
+
90
+ # ========================================
91
+ # CLEAN PROJECT DIRECTORIES
92
+ # ========================================
93
+
94
+ echo "Cleaning existing project directories..."
30
95
  safe_remove "server"
31
96
  safe_remove "admin"
32
97
  safe_remove "user"
98
+ safe_remove "logs"
99
+ safe_remove "node_modules"
33
100
  rm -f *.tgz package 2>/dev/null || true
101
+ rm -f *.log 2>/dev/null || true
102
+ rm -f ecosystem.config.js 2>/dev/null || true
103
+
104
+ # ========================================
105
+ # FRESH INSTALLATION
106
+ # ========================================
34
107
 
35
108
  # Install dependencies to get latest versions
36
- echo "📦 Installing dependencies..."
37
- npm install
109
+ echo "📦 Installing dependencies (low memory mode)..."
110
+ npm install --no-fund --no-audit --maxsockets=2 --loglevel=warn
38
111
 
39
112
  # Download npm packages
40
113
  echo "📦 Downloading packages..."
@@ -69,63 +142,44 @@ if [ -f "gv-sh-specgen-user-"*.tgz ]; then
69
142
  rm gv-sh-specgen-user-*.tgz
70
143
  fi
71
144
 
72
- # Patch package.json files to fix React scripts
73
- echo "🔧 Patching package scripts..."
74
-
75
- # Fix user package start script
76
- if [ -f "user/package.json" ]; then
77
- echo "Fixing user package start script..."
78
- # Replace the start script to use react-scripts instead of missing scripts/start.js
79
- 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
80
- rm -f user/package.json.bak
81
- fi
82
-
83
- # Fix admin package start script if needed
84
- if [ -f "admin/package.json" ]; then
85
- echo "Checking admin package start script..."
86
- # Check if admin has similar issue
87
- if grep -q "node scripts/start.js" admin/package.json; then
88
- echo "Fixing admin package start script..."
89
- sed -i.bak 's|node scripts/start.js|react-scripts start|g' admin/package.json
90
- rm -f admin/package.json.bak
91
- fi
92
- fi
93
-
94
- # Install dependencies for each component
95
- echo "📚 Installing dependencies..."
145
+ # Install dependencies for each component (low memory)
146
+ echo "📚 Installing dependencies (low memory mode)..."
96
147
  for dir in server admin user; do
97
148
  if [ -d "$dir" ]; then
98
149
  echo "Installing $dir dependencies..."
99
- cd "$dir" && npm install
150
+ cd "$dir"
151
+ # Create .npmrc for low memory mode
152
+ echo "engine-strict=false" > .npmrc
153
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
100
154
  cd ..
101
155
  else
102
156
  echo "⚠️ Warning: $dir directory not found"
103
157
  fi
104
158
  done
105
159
 
106
- # Setup environment files
160
+ # ========================================
161
+ # SETUP ENVIRONMENT FILES
162
+ # ========================================
163
+
107
164
  echo "🔧 Setting up environment files..."
108
165
 
109
- # Server .env
166
+ # Server .env (default to port 8080)
110
167
  if [ ! -f server/.env ] || [ "$CI" = "true" ]; then
111
168
  # If in CI mode, use a dummy key
112
169
  if [ "$CI" = "true" ]; then
113
- # If in CI environment and .env already exists, just use it
114
170
  if [ -f server/.env ]; then
115
171
  echo "Using existing .env file for CI environment"
116
172
  else
117
- # Create a CI .env file
118
173
  cat > server/.env << EOF
119
174
  OPENAI_API_KEY=sk-test1234
120
175
  NODE_ENV=test
121
- PORT=3000
176
+ PORT=8080
122
177
  EOF
123
178
  echo "Created test .env file for CI environment"
124
179
  fi
125
180
  KEY_PROVIDED=true
126
181
  else
127
182
  # Normal interactive mode
128
- # Prompt for OpenAI API key
129
183
  echo "To use SpecGen, you need an OpenAI API key."
130
184
  echo "Enter your OpenAI API key (or press enter to set it later): "
131
185
  read -r OPENAI_KEY
@@ -142,7 +196,7 @@ EOF
142
196
  # OpenAI API key
143
197
  OPENAI_API_KEY=$OPENAI_KEY
144
198
  NODE_ENV=development
145
- PORT=3000
199
+ PORT=8080
146
200
  EOF
147
201
 
148
202
  if [ "$KEY_PROVIDED" = true ]; then
@@ -156,34 +210,54 @@ fi
156
210
  # Admin .env.development
157
211
  if [ -d admin ]; then
158
212
  cat > admin/.env.development << 'EOF'
159
- REACT_APP_API_URL=http://localhost:3000
213
+ REACT_APP_API_URL=http://localhost:8080
160
214
  PORT=3001
161
215
  SKIP_PREFLIGHT_CHECK=true
162
- GENERATE_SOURCEMAP=true
216
+ GENERATE_SOURCEMAP=false
163
217
  EOF
164
218
  fi
165
219
 
166
220
  # User .env.development
167
221
  if [ -d user ]; then
168
222
  cat > user/.env.development << 'EOF'
169
- REACT_APP_API_URL=http://localhost:3000
223
+ REACT_APP_API_URL=http://localhost:8080
170
224
  PORT=3002
171
225
  SKIP_PREFLIGHT_CHECK=true
172
- GENERATE_SOURCEMAP=true
226
+ GENERATE_SOURCEMAP=false
173
227
  EOF
174
228
  fi
175
229
 
176
- echo "✅ Setup complete!"
230
+ # Create logs directory
231
+ mkdir -p logs
232
+
233
+ echo ""
234
+ echo "✅ Setup complete! All previous installations cleaned up."
235
+ echo ""
236
+ echo "🧹 Cleaned up:"
237
+ echo " - PM2 processes and configurations"
238
+ echo " - Nginx specgen configurations"
239
+ echo " - Systemd services"
240
+ echo " - Docker containers"
241
+ echo " - Old project files"
242
+ echo " - Freed ports: 8080, 3000, 3001, 3002"
177
243
  echo ""
178
244
  echo "Next steps:"
179
245
  if [ "$KEY_PROVIDED" = false ]; then
180
246
  echo "1. Add your OpenAI API key to server/.env"
181
247
  echo "2. Run 'npm run dev' to start all services"
248
+ echo "3. Or run 'npm run production' for production mode on port 8080"
182
249
  else
183
250
  echo "1. Run 'npm run dev' to start all services"
251
+ echo "2. Or run 'npm run production' for production mode on port 8080"
184
252
  fi
185
253
  echo ""
186
254
  echo "Access URLs:"
255
+ echo " 🌐 Production: http://localhost:8080 (main app)"
256
+ echo " 📱 Production User: http://localhost:8080/app"
257
+ echo " ⚙️ Production Admin: http://localhost:8080/admin"
258
+ echo " 📚 API Docs: http://localhost:8080/api-docs"
259
+ echo ""
260
+ echo "Development URLs:"
187
261
  echo " 🌐 User Interface: http://localhost:3002"
188
- echo " ⚙️ Admin Interface: http://localhost:3001"
189
- echo " 🔧 API: http://localhost:3000"
262
+ echo " ⚙️ Admin Interface: http://localhost:3001"
263
+ echo " 🔧 API: http://localhost:8080"