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