-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress-dist.sh
executable file
·50 lines (45 loc) · 1.62 KB
/
compress-dist.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
#!/bin/bash
DIR="$(cd "$(dirname "$0")" && pwd -P)"
DIST_DIR=${DIR}/dist
BROTLI=$(command -v brotli)
ZOPFLI=$(command -v zopfli)
GZIP=$(command -v pigz)
[ ! -x "$GZIP" ] && GZIP=$(command -v gzip)
[ ! -x "$GZIP" ] && echo "no 'pigz'/'gzip' found" && exit 1
TOUCH=$(command -v touch)
[ ! -x "$TOUCH" ] && echo "no 'touch' found" && exit 1
WC=$(command -v wc)
[ ! -x "$WC" ] && echo "no 'wc' found" && exit 1
find "$DIST_DIR" -type f -print0 | while IFS= read -r -d $'\0' file; do
ext="${file##*.}"
case $ext in
html|js|css|map|svg|ttf|eot|json|ico|webapp)
if [ "$($WC -c < "$file")" -gt 512 ]; then
if [ -x "$BROTLI" ]; then
outfile="${file}.br"
(
(
# increment "$outfile start" &&
$BROTLI -c "$file" > "$outfile" &&
$TOUCH -r "$file" "$outfile"
) # && decrement "$outfile done"
) &
fi
if [ -x "$ZOPFLI" ]; then
outfile="${file}.gz"
(
(
# increment "$outfile start" &&
$ZOPFLI -c "$file" > "$outfile" &&
$TOUCH -r "$file" "$outfile"
) # && decrement "$outfile done"
) &
else
echo "${file}.gz"
$GZIP -9 -c "$file" > "${file}.gz"
$TOUCH -r "$file" "${file}.gz"
fi
fi
;;
esac
done