@dream-encode/wp-build-tools
v0.9.1
Published
Some scripts to help handle builds, releases, testing, etc.
Readme
WP Build Tools
Some scripts to help handle builds, releases, testing, etc.
Prerequisites
The release script automatically detects and uses the best available tools on your platform (Windows, macOS, Linux).
Required Tools
- Git - Version control operations
- GitHub CLI (gh) - Creating GitHub releases (install & authenticate:
gh auth login) - jq - JSON processing
- Compression tool - One of: 7z, zip
Optional Tools
- WP-CLI - Translation file updates (install)
- Node.js/npm/yarn - For block plugins
- Composer - For PHP dependencies
Quick Install Commands
# Windows (via Chocolatey)
choco install git jq 7zip gh
# macOS (via Homebrew)
brew install git jq p7zip gh
# Linux (Ubuntu/Debian)
sudo apt install git jq p7zip-full
# Install GitHub CLI: https://github.com/cli/cli/blob/trunk/docs/install_linux.mdAutomatic Setup
After installing wp-build-tools, it will automatically offer to configure your project:
npm install --save-dev @dream-encode/wp-build-tools
# Automatically prompts to add "release": "wp-release" and "zip": "wp-zip" to package.jsonManual Setup
npx @dream-encode/wp-build-tools setup # Interactive setup
npx @dream-encode/wp-build-tools setup --force # Automatic setupCheck Tool Availability
wp-release --check-tools # Verify all tools are installed
wp-release --test # Run comprehensive tests
wp-release --dry-run patch # Test release process without git operationsUsage
Basic Commands
# Interactive release (prompts for version bump type selection)
wp-release
# Specific version bumps
wp-release patch # 1.0.0 → 1.0.1 (bug fixes)
wp-release minor # 1.0.0 → 1.1.0 (new features)
wp-release major # 1.0.0 → 2.0.0 (breaking changes)
wp-release hotfix # 1.0.0 → 1.0.0.1 (critical fixes)
# Tool management
wp-release --check-tools # Check if all required tools are installed
wp-release --test # Run comprehensive compatibility and readiness tests
wp-release --dry-run patch # Test release process without git operations
wp-release --help # Show detailed help
wp-release --version # Show version infoZIP Creation Commands
# Interactive ZIP creation (prompts for type selection)
wp-zip
# Create installation ZIP (files at root)
wp-zip --for-install
# Create versioned ZIP for Git Updater
wp-zip --for-git-updater
# Silent mode (returns only file path)
wp-zip --quiet
# Show help
wp-zip --helpUsing npm/yarn scripts (alternative)
# If you have npm scripts configured
npm run release # Interactive release
npm run zip # Interactive ZIP creation
yarn release # Interactive release
yarn zip # Interactive ZIP creationWhat the release script does
Pre-release validation
- Checks for Ray debugging code
- Validates git repository state
- Ensures working directory is clean
Project type detection
- Detects if this is a regular plugin, theme, or block plugin
- Applies appropriate build and packaging logic
Version management
- Interactive mode: Shows menu with version bump options (patch/minor/major/hotfix/custom)
- Command line mode: Uses specified bump type (patch/minor/major/hotfix)
- Calculates and displays new version before confirmation
- Updates version in multiple files:
package.jsoncomposer.json(if exists)block.jsonfiles (if exists)- Main plugin PHP file
- Constants files (if exists)
public/manifest.json(if exists)
Translation updates
- Updates POT files using WP-CLI (if available)
Changelog management
- Looks for "0.7.4 - [UNRELEASED]" entry at top of CHANGELOG.md
- Replaces "0.7.4 - [UNRELEASED]" with "[X.X.X.X] - YYYY-MM-DD" format
Git operations
- Commits version bump changes
- Pushes to main branch
- Creates and pushes git tag
GitHub release
- Creates GitHub release with changelog notes
- Uploads release ZIP asset (if plugin uses release assets)
Build process
- Runs production build if
productionscript exists - Falls back to
buildscript if available - Creates optimized ZIP file for distribution
- Runs production build if
ZIP Creation Tool
The wp-zip command provides standalone ZIP creation functionality for WordPress plugins and themes, separate from the full release process.
What the ZIP tool does
Project detection
- Automatically detects WordPress plugin or theme directories
- Must be run from within
/wp-content/plugins/or/wp-content/themes/directory
ZIP type selection
- For install: Creates ZIP with files at root level (standard WordPress installation format)
- For Git Updater: Creates versioned ZIP with folder structure for Git Updater plugin
Build process
- Copies files to temporary directory with proper exclusions
- Runs production build if available
- Removes development files and dependencies
File exclusions
- Automatically excludes development files (node_modules, .git, tests, etc.)
- Respects
.wp-build-exclusionsfile for custom exclusions - Uses platform-specific copy tools (robocopy, rsync, tar, cp)
Output
- Creates ZIP file in system temp directory
- Opens file location in system file manager
- Provides direct path to ZIP file
ZIP Tool Usage Examples
# Interactive mode - prompts for ZIP type
wp-zip
# Create installation ZIP
wp-zip --for-install
# Create Git Updater ZIP
wp-zip --for-git-updater
# Silent mode (for scripts)
ZIP_PATH=$(wp-zip --for-install --quiet)
echo "ZIP created at: $ZIP_PATH"Configuration
Automatic Project Setup
When you install @dream-encode/wp-build-tools in a project, it will automatically:
- Detect your project - Finds your package.json
- Analyze existing scripts - Checks for existing release scripts
- Prompt for setup - Asks permission before making changes (in interactive mode)
- Backup existing scripts - Saves any existing scripts as "release-backup" and "zip-backup"
- Add scripts - Adds
"release": "wp-release"and"zip": "wp-zip"to your package.json
Setup Options
# Interactive setup (prompts for confirmation)
npx @dream-encode/wp-build-tools setup
# Automatic setup (no prompts)
npx @dream-encode/wp-build-tools setup --force
# Skip setup entirely
NO_SETUP=1 npm install @dream-encode/wp-build-toolsWhat Gets Added
{
"scripts": {
"release": "wp-release",
"zip": "wp-zip"
}
}If you already have existing scripts, they will be backed up:
{
"scripts": {
"release": "wp-release",
"zip": "wp-zip",
"release-backup": "your-previous-release-command",
"zip-backup": "your-previous-zip-command"
}
}Release Assets
To enable ZIP asset creation, add this line to your main plugin file header:
/**
* Release Asset: true
*/Custom ZIP Exclusions
You can customize which files and directories are excluded from ZIP files by creating a .wp-build-exclusions file in your project root:
# .wp-build-exclusions
# Custom exclusions for ZIP files (one per line)
# Lines starting with # are comments
# Exclude custom directories
development
local-config
temp-files
# Exclude file patterns
*.dev
*.local
*.backup
# Exclude documentation
docs
examplesThese exclusions are added to the default exclusions (like node_modules, vendor, .git, etc.). The custom exclusions work with all compression tools (zip, 7z).
Note: The .wp-build-exclusions file itself is automatically excluded from ZIP files. The exclusions are read early in the release process to ensure the configuration file is available when needed.
Changelog Format
The script expects a CHANGELOG.md file in Keep a Changelog format with an "0.6.1 - [UNRELEASED]" entry at the top:
## 0.6.1 - [UNRELEASED]
* Added new feature
* Fixed bug
## [1.0.0] - 2024-01-15
* Initial releaseDuring release, "0.6.1 - [UNRELEASED]" will be automatically replaced with the version and date:
## [1.1.0] - 2024-01-20
* Added new feature
* Fixed bug
## [1.0.0] - 2024-01-15
* Initial releaseThen, a new "0.6.1 - [UNRELEASED]" entry will be added at the top for the next release.
Troubleshooting
Common Issues
- "jq not found" - Install jq JSON processor
- "gh not authenticated" - Run
gh auth login - "Working directory not clean" - Commit or stash changes
- "Changelog version mismatch" - Update CHANGELOG.md with correct version
Debug Mode
To see more detailed output, you can modify the script to add debug flags:
# Add to the top of release.sh after the shebang
set -x # Enable debug outputFile Structure
bin/
├── release.sh # Main release script with CLI flags
├── wp-release.js # Node.js wrapper script
├── setup.js # Setup command (npx @dream-encode/wp-build-tools setup)
└── lib/
├── platform-utils.sh # Cross-platform utilities
├── tool-checker.sh # Tool availability checking
├── general-functions.sh # General utility functions
├── git-functions.sh # Git-related functions
└── wp-functions.sh # WordPress-specific functions
scripts/
├── setup-project.js # Project setup logic
└── postinstall.js # Automatic setup after npm installCustomization
You can customize the release process by modifying the functions in the lib/ directory:
- general-functions.sh - Version bumping, file operations
- git-functions.sh - Git operations, GitHub releases
- wp-functions.sh - WordPress-specific operations, ZIP creation
Testing
wp-build-tools includes a comprehensive test suite for validating functionality before releases:
# Run full test suite (tests wp-release on Max Marine plugins/themes)
npm test
# Run quick test subset
npm run test:quick
# Clean up test sandbox
npm run test:cleanupThe test suite:
- Creates a sandbox environment (
wp-build-tools-tests) - Copies Max Marine plugins/themes for testing
- Runs wp-release in dry-run mode (no git operations)
- Validates version bumps, ZIP contents, changelog updates, etc.
- Makes zero changes to original files
See tests/README.md for detailed documentation.
Support
If you encounter issues with the release script, check:
- All prerequisites are installed and configured
- You're in the correct directory (plugin root)
- Git working directory is clean
- GitHub CLI is authenticated
- CHANGELOG.md format is correct
