|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# WP API JWT Auth - Release Package Creator |
| 4 | +# This script creates a release package excluding files listed in .distignore |
| 5 | + |
| 6 | +set -e # Exit on any error |
| 7 | + |
| 8 | +# Colors for output |
| 9 | +RED='\033[0;31m' |
| 10 | +GREEN='\033[0;32m' |
| 11 | +YELLOW='\033[1;33m' |
| 12 | +BLUE='\033[0;34m' |
| 13 | +NC='\033[0m' # No Color |
| 14 | + |
| 15 | +# Helper functions |
| 16 | +print_header() { |
| 17 | + echo -e "\n${BLUE}================================${NC}" |
| 18 | + echo -e "${BLUE}$1${NC}" |
| 19 | + echo -e "${BLUE}================================${NC}\n" |
| 20 | +} |
| 21 | + |
| 22 | +print_success() { |
| 23 | + echo -e "${GREEN}✅ $1${NC}" |
| 24 | +} |
| 25 | + |
| 26 | +print_error() { |
| 27 | + echo -e "${RED}❌ $1${NC}" |
| 28 | +} |
| 29 | + |
| 30 | +print_info() { |
| 31 | + echo -e "${BLUE}ℹ️ $1${NC}" |
| 32 | +} |
| 33 | + |
| 34 | +# Set variables |
| 35 | +PLUGIN_SLUG="wp-api-jwt-auth" |
| 36 | +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 37 | +PLUGIN_ROOT="$CURRENT_DIR/.." |
| 38 | +DISTIGNORE_FILE="$PLUGIN_ROOT/.distignore" |
| 39 | + |
| 40 | +# Get version from the main plugin file |
| 41 | +VERSION=$(grep "Version:" "$PLUGIN_ROOT/jwt-auth.php" | awk -F': ' '{print $2}' | tr -d '\r' | xargs) |
| 42 | + |
| 43 | +# Check if version was found |
| 44 | +if [ -z "$VERSION" ]; then |
| 45 | + print_error "Could not determine plugin version from jwt-auth.php" |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +# Check if .distignore exists |
| 50 | +if [ ! -f "$DISTIGNORE_FILE" ]; then |
| 51 | + print_error ".distignore file not found at $DISTIGNORE_FILE" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +print_header "Creating Release Package" |
| 56 | +print_info "Plugin: $PLUGIN_SLUG" |
| 57 | +print_info "Version: $VERSION" |
| 58 | + |
| 59 | +# Create a temporary directory |
| 60 | +TEMP_DIR="$(mktemp -d)" |
| 61 | +DEST_DIR="$TEMP_DIR/$PLUGIN_SLUG" |
| 62 | + |
| 63 | +# Create destination directory |
| 64 | +mkdir -p "$DEST_DIR" |
| 65 | + |
| 66 | +print_info "Copying files to temporary directory..." |
| 67 | + |
| 68 | +# Use rsync to copy files while respecting .distignore |
| 69 | +# Convert .distignore patterns to rsync exclude format |
| 70 | +RSYNC_EXCLUDES="" |
| 71 | +while IFS= read -r line || [ -n "$line" ]; do |
| 72 | + # Skip empty lines and comments |
| 73 | + if [[ -z "$line" ]] || [[ "$line" =~ ^# ]]; then |
| 74 | + continue |
| 75 | + fi |
| 76 | + |
| 77 | + # Trim whitespace |
| 78 | + line=$(echo "$line" | xargs) |
| 79 | + |
| 80 | + if [[ -n "$line" ]]; then |
| 81 | + RSYNC_EXCLUDES="$RSYNC_EXCLUDES --exclude=$line" |
| 82 | + fi |
| 83 | +done < "$DISTIGNORE_FILE" |
| 84 | + |
| 85 | +# Additional excludes for safety |
| 86 | +RSYNC_EXCLUDES="$RSYNC_EXCLUDES --exclude=.git --exclude=.DS_Store --exclude=*.zip" |
| 87 | + |
| 88 | +# Copy files using rsync with excludes |
| 89 | +rsync -av --progress $RSYNC_EXCLUDES "$PLUGIN_ROOT/" "$DEST_DIR/" |
| 90 | + |
| 91 | +# Install production composer dependencies if composer.json exists and vendor is not excluded |
| 92 | +if [ -f "$DEST_DIR/composer.json" ] && [ ! -d "$DEST_DIR/includes/vendor" ]; then |
| 93 | + print_info "Installing production Composer dependencies..." |
| 94 | + cd "$DEST_DIR" |
| 95 | + composer install --no-dev --optimize-autoloader --prefer-dist --no-interaction |
| 96 | + cd - > /dev/null |
| 97 | +else |
| 98 | + print_info "Vendor directory already exists or composer.json not found, skipping composer install" |
| 99 | +fi |
| 100 | + |
| 101 | +# Build frontend assets if needed |
| 102 | +if [ -f "$DEST_DIR/package.json" ] && [ ! -d "$DEST_DIR/admin/ui/dist" ]; then |
| 103 | + print_info "Building frontend assets..." |
| 104 | + cd "$DEST_DIR" |
| 105 | + npm install --production=false |
| 106 | + npm run build |
| 107 | + # Remove node_modules after build |
| 108 | + rm -rf node_modules |
| 109 | + cd - > /dev/null |
| 110 | +else |
| 111 | + print_info "Frontend dist already exists or package.json not found, skipping build" |
| 112 | +fi |
| 113 | + |
| 114 | +# Create the zip file |
| 115 | +print_info "Creating zip archive..." |
| 116 | +cd "$TEMP_DIR" |
| 117 | +ZIP_NAME="${PLUGIN_SLUG}.zip" |
| 118 | +zip -r "$ZIP_NAME" "$PLUGIN_SLUG" -q |
| 119 | + |
| 120 | +# Move zip to plugin root |
| 121 | +mv "$ZIP_NAME" "$PLUGIN_ROOT/" |
| 122 | + |
| 123 | +# Cleanup |
| 124 | +print_info "Cleaning up temporary files..." |
| 125 | +rm -rf "$TEMP_DIR" |
| 126 | + |
| 127 | +print_success "Release package created successfully!" |
| 128 | +print_info "📦 Package location: $PLUGIN_ROOT/$ZIP_NAME" |
| 129 | +print_info "📏 Package size: $(du -h "$PLUGIN_ROOT/$ZIP_NAME" | cut -f1)" |
| 130 | + |
| 131 | +# List contents summary |
| 132 | +print_info "Package contents summary:" |
| 133 | +unzip -l "$PLUGIN_ROOT/$ZIP_NAME" | tail -n 3 |
0 commit comments