-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
59 lines (50 loc) · 1.75 KB
/
build.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
buildAllTheThings () {
rm -rf ./dist
mkdir ./dist
sed -e 's#export ##g' dragon-router.js > dist/dragon-router.js
echo "
if (typeof module === 'object' && module.exports) {
module.exports = {Router, Context, DerivedSubpath, RouteHandler, TokenizedPath}
} else {
Object.assign(window, {Router, Context, DerivedSubpath, RouteHandler, TokenizedPath})
}
" >> dist/dragon-router.js
npx babel-minify dist/dragon-router.js --out-file dist/dragon-router.min.js
cp dragon-router.js dist/dragon-router.module.js
}
filesize () {
wc -c "$1" | awk '{print $1}'
}
reportSize () {
Msize=$(filesize dragon-router.js)
Gsize=$(filesize dist/dragon-router.js)
GminS=$(filesize dist/dragon-router.min.js)
# Table Alignment
a="| %-30s | %6s |\n"
echo;
echo "+--------------------------------+--------+"
echo "| FILE | SIZE |"
echo "+--------------------------------|--------+"
printf "$a" "dragon-router.js" $Msize
printf "$a" "dist/" ""
printf "$a" " dragon-router.module.js" $Msize
printf "$a" " dragon-router.js" $Gsize
printf "$a" " dragon-router.min.js" $GminS
echo "+--------------------------------+--------+"
echo;
echo " min file compression: $(expr \( $GminS \* 100 \) / $Msize)%"
echo;
}
###################################################################################
if [ "$1" = 'build-only-if-needed' ]; then
echo "Checking if we need to run the build..."
if [ ./dragon-router.js -nt ./dist/dragon-router.module.js ]; then
echo "'dragon-router.js' is dirty, running build..."
buildAllTheThings
else
echo "'dragon-router.js' is clean, no need to run build."
fi
else
buildAllTheThings
fi
reportSize