forked from sharpie7/circuitjs1
-
Notifications
You must be signed in to change notification settings - Fork 285
/
dev.sh
executable file
·95 lines (81 loc) · 2.37 KB
/
dev.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
#!/bin/bash
set -o errexit -o nounset # bash script safety
# For GWT download URLs see https://www.gwtproject.org/versions.html
GWT_VERSION="2.8.2"
#GWT_URL="https://github.com/gwtproject/gwt/releases/download/2.10.0/gwt-2.10.0.zip"
#GWT_URL="https://storage.googleapis.com/gwt-releases/gwt-2.9.0.zip"
GWT_URL="https://goo.gl/pZZPXS" # 2.8.2
#GWT_URL="https://goo.gl/TysXZl" # 2.8.1 (does not run)
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
SDK_DIR="$SCRIPT_DIR/.."
GWT_DIR="$SDK_DIR/gwt-$GWT_VERSION"
compile() {
ant build
}
package() {
compile
(
cd "$SCRIPT_DIR/war"
tar czf "$SCRIPT_DIR/circuitjs1.tar.gz" .
)
}
setup() {
# Install Java if no java compiler is present
if ! which javac > /dev/null 2>&1 || ! which ant > /dev/null 2>&1; then
echo "Installing packages may need your sudo password."
set -x
sudo apt-get update
sudo apt-get install -y openjdk-8-jdk-headless ant
set +x
fi
if ! [[ -d "$GWT_DIR" ]]; then
mkdir -p "$SDK_DIR"
(
cd "$SDK_DIR"
wget "$GWT_URL" -O "gwt-$GWT_VERSION.zip"
unzip "gwt-$GWT_VERSION.zip"
rm "gwt-$GWT_VERSION.zip"
set +x
)
fi
if [[ -e build.xml ]]; then
mv build.xml build.xml.backup
fi
chmod +x "$GWT_DIR/webAppCreator"
"$GWT_DIR/webAppCreator" -out ../tempProject com.lushprojects.circuitjs1.circuitjs1
cp ../tempProject/build.xml ./
sed -i 's/source="1.7"/source="1.8"/g' build.xml
sed -i 's/target="1.7"/target="1.8"/g' build.xml
rm -rf ../tempProject
}
codeserver() {
mkdir -p war
java -classpath "src:$GWT_DIR/gwt-codeserver.jar:$GWT_DIR/gwt-dev.jar:$GWT_DIR/gwt-user.jar" \
com.google.gwt.dev.codeserver.CodeServer \
-launcherDir war \
com.lushprojects.circuitjs1.circuitjs1
}
webserver() {
webroot="$SCRIPT_DIR/war"
(
cd $webroot
python -m http.server
)
}
start() {
echo "Starting web server http://127.0.0.1:8000"
trap "pkill -f \"python -m http.server\"" EXIT
webserver >"webserver.log" 2>&1 &
sleep 0.5
codeserver | tee "codeserver.log"
}
for func in $(compgen -A function); do
if [[ $func == "$1" ]]; then
shift
$func "$@"
exit $?
fi
done
echo "Unknown command '$1'. Try one of the following:"
compgen -A function
exit 1