-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathbuild-plugin-zip.sh
executable file
·87 lines (77 loc) · 2.45 KB
/
build-plugin-zip.sh
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
#!/bin/bash
# Exit if any command fails
set -e
# Change to the expected directory
cd "$(dirname "$0")"
cd ..
# Make sure there are no changes in the working tree. Release builds should be
# traceable to a particular commit and reliably reproducible. (This is not
# totally true at the moment because we download nightly vendor scripts).
changed=
if ! git diff --exit-code > /dev/null; then
changed="file(s) modified"
elif ! git diff --cached --exit-code > /dev/null; then
changed="file(s) staged"
fi
if [ ! -z "$changed" ]; then
git status
echo "ERROR: Cannot build plugin zip with dirty working tree."
echo " Commit your changes and try again."
exit 1
fi
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" != 'master' ]; then
echo "WARNING: You should probably be running this script against the"
echo " 'master' branch (current: '$branch')"
echo
sleep 2
fi
# Download all vendor scripts
vendor_scripts=""
# Using `command | while read...` is more typical, but the inside of the while
# loop will run under a separate process this way, meaning that it cannot
# modify $vendor_scripts. See: https://stackoverflow.com/a/16855194
exec 3< <(
# minified versions of vendor scripts
php bin/get-vendor-scripts.php
# non-minified versions of vendor scripts (for SCRIPT_DEBUG)
php bin/get-vendor-scripts.php debug
)
while IFS='|' read -u 3 url filename; do
echo "$url"
echo -n " > vendor/$filename ... "
curl --location --silent "$url" --output "vendor/_download.tmp.js"
mv -f "vendor/_download.tmp.js" "vendor/$filename"
echo "done!"
vendor_scripts="$vendor_scripts vendor/$filename"
done
# Run the build
npm install
npm run build
# Remove any existing zip file
rm -f gutenberg.zip
# Temporarily modify `gutenberg.php` with production constants defined. Use a
# temp file because `bin/generate-gutenberg-php.php` reads from `gutenberg.php`
# so we need to avoid writing to that file at the same time.
php bin/generate-gutenberg-php.php > gutenberg.tmp.php
mv gutenberg.tmp.php gutenberg.php
# Generate the plugin zip file
zip -r gutenberg.zip \
gutenberg.php \
lib/*.php \
lib/blocks/*.php \
post-content.js \
$vendor_scripts \
blocks/build/*.{js,map} \
components/build/*.{js,map} \
date/build/*.{js,map} \
editor/build/*.{js,map} \
element/build/*.{js,map} \
i18n/build/*.{js,map} \
utils/build/*.{js,map} \
blocks/build/*.css \
components/build/*.css \
editor/build/*.css \
README.md
# Reset `gutenberg.php`
git checkout gutenberg.php