-
Notifications
You must be signed in to change notification settings - Fork 8
/
package.sh
executable file
·145 lines (127 loc) · 4.02 KB
/
package.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# First parameter not mandatory is the folder of the plugin, if not set use the current working directory
# Second parameter not mandatory is the root file of the plugin, if not set use the foldername of the plugin (not require the extension of the file)
if [ "$(uname -s)" = 'Linux' ]; then
pluginfolder=$(readlink -f "$1")
else
pluginfolder=$(readlink "$1")
fi
output='/tmp'
if [ -z "$1" ]; then
pluginfolder=$(pwd)
fi
originalfoldername=$(basename "$pluginfolder")
packagename=$2
if [ -z "$2" ]; then
packagename=$(basename "$pluginfolder")
fi
fileroot="$packagename.php"
fullpathfile="$pluginfolder/$packagename.php"
if [ ! -f "$fullpathfile" ]; then
echo "$fullpathfile file not exists"
exit 1
fi
foldername="/tmp/$originalfoldername.XXXX"
mktemp -d "$foldername"
cd "$pluginfolder" || exit
version=$(grep "^Stable tag:" README.txt | awk -F' ' '{print $NF}')
if [ -x "$(command -v wp-readme-last-wp-tested)" ]; then
wp-readme-last-wp-tested README.txt
if [[ -n $(git diff-index --quiet HEAD) ]]; then
git add README.txt > /dev/null
git commit -m "bumped Tested Up field in README.txt" -n > /dev/null
git push origin master
fi
fi
echo "- Created the git tag for $version version"
git tag -a "$version" -m "$version"
git checkout master &> /dev/null
git push origin "$version" > /dev/null
echo "- Copy the whole plugin folder to cleanup later, takes a while"
rsync -a --exclude "vendor" "$pluginfolder/" "$foldername"
cd "$foldername" || exit
echo "- Generating the zip in progress..."
echo "- Cleaning in Progress..."
rm -rf ./.git*
rm -rf ./.sass-cache
rm -rf ./.directory
rm -rf ./.eslintrc.json
rm -rf ./node_modules
rm -rf ./nbproject
rm -rf ./composer/
rm -rf ./wp-config-test.php
rm -rf ./*.yml
rm -rf ./*.neon
rm -rf ./*.ini
rm -rf ./*.sh
rm -rf ./.*.cache
rm -rf ./.env
rm -rf ./.gitignore
rm -rf ./.editorconfig
rm -rf ./package.json
rm -rf ./package-lock.json
rm -rf ./Gruntfile.js
rm -rf ./gulpfile.js
rm -rf ./composer.lock
rm -rf ./.travis*
rm -rf ./.php_cs
rm -rf ./wp-content
rm -rf ./*.zip
# This contain the test stuff
rm -rf ./tests
# This contain the WP repo assets
if [ -d './wp-assets' ]; then
rm -rf ./wp-assets
else
# Oldp lugins has that folde but new one use for other stuff
rm -rf ./assets
fi
if [ -s './composer.json' ]; then
# Detect if there are composer dependencies
dep=$(jq 'has("require")' < "./composer.json")
if [ "$dep" == 'true' ]; then
echo "- Downloading clean composer dependencies..."
rm -rf vendor
composer update --no-dev &> /dev/null
for dir in ./vendor/*/*/
do
if [ -d "$dir/tests" ]; then
rm -rf "$dir/tests"
fi
done
for dir in ./vendor/*/*/vendor/*/*/
do
if [ -d "$dir/tests" ]; then
rm -rf "$dir/tests"
fi
done
composer dumpautoload -o
else
echo "- No composer packages detected for production..."
rm -rf ./composer.json
rm -rf ./vendor
fi
fi
# Remove Fake_Freemius - it is the only requirement for Freemius
if [ -s './Fake_Freemius.php' ]; then
echo "- Cleaning for Freemius"
rm -rf ./Fake_Freemius.php
rowff=$(grep -n "/Fake_Freemius.php" "$fileroot" | awk -F: '{print $1}')
rowff+='s'
sed -i "$rowff/.*/ require_once dirname( __FILE__ ) \\. '\\/vendor\\/freemius\\/wordpress-sdk\\/start.php'\;/" "$fileroot"
fi
# Support for old plugins
if [ -s './includes/Fake_Freemius.php' ]; then
echo "- Cleaning for Freemius"
rm -rf ./includes/Fake_Freemius.php
rowff=$(grep -n "/includes/Fake_Freemius.php" "$fileroot" | awk -F: '{print $1}')
rowff+='d'
sed -i "$rowff" "$fileroot"
# If Freemius SDK is commented remove the comments
rowfs=$(grep -n "/includes/freemius/start.php" "$fileroot" | awk -F: '{print $1}')
rowfs+='s'
sed -i "$rowfs/\\/\\///" "$fileroot"
fi
zip -r "$output"/"$packagename"-"$version".zip ./ &> /dev/null
rm -rf "$foldername"
echo "- Package generated! $output/$packagename-$version.zip"