1 | #!/bin/bash |
---|
2 | |
---|
3 | set -e |
---|
4 | |
---|
5 | # Base directory for this entire project |
---|
6 | BASEDIR=$(cd $(dirname $0) && pwd) |
---|
7 | |
---|
8 | # Source directory for unbuilt code |
---|
9 | SRCDIR="$BASEDIR" |
---|
10 | |
---|
11 | # Directory containing dojo build utilities |
---|
12 | TOOLSDIR="$SRCDIR/util/buildscripts" |
---|
13 | |
---|
14 | # Destination directory for built code |
---|
15 | DISTDIR="$BASEDIR/dist" |
---|
16 | |
---|
17 | # Main application package loader configuration |
---|
18 | LOADERCONF="$SRCDIR/rft/main.js" |
---|
19 | |
---|
20 | # Main application package build configuration |
---|
21 | PROFILE="$SRCDIR/rft/rft.profile.js" |
---|
22 | |
---|
23 | # Configuration over. Main application start up! |
---|
24 | |
---|
25 | if [ ! -d "$TOOLSDIR" ]; then |
---|
26 | echo "Can't find Dojo build tools -- did you initialise submodules? (git submodule update --init --recursive)" |
---|
27 | exit 1 |
---|
28 | fi |
---|
29 | |
---|
30 | echo "Building application with $PROFILE to $DISTDIR." |
---|
31 | |
---|
32 | echo -n "Cleaning old files..." |
---|
33 | rm -rf "$DISTDIR" |
---|
34 | echo " Done" |
---|
35 | |
---|
36 | cd "$TOOLSDIR" |
---|
37 | |
---|
38 | if which node >/dev/null; then |
---|
39 | node ../../dojo/dojo.js load=build --require "$LOADERCONF" --profile "$PROFILE" --releaseDir "$DISTDIR" "$@" |
---|
40 | elif which java >/dev/null; then |
---|
41 | java -Xms256m -Xmx256m -cp ../shrinksafe/js.jar:../closureCompiler/compiler.jar:../shrinksafe/shrinksafe.jar org.mozilla.javascript.tools.shell.Main ../../dojo/dojo.js baseUrl=../../dojo load=build --require "$LOADERCONF" --profile "$PROFILE" --releaseDir "$DISTDIR" "$@" |
---|
42 | else |
---|
43 | echo "Need node.js or Java to build!" |
---|
44 | exit 1 |
---|
45 | fi |
---|
46 | |
---|
47 | cd "$BASEDIR" |
---|
48 | |
---|
49 | LOADERMID=${LOADERMID//\//\\\/} |
---|
50 | |
---|
51 | # Copy & minify index.html to dist |
---|
52 | cat "$SRCDIR/index.html" | tr '\n' ' ' | \ |
---|
53 | perl -pe " |
---|
54 | s/<\!--.*?-->//g; # Strip comments |
---|
55 | s/isDebug: *1/deps:['$LOADERMID']/; # Remove isDebug, add deps |
---|
56 | s/<script src=\"$LOADERMID.*?\/script>//; # Remove script app/run |
---|
57 | s/\s+/ /g; # Collapse white-space" > "$DISTDIR/index.html" |
---|
58 | |
---|
59 | echo "Build complete" |
---|