@gv-sh/specgen-app 0.5.0 → 0.5.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/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"