-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·81 lines (65 loc) · 2.62 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
80
81
#!/bin/bash
zipfile="js13k.zip"
buildpath="tmpbuild"
jscat="${buildpath}/min.js"
indexcat="${buildpath}/index.html"
leveljs="levels.js"
# Create clean build folder
rm -Rf "${buildpath}" >/dev/null 2>&1
rm -Rf "${zipfile}" >/dev/null 2>&1
mkdir "${buildpath}"
# Concatenate the JSON level files
echo "var levels=[" > "${leveljs}"
for file in level*.json
do
cat "${file}" | sed 's/ 0,/,/g' | sed 's/, /,/g' | egrep -v '(name|type|visible|opacity|image|orientation|margin|spacing|version|rotation|draworder|renderorder|tilecount|columns|nextobjectid|firstgid|"id")' >> "${leveljs}"
echo "," >> "${leveljs}"
done
echo "];" >> "${leveljs}"
# Concatenate the JS files
touch "${jscat}" >/dev/null 2>&1
for file in random.js timeline.js dtmf.js music.js font.js writer.js levels.js main.js
do
yui-compressor "${file}" >> "${jscat}"
done
# Remove some fluff from the levels
sed -i "s/,width:0,/,/g" "${jscat}"
sed -i "s/,height:0,/,/g" "${jscat}"
sed -i "s/,width:64,/,/g" "${jscat}"
sed -i "s/,height:64,/,/g" "${jscat}"
sed -i "s/properties:{},//g" "${jscat}"
# Copy minified JS from build folder
cp "${jscat}" "${jscat}.b.js"
./closeyoureyes.sh "${jscat}.b.js" > "${jscat}" 2>/dev/null
# Remove the minified JS
rm "${jscat}.b.js" >/dev/null 2>&1
# 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>Planet Figadore has gone OFFLINE</title><style>' > "${indexcat}"
# Concatenate the CSS files
for file in main.css tiles.css collect.css player.css enemy.css
do
yui-compressor "${file}" >> "${indexcat}"
done
# Add on the rest of the index file
echo -n '</style><script type="text/javascript">' >> "${indexcat}"
cat "${jscat}" >> "${indexcat}"
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"><div id="background"></div><div id="playfield" level="0"></div><div id="player"></div></div><div id="ui"></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