-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·79 lines (63 loc) · 2.88 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Check for work folder specified
if [ $# -eq 1 ]
then
workdir=$1
echo "Entering ${workdir}"
cd "${workdir}"
fi
zipfile="js13k.zip"
models="models.js"
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}"
# Create a 3D models bundle
echo "var models=[" > "${models}"
for file in "dev/stealth.obj" "dev/cvn-65.obj"
do
php obj2js.php "${file}" "-" "set" >> "${models}"
echo -n "," >> "${models}"
done
echo "];" >> "${models}"
# Concatenate the JS files
touch "${jscat}" >/dev/null 2>&1
for file in "random.js" "timeline.js" "font.js" "writer.js" "hudfont.js" "hudwriter.js" "models.js" "3dsvg.js" "hud.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>Airspace Alpha Zulu</title><style>' > "${indexcat}"
# Inject the concatenated and minified CSS files
for file in "main.css"
do
JAVA_CMD=java 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"><svg id="svg" style="width:1280px; height:720px;" viewbox="0 0 640 360"><defs><clipPath id="crop"><rect x="0" y="0" width="640" height="360" /></clipPath><linearGradient id="skygradient" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" style="stop-color:rgb(45,145,194);stop-opacity:1" /><stop offset="100%" style="stop-color:rgb(30,82,142);stop-opacity:1" /></linearGradient></defs><rect width="640" height="360" fill="url(#skygradient)" /><g id="playfield" shaperendering="optimizeSpeed" clip-path="url(#crop)"></g><g id="txthud" shaperendering="optimizeSpeed" clip-path="url(#crop)"></g></svg><canvas id="static_hud" width="640" height="480"></canvas><canvas id="dynamic_hud" width="640" height="480"></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