forked from jparyani/etherpad-lite
-
Notifications
You must be signed in to change notification settings - Fork 11
/
minify-cache.sh
executable file
·58 lines (47 loc) · 1.45 KB
/
minify-cache.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
#! /bin/bash
set -euo pipefail
minify_embeds() {
# TODO(someday): Minify JS too. But require-kernel.js seems to be concocted from thin air.
local pattern='^Ace2Editor\.EMBEDED\["\.\./([^"]*\.css)"] = '
while read -r LINE; do
if [[ "$LINE" =~ $pattern ]]; then
embed=${BASH_REMATCH[1]}
echo -n "Ace2Editor.EMBEDED[\"../$embed\"] = \""
cleancss src/$embed | sed -e 's/"/\\"/g'
echo "\";"
else
echo "$LINE"
fi
done
}
for file in cache/*.js%3F*; do
if [ ${file%.gz} != $file ]; then continue; fi
if [ ${file%.ugly} != $file ]; then continue; fi
if grep -q already_ugly $file; then continue; fi
echo "**** $file" >&2
if egrep -q '^Ace2Editor\.EMBEDED\["\.\./([^"]*\.css)"] = ' $file; then
echo "* minifying embeds too" >&2
minify_embeds < $file > $file.reembed
mv $file.reembed $file
fi
uglify -s $file -o $file.ugly
echo "//already_ugly" >> $file.ugly
mv $file.ugly $file
rm -f $file.gz
gzip -k $file
done
for file in cache/*.css; do
if [ ${file%.gz} != $file ]; then continue; fi
if [ ${file%.ugly} != $file ]; then continue; fi
if grep -q already_ugly $file; then continue; fi
echo "**** $file" >&2
if grep -q "@import url([\"']./" $file; then
sed -i -re "s,@import url\(([\"'])\./,@import url(\1../src/static/css/,g" $file
fi
echo $file
cleancss -o $file.ugly $file
echo "/*already_ugly*/" >> $file.ugly
mv $file.ugly $file
rm -f $file.gz
gzip -k $file
done