-
Notifications
You must be signed in to change notification settings - Fork 2
/
task
executable file
·89 lines (75 loc) · 2.07 KB
/
task
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
82
83
84
85
86
87
88
89
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
GAMES=(wow trap rope)
JS13K_GAMES=(none)
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
function js13k {
printf "${GREEN}JS13K${NC}\n"
echo "Building..."
echo "import main from './src/${GAME}.js'; main();" | \
npx rollup -c tools/rollup.js13k.mjs -o "www/${GAME}/js13k.js"
node tools/generate_js13k.mjs "${GAME}"
# rm -f "www/${GAME}/js13k.js"
echo "Packing..."
zip -q www/${GAME}/js13k.zip www/${GAME}/index.html
advzip -q -4 -i 100 -z www/${GAME}/js13k.zip
mv www/${GAME}/index.html www/${GAME}/js13k.html
PRESIZE=`cat www/${GAME}/js13k.html | wc -c`
ZIPSIZE=`cat www/${GAME}/js13k.zip | wc -c`
printf "JS13K size: ${PRESIZE} -> ${YELLOW}${ZIPSIZE}${GREEN} ($((100*ZIPSIZE/13312))%%)${NC}\n"
if (( $ZIPSIZE > 13312 )); then
printf "🚨 ${RED}Pack too big for JS13K${NC} 🚨\n"
fi
}
function build {
GAME="$1"
echo "Building $GAME"
rm -rf "www/${GAME}"
mkdir "www/${GAME}"
if echo ${JS13K_GAMES[@]} | grep -ow "${GAME}"; then js13k; fi
echo "import main from './src/${GAME}.js'; main();" | \
npx rollup -c tools/rollup.mjs -o "www/${GAME}/bundle.js"
node tools/generate_page.mjs "${GAME}"
rm -f "www/${GAME}/bundle.js"
node tools/take_screenshots.mjs "${GAME}"
PRESIZE=`cat www/${GAME}/index.html | wc -c`
GZIPSIZE=`gzip -9 -c www/${GAME}/index.html | wc -c`
printf "Final size: ${PRESIZE} -> ${YELLOW}${GZIPSIZE}${NC}\n"
echo "optimizing PNGs..."
optipng -quiet www/${GAME}/*.png
}
function rebuild {
rm -rf www/
mkdir www/
buildall
}
function buildall {
\cp page.html www/index.html
\cp icon.png www/
for g in ${GAMES[@]}; do
if [ ! -d "www/$g" ]; then
build "$g"
else
echo "Skipping $g"
fi
done
}
function sync {
buildall
rsync -a --partial --progress www/ metaphora:one/
}
function update-deps {
yarn upgrade-interactive --latest
rollup -c tools/planck.rollup.js
}
function help {
echo "$0 <task> <args>"
echo "Tasks:"
compgen -A function | grep -v "^_" | cat -n
}
TIMEFORMAT="Task completed in %3lR"
time "${@:-help}"