forked from Blockstream/esplora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·41 lines (30 loc) · 1.11 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
#!/bin/bash
set -xeo pipefail
shopt -s extglob
for flavor in "$@"; do source flavors/$flavor/config.env; done
export DEST=${DEST:-dist}
export NODE_ENV=${NODE_ENV:=production}
export BASE_HREF=${BASE_HREF:-/}
export API_URL=${API_URL:-"${BASE_HREF}api"}
mkdir -p $DEST
rm -rf $DEST/*
[[ -d node_modules ]] || npm install
(cd client && [[ -d node_modules ]] || npm install)
# Static assets
cp -rL www/* $CUSTOM_ASSETS $DEST/
# CSS customizations
[ -n "$CUSTOM_CSS" ] && cat $CUSTOM_CSS >> $DEST/style.css
# Index HTML
pug client/index.pug -o $DEST
# Open search (requires absolute CANONICAL_URL)
if [ -n "$CANONICAL_URL" ]; then
pug client/opensearch.pug -E xml -o $DEST
fi
# RTLify CSS
cat $DEST/style.css | node -p "require('cssjanus').transform(fs.readFileSync('/dev/stdin').toString(), false, true)" > $DEST/style-rtl.css
# Browserify bundle
(cd client && browserify -p bundle-collapser/plugin src/run-browser.js \
| ( [[ "$NODE_ENV" != "development" ]] && uglifyjs -cm || cat ) ) \
> $DEST/app.js
# Pre-render notfound.html
babel-node render-view.js '{"view":"error","error":"Page Not Found"}' > $DEST/notfound.html