-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·61 lines (47 loc) · 2.1 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
60
61
#!/bin/bash
zipfile="js13k.zip"
buildpath="tmpbuild"
jscat="${buildpath}/min.js"
indexcat="${buildpath}/index.html"
# Create clean build folder
rm -Rf "${buildpath}" >/dev/null 2>&1
rm -Rf "${zipfile}" >/dev/null 2>&1
mkdir "${buildpath}"
# Concatenate the JS files
touch "${jscat}" >/dev/null 2>&1
for file in "wichmann-hill_rng.js" "font.js" "writer.js" "gamepad.js" "keyboard.js" "timeline.js" "models.js" "music.js" "threedee.js" "main.js"
do
cat "${file}" >> "${jscat}"
done
# Add the index header
echo -n '<!DOCTYPE html><html><head><meta charset="utf-8"/><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/><title>Coding Golf - Broken Links</title><style>' > "${indexcat}"
# Inject the concatenated and minified CSS files
for file in "main.css"
do
yui-compressor "${file}" >> "${indexcat}"
done
# Add on the rest of the index file
echo -n '</style><script type="text/javascript">' >> "${indexcat}"
# Inject the closure-ised and minified JS
./closeyoureyes.sh "${jscat}" >> "${indexcat}"
# Add on the rest of the index file
echo -n '</script><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/></head><body><div id="wrapper"><canvas id="course" width="1280" height="720"></canvas><canvas id="canvas" width="1280" height="720"></canvas><canvas id="hud" width="1280" height="720"></canvas><canvas id="fx" width="1280" height="720"></canvas><canvas id="threedee" width="1280" height="720"></canvas></div></body></html>' >> "${indexcat}"
# Remove the minified JS
rm "${jscat}" >/dev/null 2>&1
# Zip everything up
zip -j "${zipfile}" "${buildpath}"/*
# Re-Zip with advzip to save a bit more
advzip -i 200 -k -z -4 "${zipfile}"
# Determine file sizes and compression
unzip -lv "${zipfile}"
stat "${zipfile}"
zipsize=`stat -c %s "${zipfile}"`
maxsize=$((13*1024))
bytesleft=$((${maxsize}-${zipsize}))
percent=$((200*${zipsize}/${maxsize} % 2 + 100*${zipsize}/${maxsize}))
if [ ${bytesleft} -ge 0 ]
then
echo "YAY ${percent}% used - it fits with ${bytesleft} bytes spare"
else
echo "OH NO ${percent}% used - it's gone ovey by "$((0-${bytesleft}))" bytes"
fi