Files
wp-plugin-starter-template-…/build.sh
marcusquinn 476dc7e647 fix: address PR #10 CodeRabbit review feedback
- Fix SC2115 shellcheck warning in build.sh (use ${var:?} for safe rm -rf)
- Fix SC2164 shellcheck warning in build.sh (cd build || exit 1)
- Standardise bullet points from hyphens to asterisks in .wiki/Contributing.md
- Refine verb formality in readme.txt, README.md, .wiki/Contributing.md, .wiki/Coding-Standards.md
- Clarify PHPDoc wording in .wiki/Coding-Standards.md
- Add clarifying comment to phpcs-simple.xml arg value
2026-03-16 20:11:05 +00:00

111 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
# 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
echo "\nDeploying to local WordPress installation..."
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