This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_static
executable file
·101 lines (85 loc) · 2.84 KB
/
build_static
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
#!/bin/bash
# quit if there are any errors:
set -e
# show each command as it is executed:
#set -x
abspath () {
python -c "import os, sys; print os.path.abspath(sys.argv[1])" "$1"
}
regex_escape () {
python -c "import re, sys; print re.escape(sys.argv[1])" "$1"
}
HERE="$(dirname $(abspath $BASH_SOURCE))"
SITE="$(dirname $HERE)/"
HOST="https://apps.persona.org"
ORIG_HOST="https://myapps.mozillalabs.com"
APPDIR=""
help () {
echo "Usage: $(basename $0) [-H https://...] [-a APPDIR] DEST"
echo "Builds the site in $SITE and puts it in DEST"
echo "-H sets the hostname (default $HOST)"
echo "-a gives the location of a checkout of apps.mozillalabs.com"
}
while getopts H:a:h o ; do
case "$o" in
H)
HOST="$OPTARG"
;;
a)
APPDIR="$OPTARG"
;;
h)
help
exit
;;
?)
echo "Error in option: $OPTARG"
help
exit 1
;;
esac
done
shift $(expr $OPTIND - 1)
DEST="$1"
if [ -z "$DEST" ] ; then
echo "Error: you must give a DEST"
help
exit 1
fi
if [ "$DEST" = "$SITE" ] ; then
echo "Error: DEST must not be the same as $SITE"
help
exit 1
fi
echo "Building the site from $SITE"
if [ ! -e "$DEST" ] ; then
echo "Creating ${DEST}/"
mkdir -p "$DEST"
fi
cp -R -L ${SITE}/jsapi/* $DEST
if [ ! -z "$APPDIR" ] ; then
mkdir -p ${DEST}/apps
cp --recursive --dereference ${APPDIR}/appdir ${APPDIR}/css ${APPDIR}/i ${APPDIR}/js ${APPDIR}/index.html ${DEST}/apps/
fi
if [ "$HOST" != "$ORIG_HOST" ] ; then
echo "Replacing $ORIG_HOST with $HOST"
find "$DEST" \( -name "*.js" -o -name "*.html" \) -exec \
sed -i "s!$(regex_escape "$ORIG_HOST")!${HOST}!g" {} \;
fi
COMP_DIR="${HERE}/build-compressor"
if [ ! -e "$COMP_DIR" ] ; then
mkdir -p "$COMP_DIR"
echo "Fetching compressor tools"
wget http://htmlcompressor.googlecode.com/files/htmlcompressor-0.9.8.jar -O "${COMP_DIR}/htmlcompressor-0.9.8.jar"
wget http://yui.zenfs.com/releases/yuicompressor/yuicompressor-2.4.2.zip -O "${COMP_DIR}/yuicompressor-2.4.2.zip"
(cd $COMP_DIR ; unzip -j yuicompressor-2.4.2.zip yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar)
fi
echo "Creating minified include.html"
cp ${DEST}/include.html ${DEST}/include.complete.html
${HERE}/compress_html.py ${DEST}/include.html -o ${DEST}/include.html --compress --compressor-dir "$COMP_DIR" --comment "The original (unminified) source is at ${HOST}/include.complete.html"
echo "Creating minified include.js"
cp ${DEST}/include.js ${DEST}/include.complete.js
echo "/* For unminified source see ${HOST}/include.complete.js */" > ${DEST}/include.js
java -jar ${COMP_DIR}/yuicompressor-2.4.2.jar ${DEST}/include.complete.js >> ${DEST}/include.js
echo "Moving homepage into place"
mv ${DEST}/apps.persona.org-index.html ${DEST}/index.html