-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·69 lines (54 loc) · 2.23 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
#!/bin/bash
# Check for work folder specified
if [ $# -eq 1 ]
then
workdir=$1
echo "Entering ${workdir}"
cd "${workdir}"
fi
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 "sprites.js" "spritelib.js" "wichmann-hill_rng.js" "text.js" "timeline.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>Crater Space</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"/><meta name="apple-mobile-web-app-capable" content="yes"/><meta name="mobile-web-app-capable" content="yes"/></head><body><div id="wrapper"><canvas id="threedee" width="400" height="711"></canvas><canvas id="board" width="400" height="711"></canvas><canvas id="fx" width="400" height="711"></canvas><canvas id="ui" width="400" height="711"></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