Files
wp-plugin-starter-template-…/build.sh
Marcus Quinn 81e5b14604 fix: consolidate duplicate deployment echo into single printf in build.sh (#99)
Addresses Gemini review feedback from PR #80 (build.sh:88): replaces the
redundant pair of printf+echo deployment messages with a single printf call,
which is more concise and idiomatic for formatted shell output.

Closes #97
2026-03-18 21:27:26 +00:00

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*"
)
# 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'
# 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