- .markdownlint.json: enforce MD004 asterisk style to match project conventions
- .wiki/Contributing.md: convert all dash list markers to asterisks (MD004)
- .wiki/Coding-Standards.md: fix PHPDoc bullet wording (add missing preposition)
- build.sh: add set -euo pipefail for strict error handling
- build.sh: fix SC2115 (use ${var:?} to prevent rm -rf /)
- build.sh: fix SC2164 (cd build || exit 1)
- build.sh: fix SC2028 (use printf instead of echo for escape sequences)
- build.sh: fix SC2035 (use ./*.php glob to avoid dash-named files)
Closes #46
112 lines
3.2 KiB
Bash
Executable File
112 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# WordPress Plugin Build Script
|
|
# This script creates a clean build of the plugin for distribution
|
|
|
|
# Check if version is provided
|
|
if [ -z "$1" ]; then
|
|
echo "❌ Error: Version number is required"
|
|
echo "Usage: ./build.sh <version>"
|
|
exit 1
|
|
fi
|
|
|
|
VERSION=$1
|
|
PLUGIN_SLUG="wp-plugin-starter-template"
|
|
BUILD_DIR="build/$PLUGIN_SLUG"
|
|
ZIP_FILE="$PLUGIN_SLUG-$VERSION.zip"
|
|
|
|
# Create build directory
|
|
echo "Creating build directory..."
|
|
rm -rf "$BUILD_DIR"
|
|
mkdir -p "$BUILD_DIR"
|
|
|
|
# Run code quality checks
|
|
echo "Running code quality checks..."
|
|
if command -v composer &>/dev/null; then
|
|
echo "Running PHPCS..."
|
|
composer run phpcs || { echo "⚠️ PHPCS found issues. Consider running 'composer run phpcbf' to fix them."; }
|
|
|
|
# Uncomment the following line to automatically fix coding standards issues
|
|
# echo "Running PHPCBF..."
|
|
# composer run phpcbf
|
|
else
|
|
echo "⚠️ Composer not found, skipping code quality checks"
|
|
fi
|
|
|
|
# Install composer dependencies
|
|
echo "Installing composer dependencies..."
|
|
composer install --no-dev --optimize-autoloader
|
|
|
|
# Copy plugin files to build directory
|
|
echo "Copying plugin files..."
|
|
cp -R ./*.php "$BUILD_DIR/"
|
|
cp -R README.md LICENSE CHANGELOG.md readme.txt composer.json "$BUILD_DIR/"
|
|
|
|
# Copy directories
|
|
echo "Copying directories..."
|
|
mkdir -p "$BUILD_DIR/admin" "$BUILD_DIR/includes" "$BUILD_DIR/languages" "$BUILD_DIR/assets"
|
|
cp -R admin/* "$BUILD_DIR/admin/"
|
|
cp -R includes/* "$BUILD_DIR/includes/"
|
|
cp -R languages/* "$BUILD_DIR/languages/"
|
|
|
|
# Create assets directory structure
|
|
mkdir -p "$BUILD_DIR/assets/banner" "$BUILD_DIR/assets/icon" "$BUILD_DIR/assets/screenshots"
|
|
|
|
# Copy assets if they exist
|
|
if [ -d "assets/banner" ]; then
|
|
cp -R assets/banner/* "$BUILD_DIR/assets/banner/"
|
|
fi
|
|
|
|
if [ -d "assets/icon" ]; then
|
|
cp -R assets/icon/* "$BUILD_DIR/assets/icon/"
|
|
fi
|
|
|
|
if [ -d "assets/screenshots" ]; then
|
|
cp -R assets/screenshots/* "$BUILD_DIR/assets/screenshots/"
|
|
fi
|
|
|
|
# Copy vendor directory if it exists
|
|
if [ -d "vendor" ]; then
|
|
cp -R vendor "$BUILD_DIR/"
|
|
fi
|
|
|
|
# Create ZIP file
|
|
echo "Creating ZIP file..."
|
|
cd build || exit 1
|
|
zip -r "../$ZIP_FILE" "$PLUGIN_SLUG" -x "*.DS_Store" -x "*.git*" -x "*.github*"
|
|
cd ..
|
|
|
|
# Check if ZIP file was created successfully
|
|
if [ -f "$ZIP_FILE" ]; then
|
|
echo "✅ Build successful: $ZIP_FILE created"
|
|
echo "File path: $(pwd)/$ZIP_FILE"
|
|
|
|
# Deploy to local WordPress installation if environment variable is set
|
|
if [ -n "$WP_LOCAL_PLUGIN_DIR" ]; then
|
|
printf '\nDeploying to local WordPress installation...\n'
|
|
echo "Deploying to local WordPress installation..."
|
|
|
|
# Remove existing plugin directory
|
|
rm -rf "${WP_LOCAL_PLUGIN_DIR:?}/$PLUGIN_SLUG"
|
|
|
|
# Copy files to local WordPress installation
|
|
rsync -av --exclude=".git" --exclude=".github" --exclude=".DS_Store" \
|
|
"$BUILD_DIR/" "$WP_LOCAL_PLUGIN_DIR/$PLUGIN_SLUG"
|
|
|
|
# Clear WordPress transients if WP-CLI is available
|
|
if command -v wp &>/dev/null; then
|
|
echo "Clearing WordPress transients..."
|
|
wp transient delete --all --path="$WP_LOCAL_PLUGIN_DIR/../.."
|
|
else
|
|
echo "⚠️ WP-CLI not found, skipping transient clearing"
|
|
fi
|
|
|
|
echo "✅ Local deployment successful!"
|
|
echo "Plugin deployed to: $WP_LOCAL_PLUGIN_DIR/$PLUGIN_SLUG"
|
|
fi
|
|
else
|
|
echo "❌ Build failed: ZIP file was not created"
|
|
exit 1
|
|
fi
|