@gv-sh/specgen-app 0.1.6 → 0.3.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.
@@ -39,10 +39,22 @@ jobs:
39
39
  - name: Install dependencies
40
40
  run: npm install
41
41
 
42
- - name: Test setup process
42
+ - name: Test setup and production process
43
43
  run: |
44
- # Run setup to verify everything works
45
- npm run setup
44
+ # Create an automated setup process for CI environment
45
+ mkdir -p server
46
+
47
+ # Create a CI-specific .env file with a dummy API key
48
+ echo "OPENAI_API_KEY=sk-test1234\nNODE_ENV=test\nPORT=3000" > server/.env
49
+
50
+ # Run normal setup with the environment variable to indicate CI mode
51
+ CI=true npm run setup
52
+
53
+ # Make scripts executable
54
+ npm run make-executable
55
+
56
+ # Test production script in CI mode
57
+ CI=true timeout 10s ./scripts/production.sh || true
46
58
 
47
59
  # Verify all components are extracted
48
60
  if [ ! -d "server" ]; then
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.1.6-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.3.1-blue.svg)](https://github.com/gv-sh/specgen-app)
4
4
 
5
5
  A unified deployment package for the SpecGen speculative fiction generator platform.
6
6
 
@@ -16,29 +16,149 @@ A unified deployment package for the SpecGen speculative fiction generator platf
16
16
  ```bash
17
17
  npm run setup
18
18
  ```
19
+ During setup, you'll be prompted to enter your OpenAI API key.
19
20
 
20
- 2. **Add OpenAI API Key** to `server/.env`
21
+ 2. **Add OpenAI API Key** to `server/.env` if you skipped during setup
21
22
 
22
23
  3. **Start Development**:
23
24
  ```bash
24
25
  npm run dev
25
26
  ```
26
27
 
28
+ 4. **Start Production** (optimized build with API key validation):
29
+ ```bash
30
+ npm run production
31
+ ```
32
+
27
33
  ## Access URLs
28
34
 
29
35
  - User Interface: http://localhost:3002
30
36
  - Admin Interface: http://localhost:3001
31
37
  - API: http://localhost:3000
32
38
 
33
- ## Production Deployment
39
+ ## Deployment Options
40
+
41
+ ### Option 1: Quick NPM Deployment to Remote Server
42
+
43
+ If you have SSH access to a server (like an EC2 instance), this is the fastest way to deploy:
44
+
45
+ 1. **Save your SSH key** to a file (e.g., `key.pem`) and set permissions:
46
+ ```bash
47
+ chmod 400 key.pem
48
+ ```
49
+
50
+ 2. **SSH into your server**:
51
+ ```bash
52
+ ssh -i "key.pem" ubuntu@your-server-ip
53
+ ```
54
+
55
+ 3. **Install Node.js 18 or higher**:
56
+ ```bash
57
+ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
58
+ sudo apt-get install -y nodejs
59
+ ```
60
+
61
+ 4. **Install and run SpecGen**:
62
+ ```bash
63
+ # Install globally
64
+ sudo npm install -g @gv-sh/specgen-app
65
+
66
+ # Create and enter project directory
67
+ mkdir specgen
68
+ cd specgen
69
+
70
+ # Run the setup
71
+ npx @gv-sh/specgen-app setup
72
+
73
+ # Start in production mode
74
+ npx @gv-sh/specgen-app production
75
+ ```
76
+
77
+ 5. **Keep the service running with PM2** (recommended):
78
+ ```bash
79
+ sudo npm install -g pm2
80
+ pm2 start "npx @gv-sh/specgen-app production" --name "specgen"
81
+ pm2 startup
82
+ pm2 save
83
+ ```
84
+
85
+ 6. **Access your application**:
86
+ - User Interface: http://your-server-ip:3000
87
+ - Admin Interface: http://your-server-ip:3000/admin
88
+
89
+ ### Option 2: NPM Package Deployment (Detailed)
90
+
91
+ #### Local Machine Deployment
92
+
93
+ 1. **Install globally** (recommended for deployment):
94
+ ```bash
95
+ npm install -g @gv-sh/specgen-app
96
+ ```
97
+
98
+ 2. **Create a project directory**:
99
+ ```bash
100
+ mkdir specgen-project
101
+ cd specgen-project
102
+ ```
103
+
104
+ 3. **Initialize and setup**:
105
+ ```bash
106
+ npx @gv-sh/specgen-app setup
107
+ ```
108
+ During setup, you'll be prompted to enter your OpenAI API key.
109
+
110
+ 4. **Start the application**:
111
+ - Development mode: `npx @gv-sh/specgen-app dev`
112
+ - Production mode: `npx @gv-sh/specgen-app production`
113
+
114
+ #### Remote Server Deployment
115
+
116
+ 1. **SSH into your server**:
117
+ ```bash
118
+ ssh -i "your-key.pem" username@your-server
119
+ ```
120
+
121
+ 2. **Install Node.js** (if not already installed):
122
+ ```bash
123
+ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
124
+ sudo apt-get install -y nodejs
125
+ ```
126
+
127
+ 3. **Create a project directory**:
128
+ ```bash
129
+ mkdir specgen
130
+ cd specgen
131
+ ```
132
+
133
+ 4. **Install SpecGen**:
134
+ ```bash
135
+ npm install @gv-sh/specgen-app
136
+ ```
34
137
 
35
- ### Build
138
+ 5. **Setup the application**:
139
+ ```bash
140
+ npx @gv-sh/specgen-app setup
141
+ ```
142
+
143
+ 6. **Start in production mode**:
144
+ ```bash
145
+ npx @gv-sh/specgen-app production
146
+ ```
147
+
148
+ ### Option 3: Manual Deployment
149
+
150
+ Alternatively, you can deploy manually using the repository:
151
+
152
+ #### Build and Run Locally
36
153
  ```bash
154
+ git clone https://github.com/gv-sh/specgen-app.git
155
+ cd specgen-app
156
+ npm run setup
37
157
  npm run build
38
- npm start
158
+ npm run production
39
159
  ```
40
160
 
41
- ### AWS Deployment
161
+ #### AWS Deployment Script
42
162
 
43
163
  1. Launch Ubuntu 22.04 instance with SSH access
44
164
  2. Run deployment script:
@@ -52,6 +172,19 @@ sudo ./deploy.sh
52
172
 
53
173
  ## Management Commands
54
174
 
175
+ When using NPM global installation:
176
+ ```bash
177
+ # Check status
178
+ npx @gv-sh/specgen-app status
179
+
180
+ # Stop services
181
+ npx @gv-sh/specgen-app stop
182
+
183
+ # Update to latest version
184
+ npm update -g @gv-sh/specgen-app
185
+ ```
186
+
187
+ When using the repository:
55
188
  ```bash
56
189
  # Stop services
57
190
  npm run deploy:stop
@@ -74,6 +207,10 @@ npm run deploy:backup
74
207
  If you encounter issues:
75
208
 
76
209
  ```bash
210
+ # For global NPM installation
211
+ npx @gv-sh/specgen-app troubleshoot
212
+
213
+ # For repository installation
77
214
  npm run troubleshoot
78
215
  ```
79
216
 
@@ -81,4 +218,4 @@ This will check your setup and identify common problems.
81
218
 
82
219
  ## Environment Variables
83
220
 
84
- The setup script creates necessary environment files automatically. You only need to add your OpenAI API key to `server/.env`.
221
+ The setup script creates necessary environment files automatically. You only need to add your OpenAI API key during setup or later to `server/.env`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gv-sh/specgen-app",
3
- "version": "0.1.6",
3
+ "version": "0.3.1",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,6 +8,8 @@
8
8
  "dev": "chmod +x scripts/dev.sh && ./scripts/dev.sh",
9
9
  "build": "cd admin && npm run build && cd ../user && npm run build",
10
10
  "start": "cd server && npm start",
11
+ "production": "chmod +x scripts/production.sh && ./scripts/production.sh",
12
+ "make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
11
13
  "deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
12
14
  "deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
13
15
  "deploy:restart": "chmod +x scripts/restart.sh && ./scripts/restart.sh",
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ # Make all scripts executable
4
+ chmod +x scripts/*.sh
5
+
6
+ echo "✅ All scripts are now executable"
@@ -0,0 +1,90 @@
1
+ #!/bin/bash
2
+
3
+ # SpecGen Production Script
4
+ set -e
5
+
6
+ echo "🚀 Starting SpecGen in production mode..."
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
+ # 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
59
+
60
+ # Set production environment
61
+ export NODE_ENV=production
62
+
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 ..
67
+
68
+ # Create production-ready .env for server
69
+ cat > server/.env.production << EOF
70
+ $(cat server/.env)
71
+ NODE_ENV=production
72
+ EOF
73
+
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
83
+
84
+ # Start production server
85
+ echo "Starting production server..."
86
+ if [ "$CI" = "true" ]; then
87
+ echo "CI mode detected - skipping server start"
88
+ else
89
+ cd server && NODE_ENV=production npm start
90
+ fi
package/scripts/setup.sh CHANGED
@@ -107,14 +107,50 @@ done
107
107
  echo "🔧 Setting up environment files..."
108
108
 
109
109
  # Server .env
110
- if [ ! -f server/.env ]; then
111
- cat > server/.env << 'EOF'
112
- # Add your OpenAI API key here
113
- OPENAI_API_KEY=your_openai_api_key_here
110
+ if [ ! -f server/.env ] || [ "$CI" = "true" ]; then
111
+ # If in CI mode, use a dummy key
112
+ if [ "$CI" = "true" ]; then
113
+ # If in CI environment and .env already exists, just use it
114
+ if [ -f server/.env ]; then
115
+ echo "Using existing .env file for CI environment"
116
+ else
117
+ # Create a CI .env file
118
+ cat > server/.env << EOF
119
+ OPENAI_API_KEY=sk-test1234
120
+ NODE_ENV=test
121
+ PORT=3000
122
+ EOF
123
+ echo "Created test .env file for CI environment"
124
+ fi
125
+ KEY_PROVIDED=true
126
+ else
127
+ # Normal interactive mode
128
+ # Prompt for OpenAI API key
129
+ echo "To use SpecGen, you need an OpenAI API key."
130
+ echo "Enter your OpenAI API key (or press enter to set it later): "
131
+ read -r OPENAI_KEY
132
+
133
+ # If key is provided, use it, otherwise use placeholder
134
+ if [ -z "$OPENAI_KEY" ]; then
135
+ OPENAI_KEY="your_openai_api_key_here"
136
+ KEY_PROVIDED=false
137
+ else
138
+ KEY_PROVIDED=true
139
+ fi
140
+
141
+ cat > server/.env << EOF
142
+ # OpenAI API key
143
+ OPENAI_API_KEY=$OPENAI_KEY
114
144
  NODE_ENV=development
115
145
  PORT=3000
116
146
  EOF
117
- echo "Created server/.env - Please add your OpenAI API key"
147
+
148
+ if [ "$KEY_PROVIDED" = true ]; then
149
+ echo "✅ OpenAI API key saved to server/.env"
150
+ else
151
+ echo "⚠️ No OpenAI API key provided. You'll need to add it later to server/.env"
152
+ fi
153
+ fi
118
154
  fi
119
155
 
120
156
  # Admin .env.development
@@ -140,8 +176,12 @@ fi
140
176
  echo "✅ Setup complete!"
141
177
  echo ""
142
178
  echo "Next steps:"
143
- echo "1. Add your OpenAI API key to server/.env"
144
- echo "2. Run 'npm run dev' to start all services"
179
+ if [ "$KEY_PROVIDED" = false ]; then
180
+ echo "1. Add your OpenAI API key to server/.env"
181
+ echo "2. Run 'npm run dev' to start all services"
182
+ else
183
+ echo "1. Run 'npm run dev' to start all services"
184
+ fi
145
185
  echo ""
146
186
  echo "Access URLs:"
147
187
  echo " 🌐 User Interface: http://localhost:3002"