summaryrefslogtreecommitdiff
path: root/build_system/make.gzip
blob: a95ed049dc3fcbc601d44ad7de5e12c2a190c795 (plain)
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
#!/bin/bash
#
# ExxonMobil Designer Site Build Script
# by Mike Crute, EYEMG (mcrute@eyemg.com)
#
# This is a pretty simple build script just export a
# tag or the trunk from SVN and run ./make, running
# make (w/out the ./) will not work. You can then 
# take the generated tarball and explode it on the 
# production server w/out any further configuration.
#

cd docroot

# Create the build directory and copy over the cgi-bin
mkdir -p build/{docroot,cgi-bin}
cp -R ../cgi-bin/* build/cgi-bin/

# Create a build date file
echo "Designer Site Built `date +'%Y-%m-%d %H:%M:%S'` EST" > build/docroot/build.date
echo "Code Version: `grep 'releaseVersion' classes/sme.namespace.js | cut -d"'" -f 2 `" >> build/docroot/build.date
echo "Subversion Revision: `svn info | grep 'Revision' | awk '{ print $2 }'`" >> build/docroot/build.date

# Remove stuff from the cgi-bin that does not belong in
# production.
rm build/cgi-bin/*.sql

# Also copy over any files that don't need special processing
cp -R images           \
      blank.gif        \
      favicon.ico      \
      custom_content   \
build/docroot/

# Prepare the .htaccess file for production
#
# We use a sparse layout in development where each class is
# in its own separate file but in production we use a solid
# layout that is also gzipped so we have to un-comment the 
# gzip headers in our htaccess file.

sed '
	/### PRODUCTION ###/,/### END PRODUCTION ###/ {
		/^###.*/d
		s/#//g
	}
' .htaccess > build/docroot/.htaccess

# Minify the PNG Behavior
sed '
	/\/\*/,/\*\// {
		/.*/d;
	}
' pngbehavior.htc > build/docroot/pngbehavior.htc

# Concatenate the Javascript files into a single library file
#
# application.js loads all the javascript files in the development
# environment. When we go to production we need to parse out the
# actual script names being loaded and cat them, in order, into
# the final output application.js file.

# GNU sed uses the -r flag for extended regular expressions,
# Darwin uses the -E flag for regular expressions. If neither
# of these hold true we might as well fail.
if [[ `uname` == 'Linux' ]]; then
	MYFILES=`sed -r -f ../build_system/get_jsfiles.sed  application.js`
elif [[ `uname` == 'Darwin' ]]; then
	MYFILES=`sed -E -f ../build_system/get_jsfiles.sed application.js`
else
	print 'No valid sed command could be determined.'
	exit 1
fi

for item in $MYFILES; do
	cat $item >> build/docroot/application.js.in
done

# Remove development code from the application code
# and append it to the libraries files
sed '/^;;;.*/d' build/docroot/application.js.in >> build/docroot/application.js.out
sed '/^\/\*;;;.*/d' build/docroot/application.js.out >> build/docroot/application.js
rm build/docroot/application.js.in build/docroot/application.js.out

# Minify index.html by removing leading spaces on each line
# as well as the ID comment, blank lines, and any script tags
# that appear in the <head> of the document.
sed 's/^[[:space:]]*//; /^$/d; s/\n$//; /<!--/,/-->/ { /.*/d; }' index.html > build/docroot/index.html
sed 's/^[[:space:]]*//; /^$/d; s/\n$//; /<!--/,/-->/ { /.*/d; }' logged_out.html > build/docroot/logged_out.html

# Minify the application Javascript using the YUI Compressor
java -jar ../build_system/yui_compressor.jar -o application.o build/docroot/application.js > /dev/null 2>&1
mv application.o build/docroot/application.js

# Minify the JSON data files
mkdir -p build/docroot/data
for item in `ls data/`; do
	java -jar ../build_system/yui_compressor.jar -o build/docroot/data/$item data/$item > /dev/null 2>&1
done

# Can't minimize JSON, the semicolon at the end breaks everything
cat data/card_tables.js > build/docroot/data/card_tables.js

# Minify the application CSS using our custom compressor
../build_system/cmpcss application.css > build/docroot/application.css
../build_system/cmpcss specialcases.css > build/docroot/specialcases.css

# Gzip all that should be gzipped. This really should be done server-side
# but for now we work around it by statically compressing them at build time
# and serving it with the correct headers in the .htaccess file
gzip build/docroot/application.js
gzip build/docroot/application.css
gzip build/docroot/index.html

mv build/docroot/application.js.gz build/docroot/application.js
mv build/docroot/application.css.gz build/docroot/application.css
mv build/docroot/index.html.gz build/docroot/index.html

# Tar it all up in a development dump
mv build aes_designer
cd aes_designer

# Removing the date since its really not needed
tar -cjvf ../../aes_designer.tbz2 * > /dev/null 2>&1
#tar -cjvf ../../aes_designer-`date +%Y%m%d_%H%M%S`.tbz2 * > /dev/null 2>&1


cd ..

rm -rf aes_designer/