|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# WordPress DocumentCloud Plugin Packaging Script |
| 4 | +# This script packages the plugin for distribution by copying files |
| 5 | +# and excluding development artifacts, hidden files, and node_modules |
| 6 | +# |
| 7 | +# Generated by Claude Sonnet 4 on 2025-06-24 |
| 8 | + |
| 9 | +set -e # Exit on any error |
| 10 | + |
| 11 | +# Colors for output |
| 12 | +RED='\033[0;31m' |
| 13 | +GREEN='\033[0;32m' |
| 14 | +YELLOW='\033[1;33m' |
| 15 | +NC='\033[0m' # No Color |
| 16 | + |
| 17 | +# Configuration |
| 18 | +PLUGIN_NAME="documentcloud" |
| 19 | +SOURCE_DIR="src/documentcloud" |
| 20 | +DIST_DIR="dist" |
| 21 | +ZIP_FILE="${PLUGIN_NAME}.zip" |
| 22 | + |
| 23 | +echo -e "${YELLOW}📦 Starting WordPress DocumentCloud Plugin packaging...${NC}" |
| 24 | + |
| 25 | +# Step 1: Clear and create dist directory |
| 26 | +echo -e "${YELLOW}🧹 Step 1: Cleaning dist directory...${NC}" |
| 27 | +if [ -d "$DIST_DIR" ]; then |
| 28 | + rm -rf "$DIST_DIR" |
| 29 | + echo " Removed existing dist directory" |
| 30 | +fi |
| 31 | +mkdir -p "$DIST_DIR" |
| 32 | +echo " Created fresh dist directory" |
| 33 | + |
| 34 | +# Step 2: Copy plugin files with exclusions |
| 35 | +echo -e "${YELLOW}📋 Step 2: Copying plugin files...${NC}" |
| 36 | + |
| 37 | +# Check if source directory exists |
| 38 | +if [ ! -d "$SOURCE_DIR" ]; then |
| 39 | + echo -e "${RED}❌ Error: Source directory $SOURCE_DIR not found!${NC}" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +# Copy main plugin files (excluding hidden files and node_modules) |
| 44 | +echo " Copying main plugin files..." |
| 45 | +rsync -av \ |
| 46 | + --exclude='.*' \ |
| 47 | + --exclude='*/.*' \ |
| 48 | + --exclude='node_modules/' \ |
| 49 | + --exclude='blocks/' \ |
| 50 | + "$SOURCE_DIR/" "$DIST_DIR/$PLUGIN_NAME/" |
| 51 | + |
| 52 | +# Step 2.1: Clean up any remaining hidden files that might have been copied |
| 53 | +echo -e "${YELLOW}🧹 Step 2.1: Cleaning up hidden files...${NC}" |
| 54 | +find "$DIST_DIR/$PLUGIN_NAME" -name ".*" -type f -delete |
| 55 | +find "$DIST_DIR/$PLUGIN_NAME" -name ".DS_Store" -delete |
| 56 | +echo " Removed any remaining hidden files" |
| 57 | + |
| 58 | +# Step 3: Handle blocks directory specially (only copy build folder) |
| 59 | +echo -e "${YELLOW}🔧 Step 3: Handling blocks directory...${NC}" |
| 60 | +BLOCKS_SOURCE="$SOURCE_DIR/blocks" |
| 61 | +BLOCKS_DEST="$DIST_DIR/$PLUGIN_NAME/blocks" |
| 62 | + |
| 63 | +if [ -d "$BLOCKS_SOURCE/build" ]; then |
| 64 | + echo " Creating blocks directory structure..." |
| 65 | + mkdir -p "$BLOCKS_DEST" |
| 66 | + |
| 67 | + echo " Copying blocks/build directory..." |
| 68 | + cp -r "$BLOCKS_SOURCE/build" "$BLOCKS_DEST/" |
| 69 | + |
| 70 | + # Copy essential block files (package.json for reference) |
| 71 | + if [ -f "$BLOCKS_SOURCE/package.json" ]; then |
| 72 | + cp "$BLOCKS_SOURCE/package.json" "$BLOCKS_DEST/" |
| 73 | + echo " Copied package.json for reference" |
| 74 | + fi |
| 75 | +else |
| 76 | + echo -e "${YELLOW} ⚠️ Warning: blocks/build directory not found${NC}" |
| 77 | +fi |
| 78 | + |
| 79 | +# Step 4: Create zip file |
| 80 | +echo -e "${YELLOW}🗜️ Step 4: Creating zip archive...${NC}" |
| 81 | + |
| 82 | +cd "$DIST_DIR" |
| 83 | +# Remove existing zip file if it exists |
| 84 | +if [ -f "$ZIP_FILE" ]; then |
| 85 | + rm "$ZIP_FILE" |
| 86 | + echo " Removed existing $ZIP_FILE" |
| 87 | +fi |
| 88 | + |
| 89 | +# Create zip file from dist directory |
| 90 | +zip -r "$ZIP_FILE" "$PLUGIN_NAME/" > /dev/null |
| 91 | +cd .. |
| 92 | + |
| 93 | +echo " Created $ZIP_FILE" |
| 94 | + |
| 95 | +# Step 5: Validate and report |
| 96 | +echo -e "${YELLOW}✅ Step 5: Validation and summary...${NC}" |
| 97 | + |
| 98 | +cd "$DIST_DIR" |
| 99 | +# Check if zip was created successfully |
| 100 | +if [ -f "$ZIP_FILE" ]; then |
| 101 | + ZIP_SIZE=$(du -h "$ZIP_FILE" | cut -f1) |
| 102 | + echo -e "${GREEN}🎉 Success! Plugin packaged successfully${NC}" |
| 103 | + echo " 📁 Archive: $ZIP_FILE ($ZIP_SIZE)" |
| 104 | + echo " 📂 Contents preview:" |
| 105 | + unzip -l "$ZIP_FILE" | head -20 |
| 106 | + echo |
| 107 | + echo -e "${GREEN}✨ Ready for distribution!${NC}" |
| 108 | +else |
| 109 | + echo -e "${RED}❌ Error: Failed to create zip file${NC}" |
| 110 | + exit 1 |
| 111 | +fi |
| 112 | + |
| 113 | +echo -e "${YELLOW}📦 Packaging complete!${NC}" |
0 commit comments