forked from witheve/Eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·164 lines (147 loc) · 3.67 KB
/
run.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
waitUrl="$(pwd)/ui/waiting-room.html"
rustVersion="nightly-2015-09-17"
tscVersion="1.6.0-dev.20150731"
tscBin="$(pwd)/ui/node_modules/typescript/bin/tsc"
mode="run"
debugFlag=false
noBrowserFlag=false
# Parse command line options.
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "Compile and run the Eve editor"
echo ""
echo "Usage:"
echo " run.sh [command = run] [options]"
echo ""
echo "Commands:"
echo " run (Default) Build and run eve"
echo " build Build editor and runtime server"
echo " test Execute the eve test suite"
echo ""
echo "Options:"
echo " -h, --help Print this message"
echo " -d, --debug Debug build"
echo " -n, --no-browser Do not open editor in browser"
exit 0
;;
run|build|test)
mode="$1"
;;
-d|--debug)
debugFlag=true
;;
-n|--no-browser)
noBrowserFlag=true
;;
*)
echo "Unkown option $1"
;;
esac
shift
done
if [[ "$mode" == "test" ]]; then
./test.sh
exit $?
fi
# Install githooks
printf "* Installing commit hooks..."
for hook in "$(ls ./githooks/)"; do
if [[ "x$hook" != "x" ]]; then
cp "./githooks/$hook" "./.git/hooks/$hook"
fi
done
echo "done."
# Ensure that dependencies are installed.
deps="npm multirust $tscBin"
function installCommand {
msg=""
case "$1" in
"$tscBin")
cd ./ui
out=$(npm install)
$res=$?
cd ..
return $out
;;
multirust)
msg="./install-multirust.sh"
;;
*)
msg="Please consult the internet for instructions on installing this on your distribution."
;;
esac
printf "\n x Please install $1:\n"
echo " $msg"
exit 1
}
printf "* Checking dependencies..."
for dep in $deps; do
if ! which "$dep" &> /dev/null; then
installCommand $dep
fi
done
# Check tsc version
version=$($tscBin --version)
if [[ "$version" != *"Version $tscVersion"* ]]; then
echo ""
echo " x Eve requires tsc version \"$tscVersion\" but \"$version\" is installed. Please reinstall using:"
echo " cd ui && npm install && cd .. before continuing."
exit 1
fi
echo "done."
# Try using the TypeScript compiler (tsc) to compile UI.
printf "* Compiling editor..."
pushd . &> /dev/null
cd "ui";
tscError=$($tscBin)
if [ $? -ne 0 ]; then
printf "\n x %s\n" "$tscError"
popd &> /dev/null
exit 1
else
echo "done."
fi
popd &> /dev/null
# If noBrowserFlag is false open the editor in the user's preferred browser.
if ! $noBrowserFlag && [[ $mode == "run" ]]; then
echo "* Opening editor: $waitUrl"
if [[ "$OSTYPE" == "darwin"* ]]; then
open "$waitUrl" &> /dev/null
else
xdg-open "$waitUrl" &> /dev/null
fi
fi
pushd . &> /dev/null
cd runtime
# Ensure Rust is updated.
multirust list-toolchains | grep "$rustVersion" &> /dev/null
if [ $? -eq 0 ]; then
echo "* Rust is up to date."
multirust override "$rustVersion" &> /dev/null
else
printf "* Updating Rust..."
multirustOutputFile="multirust-output.log"
multirust override "$rustVersion" &> "$multirustOutputFile"
if [ $? -ne 0 ]; then
cat "$multirustOutputFile"
rm "$multirustOutputFile"
exit 1
else
echo "done."
fi
fi
# Compile and run server.
rustFlags="--release"
if $debugFlag; then
rustFlags=""
fi
if [[ "$mode" == "build" ]]; then
echo "* Compiling server. This takes a while..."
RUST_BACKTRACE=1 cargo build --bin=server $rustFlags
else
echo "* Compiling and running server. This takes a while..."
RUST_BACKTRACE=1 cargo run --bin=server $rustFlags
fi
popd &> /dev/null