|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to create a release zip file for Secure Custom Fields |
| 4 | +# This script creates a zip file with only the necessary files for distribution |
| 5 | + |
| 6 | +# Set script directory and define paths |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 | +PROJECT_ROOT="$SCRIPT_DIR" |
| 9 | +OUTPUT_DIR="$PROJECT_ROOT/release" |
| 10 | +ZIP_NAME="secure-custom-fields.zip" |
| 11 | + |
| 12 | +# Create output directory if it doesn't exist |
| 13 | +mkdir -p "$OUTPUT_DIR" |
| 14 | + |
| 15 | +# Remove existing zip file if it exists |
| 16 | +if [ -f "$OUTPUT_DIR/$ZIP_NAME" ]; then |
| 17 | + echo "Removing existing zip file..." |
| 18 | + rm "$OUTPUT_DIR/$ZIP_NAME" |
| 19 | +fi |
| 20 | + |
| 21 | +echo "Creating release zip file: $ZIP_NAME" |
| 22 | +echo "Output directory: $OUTPUT_DIR" |
| 23 | + |
| 24 | +# Create temporary directory for staging files |
| 25 | +TEMP_DIR=$(mktemp -d) |
| 26 | +PLUGIN_DIR="$TEMP_DIR/secure-custom-fields" |
| 27 | +mkdir -p "$PLUGIN_DIR" |
| 28 | + |
| 29 | +echo "Staging files in temporary directory: $TEMP_DIR" |
| 30 | + |
| 31 | +# Copy files to staging directory |
| 32 | +# Note: Using the current project files instead of the SVN paths mentioned |
| 33 | +# since we're working in the main project directory |
| 34 | + |
| 35 | +# Copy individual files |
| 36 | +echo "Copying core files..." |
| 37 | +cp "$PROJECT_ROOT/acf.php" "$PLUGIN_DIR/" 2>/dev/null || echo "Warning: acf.php not found" |
| 38 | +cp "$PROJECT_ROOT/composer.json" "$PLUGIN_DIR/" 2>/dev/null || echo "Warning: composer.json not found" |
| 39 | +cp "$PROJECT_ROOT/index.php" "$PLUGIN_DIR/" 2>/dev/null || echo "Warning: index.php not found" |
| 40 | +cp "$PROJECT_ROOT/license.txt" "$PLUGIN_DIR/" 2>/dev/null || echo "Warning: license.txt not found" |
| 41 | +cp "$PROJECT_ROOT/readme.txt" "$PLUGIN_DIR/" 2>/dev/null || echo "Warning: readme.txt not found" |
| 42 | +cp "$PROJECT_ROOT/secure-custom-fields.php" "$PLUGIN_DIR/" 2>/dev/null || echo "Warning: secure-custom-fields.php not found" |
| 43 | +cp "$PROJECT_ROOT/SECURITY.md" "$PLUGIN_DIR/" 2>/dev/null || echo "Warning: SECURITY.md not found" |
| 44 | + |
| 45 | +# Copy directories |
| 46 | +echo "Copying directories..." |
| 47 | +if [ -d "$PROJECT_ROOT/assets" ]; then |
| 48 | + cp -r "$PROJECT_ROOT/assets" "$PLUGIN_DIR/" |
| 49 | + echo "✓ Copied assets directory" |
| 50 | +else |
| 51 | + echo "Warning: assets directory not found" |
| 52 | +fi |
| 53 | + |
| 54 | +if [ -d "$PROJECT_ROOT/includes" ]; then |
| 55 | + cp -r "$PROJECT_ROOT/includes" "$PLUGIN_DIR/" |
| 56 | + echo "✓ Copied includes directory" |
| 57 | +else |
| 58 | + echo "Warning: includes directory not found" |
| 59 | +fi |
| 60 | + |
| 61 | +if [ -d "$PROJECT_ROOT/lang" ]; then |
| 62 | + cp -r "$PROJECT_ROOT/lang" "$PLUGIN_DIR/" |
| 63 | + echo "✓ Copied lang directory" |
| 64 | +else |
| 65 | + echo "Warning: lang directory not found" |
| 66 | +fi |
| 67 | + |
| 68 | +if [ -d "$PROJECT_ROOT/pro" ]; then |
| 69 | + cp -r "$PROJECT_ROOT/pro" "$PLUGIN_DIR/" |
| 70 | + echo "✓ Copied pro directory" |
| 71 | +else |
| 72 | + echo "Warning: pro directory not found" |
| 73 | +fi |
| 74 | + |
| 75 | +# Install production dependencies before copying vendor |
| 76 | +echo "Installing production dependencies..." |
| 77 | +if [ -f "$PROJECT_ROOT/composer.json" ]; then |
| 78 | + cd "$PROJECT_ROOT" |
| 79 | + composer install --no-dev --optimize-autoloader --no-interaction |
| 80 | + if [ $? -eq 0 ]; then |
| 81 | + echo "✓ Composer install completed successfully" |
| 82 | + else |
| 83 | + echo "Warning: Composer install failed" |
| 84 | + fi |
| 85 | +else |
| 86 | + echo "Warning: composer.json not found, skipping composer install" |
| 87 | +fi |
| 88 | + |
| 89 | +if [ -d "$PROJECT_ROOT/vendor" ]; then |
| 90 | + cp -r "$PROJECT_ROOT/vendor" "$PLUGIN_DIR/" |
| 91 | + echo "✓ Copied vendor directory" |
| 92 | + |
| 93 | + # Remove empty vendor/bin directory if it exists |
| 94 | + if [ -d "$PLUGIN_DIR/vendor/bin" ] && [ -z "$(ls -A "$PLUGIN_DIR/vendor/bin")" ]; then |
| 95 | + rm -rf "$PLUGIN_DIR/vendor/bin" |
| 96 | + echo "✓ Removed empty vendor/bin directory" |
| 97 | + fi |
| 98 | +else |
| 99 | + echo "Warning: vendor directory not found" |
| 100 | +fi |
| 101 | + |
| 102 | +# Create the zip file |
| 103 | +echo "Creating zip file..." |
| 104 | +cd "$TEMP_DIR" |
| 105 | +zip -r "$OUTPUT_DIR/$ZIP_NAME" secure-custom-fields/ -q |
| 106 | + |
| 107 | +# Clean up temporary directory |
| 108 | +echo "Cleaning up temporary files..." |
| 109 | +rm -rf "$TEMP_DIR" |
| 110 | + |
| 111 | +# Check if zip was created successfully |
| 112 | +if [ -f "$OUTPUT_DIR/$ZIP_NAME" ]; then |
| 113 | + echo "✅ Success! Release zip created at: $OUTPUT_DIR/$ZIP_NAME" |
| 114 | + echo "📦 Zip file size: $(du -h "$OUTPUT_DIR/$ZIP_NAME" | cut -f1)" |
| 115 | + echo "" |
| 116 | + echo "Contents of the zip file:" |
| 117 | + unzip -l "$OUTPUT_DIR/$ZIP_NAME" | head -20 |
| 118 | + echo "..." |
| 119 | + echo "Total files: $(unzip -l "$OUTPUT_DIR/$ZIP_NAME" | grep -c "secure-custom-fields/")" |
| 120 | +else |
| 121 | + echo "❌ Error: Failed to create zip file" |
| 122 | + exit 1 |
| 123 | +fi |
0 commit comments