-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBakefile
53 lines (40 loc) · 1.06 KB
/
Bakefile
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
#!/bin/bash
DIST=qr.png
serve() {
waiter --dev
}
inspect() {
tot=2000
cur=$(p:minify_js | p:inject_js | p:build_url | p:encode_url | wc -c | awk '{$1=$1;print}')
per=$(echo "scale=2; ($cur / $tot) * 100" | bc)
echo "max: $tot bytes"
echo "cur: $cur bytes"
echo
echo "used $per% of available space"
}
build() {
p:minify_js | p:inject_js | p:build_url | p:encode_url | p:generate_qr
}
copy() {
p:minify_js | p:inject_js | p:build_url | p:encode_url | pbcopy
}
run() {
open -a /Applications/Google\ Chrome.app "$(p:minify_js | p:inject_js | p:build_url)"
}
# Helpers for constructing the URL and QR code.
p:minify_js() {
uglifyjs -mc unsafe --toplevel -- index.js
}
p:inject_js() {
stdin=$(cat)
cat index.html | python3 -c "import sys; print(sys.stdin.read().replace(sys.argv[1], sys.argv[2]))" '<script type=module src=index.js></script>' "<script type=module>$(echo $stdin)</script>"
}
p:build_url() {
echo "data:text/html,$(cat | tr -d '\n')"
}
p:encode_url() {
sed 's/#/%23/g' | sed 's/ /%20/g'
}
p:generate_qr() {
qrencode -o $DIST
}