-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-plugin-zip.sh
executable file
·41 lines (33 loc) · 1.51 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
#!/bin/bash
# Script for WordPress plugin block development. It compiles block assets using 'npm run build',
# attempts to read the plugin name from 'src/block.json'. If successful, it names the zip file after the plugin,
# appending a timestamp for uniqueness. If the plugin name cannot be read, it defaults to "plugin-<timestamp>.zip".
# Official WP scripts does not properly include PHP files so this was made
# Run npm build command
echo "Running npm build..."
npm run build
if [ $? -eq 0 ]; then
echo "npm build successful. Proceeding to read plugin name..."
# Attempt to extract the plugin name from block.json, fall back to default if unsuccessful
PLUGIN_NAME=$(jq -r '.name | split("/")[1] // "plugin"' src/block.json)
TIMESTAMP=$(date +%Y%m%d%H%M%S)
# Attempt to extract the plugin name and version from block.json
PLUGIN_PART=$(jq -r '.name | split("/")[1] // "plugin"' src/block.json)
VERSION=$(jq -r '.version // "1.0.0"' src/block.json)
if [ ! -z "$PLUGIN_PART" ] && [ ! -z "$VERSION" ]; then
echo "Using name and version for zip file: $PLUGIN_PART-$VERSION"
else
echo "Defaulting to generic name and version for zip file."
PLUGIN_PART="plugin"
VERSION="1.0.0"
fi
ZIPFILE="${PLUGIN_PART}-${VERSION}.zip"
zip -r "$ZIPFILE" *.php build/ readme.txt
if [ $? -eq 0 ]; then
echo "Successfully created zip file: $ZIPFILE"
else
echo "Failed to create zip file."
fi
else
echo "npm build failed. Aborting zip operation."
fi