-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·93 lines (65 loc) · 1.6 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
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -e
## MAKE PAGE HTML
# ARGS:
# $1 = _site/NAME.html
# $2 = <title>
# $3 = uglifyjs stdout
#
function makeHtml {
cat <<EOF > $1
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>$2</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width">
<link rel="icon" type="image/png" href="/heart.png">
</head>
<body>
<script type="text/javascript">
$(cat $3)
var app = Elm.Main.init();
</script>
</body>
</html>
EOF
}
## DOWNLOAD BINARIES
PATH=$(pwd)/node_modules/.bin:$PATH
if ! [ -x "node_modules/.bin/elm" ]; then
npm install [email protected]
fi
if ! [ -x "node_modules/.bin/uglifyjs" ]; then
npm install uglify-js
fi
## GENERATE HTML
mkdir -p _site
mkdir -p _temp
## static
cp -r static/* _site/
## pages
echo "PAGES"
for elm in $(find pages -type f -name "*.elm")
do
subpath="${elm#pages/}"
name="${subpath%.elm}"
js="_temp/$name.js"
html="_site/$name.html"
if [ -f $html ] && [ $(date -r $elm +%s) -le $(date -r $html +%s) ]; then
echo "Cached: $elm"
else
echo "Compiling: $elm"
mkdir -p $(dirname $js)
mkdir -p $(dirname $html)
rm -f elm-stuff/*/Main.elm*
elm make $elm --optimize --output=$js > /dev/null
uglifyjs $js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' \
| uglifyjs --mangle \
| makeHtml $html $name
fi
done
## REMOVE TEMP FILES
rm -rf _temp