forked from WPSwitzerland/plugin-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-wordpress-plugin.sh
executable file
·118 lines (88 loc) · 3.52 KB
/
build-wordpress-plugin.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
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
114
115
116
117
118
#!/bin/sh
function runPluginBuilder()
{
# Ask for data
echo "Plugin key: lowercase with underscores (e.g. 'my_plugin')"
read PLUGIN_KEY
if test -z "$PLUGIN_KEY"
then
echo "You must specify a plugin key."
exit
fi
echo "Author name (e.g. 'Mark Mustermann')"
read PLUGIN_AUTHOR
echo "Author email address"
read AUTHOR_EMAIL
echo "Author URI (website address)"
read AUTHOR_URI
# Escape URI for regexp use within sed
AUTHOR_URI=$(echo $AUTHOR_URI | sed -e 's/\//\\\//g')
echo "Author's vendor name (e.g. 'CompanyName')"
read AUTHOR_NAMESPACE
echo "Plugin name (e.g. 'My great plugin')?"
read PLUGIN_NAME
echo "Plugin description"
read PLUGIN_DESCRIPTION
echo "Plugin URI (e.g. GitHub URL)"
read PLUGIN_URI
# Replace dots from PLUGIN_KEY to not break function names
PLUGIN_KEY_CLEAN=$(echo $PLUGIN_KEY | sed 's/\./\_/g')
# Escape URI for regexp use within sed
PLUGIN_URI=$(echo $PLUGIN_URI | sed -e 's/\//\\\//g')
# Fetch the current base code from GitHub
git clone https://github.com/cubetech/plugin-boilerplate-psr $PLUGIN_KEY
rm -rf $PLUGIN_KEY/.git $PLUGIN_KEY/README.md
mv $PLUGIN_KEY/plugin-boilerplate-psr.php $PLUGIN_KEY/$PLUGIN_KEY.php
mv $PLUGIN_KEY/README_BLANK.md $PLUGIN_KEY/README.md
# Search and replace metadata and names
# Plugin key
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/PLUGIN_KEY/$PLUGIN_KEY_CLEAN/g" {} +
# Plugin prefix (for non-namespace functionality)
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/PLUGIN_PREFIX/$PLUGIN_KEY_CLEAN/g" {} +
# Text domain
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/TEXT_DOMAIN/$PLUGIN_KEY_CLEAN/g" {} +
# Plugin domain (e.g. wpswitzerland/my_great_plugin)
# First convert to lowercase
PLUGIN_DOMAIN=$(echo "$AUTHOR_NAMESPACE/$PLUGIN_KEY_CLEAN" | sed -e 's/\(.*\)/\L\1/')
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/PLUGIN_DOMAIN/$PLUGIN_DOMAIN/g" {} +
# Apply plugin key as pascal case namespace
PLUGIN_NAMESPACE=$(echo $PLUGIN_KEY_CLEAN | sed -e 's/_\([a-z]\)/\u\1/g' -e 's/^[a-z]/\u&/')
find $PLUGIN_KEY -type f -name "*.php" -exec sed -i "s/PLUGIN_NAMESPACE/$PLUGIN_NAMESPACE/g" {} +
# Plugin author name
if ! test -z "$PLUGIN_AUTHOR"
then
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/PLUGIN_AUTHOR/$PLUGIN_AUTHOR/g" {} +
fi
# Plugin author email address
if ! test -z "$AUTHOR_EMAIL"
then
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/AUTHOR_EMAIL/$AUTHOR_EMAIL/g" {} +
fi
# Plugin author website
if ! test -z "$AUTHOR_URI"
then
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/AUTHOR_URI/$AUTHOR_URI/g" {} +
fi
# Plugin name
if ! test -z "$PLUGIN_NAME"
then
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/PLUGIN_NAME/$PLUGIN_NAME/g" {} +
fi
# Plugin description
if ! test -z "$PLUGIN_DESCRIPTION"
then
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/PLUGIN_DESCRIPTION/$PLUGIN_DESCRIPTION/g" {} +
fi
# Plugin author namespace (Usually a company name; used as the top-level PHP namespace)
if ! test -z "$AUTHOR_NAMESPACE"
then
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/AUTHOR_NAMESPACE/$AUTHOR_NAMESPACE/g" {} +
fi
# Plugin's own website
if ! test -z "$PLUGIN_URI"
then
find $PLUGIN_KEY -type f -name "*.*" -exec sed -i "s/PLUGIN_URI/$PLUGIN_URI/g" {} +
fi
}
runPluginBuilder
echo "You are good to go!"