feature: Enhance bootstrap scripts with improved configuration handling and plugin management

This commit is contained in:
Keith Solomon
2025-11-01 11:01:57 -05:00
parent 06e4007b5e
commit 1f12dff4d2
3 changed files with 347 additions and 128 deletions

View File

@@ -1,67 +1,90 @@
# Easy WordPress Bootstrap
Easily set up a new WordPress dev environment utilizing Laravel Herd and DBngin (or other MySQL/MariaDB solutions).
Spin up a complete WordPress development site on macOS with Laravel Herd and DBngin (or any MySQL/MariaDB server) in one pass. For the Windows/PowerShell workflow, see [`windows/README-Windows.md`](windows/README-Windows.md).
One command to spin up a new WordPress project locally:
## What You Get
- Creates a project folder in your Herd workspace
- Provisions MySQL DB + user via DBngin or other MySQL/MariaDB solution.
- Generates wp-config.php with salts
- Installs WP and sets default options (Home/News, other useful pages, permalinks)
- Installs/activates plugins from `plugins.json`
- Clones theme starter (with fresh history), activates it, and initializes a clean repo
- Project directory under your Herd workspace with sanitized slug and host mapping.
- MySQL database + user created after verifying the supplied root credentials.
- Latest WordPress core, `wp-config.php` with fresh salts, permalinks set to `/%postname%/`, and Home/News pages.
- Plugin install/activation from `plugins.json`, resolved from the project folder first then the repository default.
- Starter theme cloned with shallow history, `.git` stripped, repo reinitialized, remote optionally set, and Composer/NPM build steps run when available.
- `.htaccess` seeded when Apache rewrites are missing, `bootstrap-summary.txt` written, and plugin install logs stored at `wp-content/plugin-bootstrap.log`.
- Automatic WP-CLI detection with a bundled `wp-cli.phar` fallback (`WP_CLI_PHAR` env/config override).
## Prerequisites
- macOS or [Windows](windows/README-Windows.md) (PowerShell)
- Herd installed and a workspace directory (default: `~/Herd`)
- DBngin or other MySQL/MariaDB server
- CLI tools in PATH: `wp`, `git`, `curl`, `openssl`, `mysql`, and optionally `jq`
- macOS with [Laravel Herd](https://herd.laravel.com/) configured (default workspace `~/Herd`).
- MySQL or MariaDB available locally (DBngin recommended) and the `mysql` client in `PATH`.
- CLI tools: `php`, `git`, `curl`, `openssl`, `composer`, `npm`, `mysql`, and optionally `jq` for pretty plugin output.
- Either `wp` in `PATH` or a downloadable `wp-cli.phar` placed beside the script (or in `windows/wp-cli.phar`).
## Quick Start
## Quick Start (Interactive)
1. Copy `wp-bootstraprc.example` to `~/.wp-bootstraprc` and edit values (one-time setup):
1. Copy the sample configuration (one time):
```bash
cp wp-bootstraprc.example ~/.wp-bootstraprc
```
2. (Optional) Edit `plugins.json`.
3. Run the bootstrap:
2. Review `plugins.json` (optional override per project; place your own copy in the project root if needed).
3. Make the script executable, then run it and answer prompts:
```bash
chmod +x wp-bootstrap.sh
./wp-bootstrap.sh
```
4. Answer prompts. When finished, the script prints a summary and writes `bootstrap-summary.txt`.
When the bootstrap completes, open the URL printed in the summary and check `bootstrap-summary.txt` under the project root.
## Configuration
## Non-Interactive Usage
- **Herd workspace**: set `HERD_WORKSPACE` in `~/.wp-bootstraprc`.
- **Local TLD**: set `LOCAL_TLD` (`test` by default).
- **DBngin**: set `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_ROOT_USER`, `MYSQL_ROOT_PASS`.
- **Theme starter**: set `THEME_STARTER_REPO`. The script clones shallow, removes `.git`, then re-initializes the theme repo.
- **Theme remote**: set `DEFAULT_THEME_REMOTE_ORIGIN` if you want the script to push the new theme repo automatically.
Pass values via flags (help output lists every option):
## Plugins
```bash
./wp-bootstrap.sh \
--project-name "Client Site" \
--admin-user admin \
--admin-email dev@example.com \
--theme-starter-repo git@github.com:vendor/theme.git \
--herd-workspace "$HOME/Herd" \
--local-tld test \
--mysql-host 127.0.0.1 \
--mysql-port 3306 \
--mysql-root-user root \
--mysql-root-pass secret
```
Baseline plugins are defined in `plugins.json`. Each entry accepts either a WordPress.org **slug** or a direct **zip** URL.
Any value omitted from the CLI falls back to `~/.wp-bootstraprc` or the script defaults. Supply `--help` to print the full usage guide.
> Premium/private zips: use signed/internal URLs or manually download and point to a local `/tmp/file.zip` (adjust the script to `wp plugin install /tmp/file.zip`).
## Configuration with `.wp-bootstraprc`
## Notes
The script sources `~/.wp-bootstraprc` on start. Key entries include:
- The script sets friendly permalinks (`/%postname%/`) and creates Home/News pages by default.
- Sample content is removed if present.
- A plugin install log is written to `wp-content/plugin-bootstrap.log`.
- `HERD_WORKSPACE`, `LOCAL_TLD`
- `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_ROOT_USER`, `MYSQL_ROOT_PASS`
- `DEFAULT_ADMIN_USER`, `DEFAULT_ADMIN_EMAIL`
- `THEME_STARTER_REPO`, `DEFAULT_THEME_REMOTE_ORIGIN`
- `WP_CLI_PHAR` to point at a custom `wp-cli.phar`
Environment variables exported before running the script take precedence over both CLI flags and rc defaults when they share the same name.
## Plugin Manifest
`plugins.json` accepts WordPress.org slugs or zip URLs. The script first looks for `./plugins.json` inside the target project (useful for site-specific manifests) and falls back to the repository version when absent. Premium/private zips can point to signed URLs or local files; make sure the executing user has access.
## Logs & Files Created
- `bootstrap-summary.txt` high-level run output, stored in the project root.
- `wp-content/plugin-bootstrap.log` detailed plugin installation results.
- `.htaccess` created only when missing, populated with standard WordPress rewrite rules.
## Troubleshooting
- If `wp` is not found, ensure WP-CLI is installed and available in `PATH`.
- If MySQL connection fails, confirm DBngin is running and credentials are correct in `~/.wp-bootstraprc`.
- On Windows, prefer WSL or Git Bash for best results.
- **WP-CLI missing** install `wp` globally, or download `wp-cli.phar` into the script directory and set `WP_CLI_PHAR=/path/to/wp-cli.phar`.
- **MySQL connection failures** confirm DBngin (or your server) is running, credentials match your `.wp-bootstraprc`, and the root user can create databases/users.
- **Composer/NPM not installed** the script skips dependency installation but leaves a warning in the output; install the tooling and rerun if theme assets are required.
- **Permissions** ensure the Herd workspace and MySQL socket/port are accessible to your user account.
--
DIY-first policy: keep `plugins.json` minimal. Add big off-the-shelf stacks (e.g., ecomm) only when warranted.
---
DIY-first policy: keep `plugins.json` minimal; add heavier stacks only when a project truly needs them.