forked from haskell-infra/www.haskell.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildAndWatch
executable file
·115 lines (100 loc) · 3.13 KB
/
buildAndWatch
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
set -eou pipefail
function buildAndWatchWithNix() {
if [[ -n "${IN_NIX_SHELL+x}" ]]; then
echo "buildAndWatch does not work inside of a nix shell. Please exit the nix-shell and retry."
exit 1
fi
if [[ ! -x $(type -P "nix-build") ]]; then
echo "nix-build is not available. Please install nix from https://nixos.org/download.html"
exit 1
fi
nix-build -A builder && \
./result/bin/haskell-org-site clean && \
./result/bin/haskell-org-site build && \
./result/bin/haskell-org-site watch
exit 0
}
function buildAndWatchWithoutNix() {
if [[ ! -x $(type -P "cabal") ]]; then
echo "Please download and install a haskell environment. See: https://www.haskell.org/downloads/"
exit 1
fi
pushd builder
cabal v2-build
builder=$(cabal v2-exec -- which haskell-org-site)
popd
if [[ ! -x "${builder}" ]]; then
cat <<EOF
After building 'haskell-org-site' I was unable to find the path to a
runnable executable. This may be because of a bug in this script. You
may want to try to build and run the builder manually, ask for help,
or submit a bug report.
EOF
exit 1
fi
"${builder}" clean
"${builder}" build
"${builder}" watch
exit 0
}
function buildAndWatchAuto() {
if [[ -x $(type -P "nix-build") ]]; then
if [[ -n "${IN_NIX_SHELL+x}" ]]; then
cat <<EOF
I found a 'nix' installation, but we're currently inside of a nix
shell. I will try to build using cabal. If building with cabal fails,
you should try to re-run this script when you are not inside of a nix
shell.
EOF
buildAndWatchWithoutNix
else
buildAndWatchWithNix
fi
else
buildAndWatchWithoutNix
fi
}
function showHelp() {
cat <<EOF
Usage: buildAndWatch [buildMode]
Build the haskell.org site builder, compile the site, and start a
local server on port 8000 to preview changes.
buildAndWatch takes a single optional argument, 'buildMode'. If it's
omitted, buildAndWatch will attempt to select the best method for
building the site based on your current environment. If you provide an
argument, it may be one of the following:
auto (default) Automatically select between 'nix' or 'cabal' based on the
current environment.
nix Use nix to build the site
cabal Use cabal to build the site. If you are in a nix shell,
it will use your nix environment. Otherwise, it will use
your system-wide cabal installation.
help Show this help message and exit
EOF
}
function buildAndWatchWithArgs() {
case ${1} in
"auto")
buildAndWatchAuto
;;
"nix")
buildAndWatchWithNix
;;
"cabal")
buildAndWatchWithoutNix
;;
"help")
showHelp
;;
*)
echo "Unrecognized or missing arguments"
showHelp
exit 1
esac
}
if [[ $# -gt 0 ]]; then
buildAndWatchWithArgs "${1}"
else
buildAndWatchWithArgs "auto"
fi