@bostonuniversity/buwp-local 0.1.0

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.
@@ -0,0 +1,307 @@
1
+ # buwp-local - Project Overview
2
+
3
+ A complete **npm CLI package** for managing local WordPress development environments at Boston University. It's modeled after `@wordpress/env` (wp-env) but customized for BU's specific infrastructure needs.
4
+
5
+ ## Architecture
6
+
7
+ ### Package Structure
8
+
9
+ ```
10
+ buwp-local/
11
+ ├── bin/
12
+ │ └── buwp-local.js # CLI entry point (commander-based)
13
+ ├── lib/
14
+ │ ├── index.js # Main library exports
15
+ │ ├── config.js # Configuration management
16
+ │ ├── compose-generator.js # Docker Compose generation (uses js-yaml)
17
+ │ └── commands/
18
+ │ ├── start.js # Start environment
19
+ │ ├── stop.js # Stop environment
20
+ │ ├── destroy.js # Destroy environment
21
+ │ ├── logs.js # View logs
22
+ │ └── config.js # Config management
23
+ ├── package.json
24
+ ├── USAGE.md # User documentation
25
+ └── README.md
26
+ ```
27
+
28
+ ### Key Technologies
29
+
30
+ - **commander** - CLI framework
31
+ - **js-yaml** - Docker Compose generation
32
+ - **chalk** - Terminal colors/formatting
33
+ - **dotenv** - Environment variable management
34
+
35
+ ## How It Works
36
+
37
+ ### 1. Configuration Management (`lib/config.js`)
38
+
39
+ Loads and merges configuration from three sources (in priority order):
40
+ 1. Environment variables (`.env.local`)
41
+ 2. User config (`.buwp-local.json`)
42
+ 3. Default config
43
+
44
+ Features:
45
+ - Deep merge of configuration objects
46
+ - Validation with detailed error messages
47
+ - Sensitive data masking
48
+ - Path resolution for volume mappings
49
+
50
+ ### 2. Docker Compose Generation (`lib/compose-generator.js`)
51
+
52
+ Programmatically generates `docker-compose.yml` files based on configuration:
53
+ - Creates services: WordPress, MariaDB, Redis, S3 proxy
54
+ - Configures networking and volumes
55
+ - Injects environment variables
56
+ - Handles conditional services (can disable Redis, S3, etc.)
57
+ - Generates volume mappings from config
58
+
59
+ Generated file is placed in `.buwp-local/docker-compose.yml` (gitignored).
60
+
61
+ ### 3. CLI Commands (`bin/buwp-local.js` + `lib/commands/`)
62
+
63
+ #### `buwp-local start [options]`
64
+ - Loads configuration
65
+ - Validates config
66
+ - Generates docker-compose.yml
67
+ - Starts Docker containers
68
+ - Shows access URLs and next steps
69
+
70
+ Options:
71
+ - `--xdebug` - Enable Xdebug
72
+ - `--no-s3` - Disable S3 proxy
73
+ - `--no-redis` - Disable Redis
74
+
75
+ #### `buwp-local stop`
76
+ - Stops running containers (preserves data)
77
+
78
+ #### `buwp-local destroy [options]`
79
+ - Stops and removes containers AND volumes
80
+ - Prompts for confirmation (unless `--force`)
81
+ - **WARNING**: Deletes database data
82
+
83
+ #### `buwp-local logs [options]`
84
+ - View container logs
85
+ - `-f, --follow` - Follow log output
86
+ - `-s, --service <name>` - Show specific service logs
87
+
88
+ #### `buwp-local config [options]`
89
+ - `--init` - Create `.buwp-local.json`
90
+ - `--validate` - Validate configuration
91
+ - `--show` - Display resolved config (masks secrets)
92
+
93
+ ## Configuration File Structure
94
+
95
+ ### `.buwp-local.json` (committed to repo)
96
+
97
+ ```json
98
+ {
99
+ "image": "ghcr.io/bu-ist/bu-wp-docker-mod_shib:arm64-latest",
100
+ "hostname": "wordpress.local",
101
+ "multisite": true,
102
+ "services": {
103
+ "redis": true,
104
+ "s3proxy": true,
105
+ "shibboleth": true
106
+ },
107
+ "ports": {
108
+ "http": 80,
109
+ "https": 443,
110
+ "db": 3306,
111
+ "redis": 6379
112
+ },
113
+ "mappings": [
114
+ {
115
+ "local": "./",
116
+ "container": "/var/www/html/wp-content/plugins/my-plugin"
117
+ }
118
+ ],
119
+ "env": {
120
+ "WP_DEBUG": true,
121
+ "XDEBUG": false
122
+ }
123
+ }
124
+ ```
125
+
126
+ ### `.env.local` (NEVER committed - gitignored)
127
+
128
+ ```bash
129
+ # Database credentials
130
+ WORDPRESS_DB_PASSWORD=password
131
+ DB_ROOT_PASSWORD=rootpassword
132
+
133
+ # Shibboleth certificates
134
+ SP_ENTITY_ID=https://your-entity-id
135
+ IDP_ENTITY_ID=https://shib-test.bu.edu/idp/shibboleth
136
+ SHIB_IDP_LOGOUT=https://shib-test.bu.edu/idp/logout.jsp
137
+ SHIB_SP_KEY=your-private-key
138
+ SHIB_SP_CERT=your-certificate
139
+
140
+ # AWS credentials
141
+ S3_UPLOADS_BUCKET=your-bucket
142
+ S3_UPLOADS_REGION=us-east-1
143
+ S3_UPLOADS_ACCESS_KEY_ID=AKIA...
144
+ S3_UPLOADS_SECRET_ACCESS_KEY=secret...
145
+
146
+ # OLAP configuration
147
+ OLAP=your-olap
148
+ OLAP_ACCT_NBR=123456
149
+ OLAP_REGION=us-east-1
150
+ ```
151
+
152
+ ## Security Model
153
+
154
+ ### Current Implementation (Phase 1)
155
+ - **Environment variables** via `.env.local` (gitignored)
156
+ - **Config masking** when displaying configuration
157
+ - **Clear separation** between config (committed) and secrets (local-only)
158
+
159
+ ### Future Enhancements (Phase 2-3)
160
+ - macOS Keychain integration
161
+ - Windows Credential Manager support
162
+ - AWS SSO integration for temporary credentials
163
+ - Encrypted credential storage
164
+
165
+ ## Usage Workflow
166
+
167
+ ### For Plugin/Theme Development
168
+
169
+ 1. Clone your plugin/theme repo
170
+ 2. Install: `npm install --save-dev buwp-local`
171
+ 3. Initialize: `npx buwp-local config --init`
172
+ 4. Edit `.buwp-local.json` to map current directory to WordPress location
173
+ 5. Create `.env.local` with credentials
174
+ 6. Add hostname to `/etc/hosts`
175
+ 7. Start: `npx buwp-local start`
176
+ 8. Develop with live code sync via volume mapping
177
+
178
+ ### For Multiple Repos
179
+
180
+ Each repo can have its own `.buwp-local.json` with different:
181
+ - Hostnames (site1.local, site2.local, etc.)
182
+ - Port mappings (avoid conflicts)
183
+ - Volume mappings (different plugins/themes)
184
+ - Service configurations
185
+
186
+ ## Testing Results ✅
187
+
188
+ Tested successfully:
189
+ - [x] CLI entry point works
190
+ - [x] `config --init` creates configuration file
191
+ - [x] `config --show` displays resolved config with masking
192
+ - [x] Help command shows all available commands
193
+ - [x] Dependencies installed correctly
194
+ - [x] File structure created properly
195
+
196
+ ## What's Ready Now
197
+
198
+ ### Phase 1 Complete ✅
199
+ - [x] Full CLI infrastructure
200
+ - [x] Configuration management system
201
+ - [x] Docker Compose generation
202
+ - [x] All core commands (start, stop, destroy, logs, config)
203
+ - [x] Environment variable credential handling
204
+ - [x] Volume mapping support
205
+ - [x] Service toggles (enable/disable Redis, S3, etc.)
206
+ - [x] Comprehensive documentation
207
+
208
+ ### Ready to Test
209
+ You can now:
210
+ 1. Create a test project
211
+ 2. Install buwp-local as dependency
212
+ 3. Initialize configuration
213
+ 4. Add credentials to `.env.local`
214
+ 5. Run `npx buwp-local start`
215
+ 6. Develop against live WordPress environment
216
+
217
+ ## Next Phase Recommendations
218
+
219
+ ### Phase 2 Features
220
+ 1. **WP-CLI Proxy** - Run WP-CLI commands in container
221
+ - `npx buwp-local wp plugin list`
222
+ - `npx buwp-local wp db export`
223
+
224
+ 2. **macOS Keychain Integration**
225
+ - Use `security` command or `keytar` npm package
226
+ - Store/retrieve credentials securely
227
+ - Cross-platform support
228
+
229
+ 3. **Better Volume Sync**
230
+ - Watch for file changes
231
+ - Automatic permission fixing
232
+ - Better error messages for mapping issues
233
+
234
+ 4. **Health Checks**
235
+ - Wait for WordPress to be ready
236
+ - Database connection verification
237
+ - Service status checking
238
+
239
+ ### Phase 3 Features
240
+ 1. **Auto /etc/hosts Management** (requires sudo)
241
+ 2. **SSL Certificate Generation** (mkcert)
242
+ 3. **Preset Configurations** (common setups)
243
+ 4. **Update Management** (keep base image current)
244
+ 5. **Backup/Restore** (database snapshots)
245
+
246
+ ## Advantages Over Manual Docker Compose
247
+
248
+ 1. **Abstraction** - Users don't need to understand Docker Compose
249
+ 2. **Validation** - Config is validated before starting
250
+ 3. **Flexibility** - Easy to enable/disable services
251
+ 4. **Secrets Management** - Clear separation of config and credentials
252
+ 5. **Reproducibility** - Same environment for all team members
253
+ 6. **Version Control** - Configuration is version controlled, generated files are not
254
+ 7. **Ease of Use** - Simple commands for common tasks
255
+
256
+ ## Distribution Options
257
+
258
+ ### Option 1: Private npm Registry
259
+ - Publish to BU's internal registry
260
+ - `npm install @bu/wp-local`
261
+
262
+ ### Option 2: GitHub Packages
263
+ - Publish to GitHub Packages
264
+ - Scoped package: `@bu-ist/wp-local`
265
+
266
+ ### Option 3: Git Direct Install
267
+ - Install from Git repo: `npm install git+https://github.com/bu-ist/buwp-local.git`
268
+
269
+ ### Option 4: Local Development
270
+ - Use `npm link` for testing
271
+ - Share via file path: `npm install file:../buwp-local`
272
+
273
+ ## Testing Strategy
274
+
275
+ 1. **Unit Tests** (add in future)
276
+ - Test config merging
277
+ - Test validation logic
278
+ - Test compose generation
279
+
280
+ 2. **Integration Tests**
281
+ - Test with actual Docker
282
+ - Test full start/stop/destroy cycle
283
+ - Test with different configurations
284
+
285
+ 3. **User Testing**
286
+ - Start with 2-3 developers
287
+ - Gather feedback on UX
288
+ - Iterate on configuration schema
289
+ - Expand to larger team
290
+
291
+ ## Success Metrics
292
+
293
+ - **Setup Time**: < 10 minutes from clone to running environment
294
+ - **Support Requests**: Reduced Docker-related questions
295
+ - **Adoption Rate**: 20/20 team members using it
296
+ - **Configuration Errors**: Caught before starting Docker
297
+ - **Developer Satisfaction**: Positive feedback on ease of use
298
+
299
+ ## Current Status
300
+
301
+ **Ready for initial testing!** 🎉
302
+
303
+ The core functionality is complete. You can now:
304
+ - Test it locally with real projects
305
+ - Get feedback from a small group
306
+ - Iterate on the configuration schema
307
+ - Add Phase 2 features based on real usage
@@ -0,0 +1,234 @@
1
+ # Quick Reference - New Features
2
+
3
+ ## Smart Initialization
4
+
5
+ ### Plugin Development
6
+ ```bash
7
+ cd your-plugin-directory
8
+ buwp-local config --init --plugin
9
+ ```
10
+ Auto-creates: `./` → `/var/www/html/wp-content/plugins/your-plugin-directory`
11
+
12
+ ### Theme Development
13
+ ```bash
14
+ cd your-theme-directory
15
+ buwp-local config --init --theme
16
+ ```
17
+ Auto-creates: `./` → `/var/www/html/wp-content/themes/your-theme-directory`
18
+
19
+ ### MU-Plugin Development
20
+ ```bash
21
+ cd your-mu-plugin-directory
22
+ buwp-local config --init --mu-plugin
23
+ ```
24
+ Auto-creates: `./` → `/var/www/html/wp-content/mu-plugins/your-mu-plugin-directory`
25
+
26
+ ---
27
+
28
+ ## Multi-Project Setup
29
+
30
+ ### Quick Start - 3 Projects
31
+ ```bash
32
+ # Project 1 (default ports)
33
+ cd ~/projects/plugin-a
34
+ buwp-local config --init --plugin
35
+ buwp-local start
36
+
37
+ # Project 2 (different ports)
38
+ cd ~/projects/plugin-b
39
+ buwp-local config --init --plugin
40
+ # Edit .buwp-local.json - change http: 8081, db: 3308, redis: 6381
41
+ buwp-local start
42
+
43
+ # Project 3 (different ports)
44
+ cd ~/projects/theme-c
45
+ buwp-local config --init --theme
46
+ # Edit .buwp-local.json - change http: 8082, db: 3309, redis: 6382
47
+ buwp-local start
48
+ ```
49
+
50
+ ### Add Hostnames
51
+ ```bash
52
+ sudo bash -c 'cat >> /etc/hosts << EOF
53
+ 127.0.0.1 plugin-a.local
54
+ 127.0.0.1 plugin-b.local
55
+ 127.0.0.1 theme-c.local
56
+ EOF'
57
+ ```
58
+
59
+ ### Access Your Sites
60
+ - http://plugin-a.local
61
+ - http://plugin-b.local:8081
62
+ - http://theme-c.local:8082
63
+
64
+ ---
65
+
66
+ ## Shared Environment (Centralized Sandbox)
67
+
68
+ ### Multiple Repos, One WordPress
69
+
70
+ Set the **same `projectName`** in multiple repos to share one environment:
71
+
72
+ ```bash
73
+ # Plugin A
74
+ cd ~/projects/plugin-a
75
+ buwp-local config --init --plugin
76
+ # Edit .buwp-local.json: "projectName": "bu-sandbox"
77
+ buwp-local start
78
+
79
+ # Plugin B (joins same environment)
80
+ cd ~/projects/plugin-b
81
+ buwp-local config --init --plugin
82
+ # Edit .buwp-local.json: "projectName": "bu-sandbox" # SAME!
83
+ buwp-local start
84
+
85
+ # Both plugins now in same WordPress at http://bu-sandbox.local
86
+ ```
87
+
88
+ ### When to Use
89
+
90
+ **Isolated (Different projectName):**
91
+ - Solo development
92
+ - Independent testing
93
+ - Need clean slate
94
+
95
+ **Shared (Same projectName):**
96
+ - Integration testing
97
+ - Team collaboration
98
+ - Plugin interactions
99
+ - Full-stack development
100
+
101
+ See `SHARED_ENVIRONMENT_EXAMPLES.md` for detailed examples.
102
+
103
+ ---
104
+
105
+ ## Key Concepts
106
+
107
+ ### Project Names
108
+ - **Auto-generated** from directory name
109
+ - **Sanitized** for Docker (lowercase, alphanumeric + dash/underscore)
110
+ - **Shows in Docker Desktop** for easy identification
111
+
112
+ ### Volume Isolation
113
+ Each project gets its own:
114
+ - `{projectName}_db_data` - Database
115
+ - `{projectName}_wp_build` - WordPress files
116
+
117
+ ### Port Configuration
118
+ Default ports:
119
+ ```json
120
+ {
121
+ "ports": {
122
+ "http": 80,
123
+ "https": 443,
124
+ "db": 3306,
125
+ "redis": 6379
126
+ }
127
+ }
128
+ ```
129
+
130
+ For multiple projects, change to avoid conflicts:
131
+ ```json
132
+ {
133
+ "ports": {
134
+ "http": 8081,
135
+ "https": 8444,
136
+ "db": 3308,
137
+ "redis": 6381
138
+ }
139
+ }
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Common Commands
145
+
146
+ ```bash
147
+ # Initialize with smart mapping
148
+ buwp-local config --init --plugin
149
+
150
+ # Start project
151
+ buwp-local start
152
+
153
+ # Stop project (keeps data)
154
+ buwp-local stop
155
+
156
+ # View logs
157
+ buwp-local logs -f
158
+
159
+ # Destroy project (deletes data)
160
+ buwp-local destroy
161
+
162
+ # Show configuration
163
+ buwp-local config --show
164
+
165
+ # Validate configuration
166
+ buwp-local config --validate
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Troubleshooting
172
+
173
+ ### Port Already in Use
174
+ Edit `.buwp-local.json`:
175
+ ```json
176
+ {
177
+ "ports": {
178
+ "http": 8081, // Change from 80
179
+ "db": 3308 // Change from 3306
180
+ }
181
+ }
182
+ ```
183
+
184
+ ### Project Name Conflict
185
+ Edit `.buwp-local.json`:
186
+ ```json
187
+ {
188
+ "projectName": "my-unique-name"
189
+ }
190
+ ```
191
+
192
+ ### Check Active Projects
193
+ ```bash
194
+ docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
195
+ ```
196
+
197
+ ### List All Volumes
198
+ ```bash
199
+ docker volume ls | grep -E '(db_data|wp_build)'
200
+ ```
201
+
202
+ ---
203
+
204
+ ## Best Practices
205
+
206
+ ✅ Use smart init flags (`--plugin`, `--theme`, `--mu-plugin`)
207
+ ✅ Use descriptive directory names (they become project names)
208
+ ✅ Keep `.env.local` secret (never commit)
209
+ ✅ Assign unique ports for each project
210
+ ✅ Document your port assignments
211
+ ✅ Add all hostnames to `/etc/hosts`
212
+
213
+ ---
214
+
215
+ ## What's New
216
+
217
+ | Feature | Before | Now |
218
+ |---------|--------|-----|
219
+ | **Project Naming** | All projects called "buwp-local" | Each project has unique name |
220
+ | **Docker Desktop** | Can't distinguish projects | Clear project separation |
221
+ | **Database** | Shared between all projects | Isolated per project |
222
+ | **Volume Management** | Shared `db_data` and `wp_build` | Project-specific volumes |
223
+ | **Multi-Project** | ❌ Second project overwrites first | ✅ Multiple projects run together |
224
+ | **Configuration** | Manual path typing | Auto-generated smart mappings |
225
+ | **Setup Time** | ~5 minutes | ~30 seconds |
226
+
227
+ ---
228
+
229
+ ## Need Help?
230
+
231
+ - 📖 Full documentation: `MULTI_PROJECT_GUIDE.md`
232
+ - 🔧 Implementation details: `IMPLEMENTATION_SUMMARY.md`
233
+ - 📚 Usage guide: `USAGE.md`
234
+ - ℹ️ CLI help: `buwp-local --help`