-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.xml
284 lines (249 loc) · 9.99 KB
/
build.xml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="DotnetMvcBoilerplate" default="build" basedir="../">
<!-- load shell environment -->
<property environment="ENV" />
<property file="build/config/project.properties"/>
<!-- load in Ant-Contrib to give us access to some very useful tasks! -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${tools.dir}/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- load in ant-dotnet to allow us to access MSBuild & NUnit -->
<taskdef resource="org/apache/ant/dotnet/antlib.xml">
<classpath>
<pathelement location="${tools.dir}/ant-dotnet/ant-dotnet-1.1.jar"/>
</classpath>
</taskdef>
<!--
full build process including everything required to validate the project and
getting the project ready for live environment.
-->
<target name="build" depends="-clean, -prepare, -compile, -unit-test, -compile-release, -copytointermediate, -css, -js, -publish, -tidy" />
<!--
removes some of the slower targets in order to test the build process.
-->
<target name="dev" depends="-clean, -prepare, -compile-release, -copytointermediate, -css, -js, -publish, -tidy" />
<!--
optimises all the images in the images directory.
-->
<target name="images" depends="-copyimages, -imagespng, -imageslosslessly" />
<!--
performs js linting on all the js.
-->
<target name="jslint">
<apply dir="${project.dir}/${js.dir}" executable="java" failonerror="true">
<fileset dir="${project.dir}/${js.dir}/">
<include name="*.js" />
<exclude name="/libs/*" />
</fileset>
<arg value="-jar" />
<arg path="${tool.rhino}" />
<arg path="${tool.jslint}" />
<srcfile />
<arg value="${tool.jslint.opts}" />
</apply>
</target>
<!--
deletes the artifacts generated from the previous build,
if there is one.
-->
<target name="-clean" >
<delete dir="${deploy.dir}" />
</target>
<!--
creates any directories that will be required during the
build process.
-->
<target name="-prepare">
<mkdir dir="${deploy.dir}" />
<mkdir dir="${test.reports.dir}" />
</target>
<!--
compiles the solution to ensure there are no errors before
we continue any further.
-->
<target name="-compile">
<nant buildfile="${nant.buildfile}">
<target name="compile" />
</nant>
</target>
<!--
Runs the unit tests copying the reports to the
deploy/test-reports directory.
-->
<target name="-unit-test">
<nant buildfile="${nant.buildfile}">
<target name="unit-test" />
</nant>
</target>
<!--
Compiles a release version of the solution, means
all the debug information will be removed.
-->
<target name="-compile-release">
<nant buildfile="${nant.buildfile}">
<target name="compile-release" />
</nant>
</target>
<!--
Copies the web project into an intermediate location
so we can modify files to speed up js, img & css loading
-->
<target name="-copytointermediate">
<copy todir="${intermediate.dir}">
<fileset dir="${project.dir}" />
</copy>
</target>
<target name="-css" depends="-css.min, -css.cache" />
<!--
Minifies the concatenated css file.
-->
<target name="-css.min">
<apply executable="java">
<fileset dir="${intermediate.dir}/${css.dir}" includes="${default.stylesheets.file}" />
<arg line="-jar"/>
<arg path="${tool.yuicompressor}"/>
<srcfile/>
<arg line="--type css"/>
<arg line="-o"/>
<mapper type="merge" to="${intermediate.dir}/${css.dir}/styles.min.css"/>
<targetfile/>
</apply>
</target>
<!--
Changes the name of the name of the concatenated css file to ensure that any
changes made to the stylesheet are presented to the user. The minified version
of the stylesheet is given a randomly generated new name and the <link> tag
to the main stylesheet file is changed to point at the renamed stylesheet.
-->
<target name="-css.cache">
<checksum file="${intermediate.dir}/${css.dir}/styles.min.css" algorithm="sha" property="css.fullsha" />
<propertyregex property="css.sha" input="${css.fullsha}" regexp=".{${hash.length}}" select="\0" />
<property name="style.css" value="${css.dir}/${css.sha}.css" />
<copy file="${intermediate.dir}/${css.dir}/styles.min.css" tofile="${intermediate.dir}/${css.dir}/${css.sha}.css" />
<replaceregexp match="<link(.+)href=['"]?(.*)/${default.stylesheets.file}(?:\?.*)?['"\s]?(.*/?>)"
replace="<link\1href='\2/${css.sha}.css'\3" flags="m">
<fileset dir="${intermediate.dir}" includes="${page-files}"/>
</replaceregexp>
<delete includeemptydirs="true">
<fileset dir="${intermediate.dir}/css" excludes="${css.sha}.css" />
</delete>
</target>
<target name="-js" depends="-js.concat, -js.min, -js.cache" />
<!--
Minifies the concatenateed javascript file.
-->
<target name="-js.min">
<apply executable="java">
<fileset dir="${intermediate.dir}/${js.dir}" includes="scripts.js"/>
<arg line="-jar"/>
<arg path="${tool.yuicompressor}"/>
<srcfile/>
<arg line="--type js"/>
<arg line="-o"/>
<mapper type="merge" to="${intermediate.dir}/${js.dir}/scripts.min.js"/>
<targetfile/>
</apply>
</target>
<!--
Concats all the js files that are inside the page files specified. These
js files are placed into a single file scripts.js file that is then copied
into a file with a cache buster name that is generated using the checksum.
-->
<target name="-js.concat">
<filelist id="file.root" dir="${intermediate.dir}" files="${page-files}" />
<apply executable="java" outputproperty="scripts.ordered">
<arg value="-cp"/>
<arg value="${tools.dir}/misc/" />
<arg value="ScriptsToConcat"/>
<first>
<filelist refid="file.root"/>
</first>
</apply>
<for param="js.file" list="${scripts.ordered}">
<sequential>
<concat destfile="${intermediate.dir}/${js.dir}/scripts.js" append="yes">
<filelist dir="${intermediate.dir}" files="@{js.file}"/>
</concat>
</sequential>
</for>
</target>
<!--
Changes the name of the main concatenated scripts file to ensure that any
the primary javascript file is never loaded from cached when a release is pushed.
The collection of javascript files in between the marker comments are removed and
replaced with the name of the new cache busting java script file.
-->
<target name="-js.cache">
<checksum file="${intermediate.dir}/${js.dir}/scripts.min.js" algorithm="sha" property="scripts.fullsha" />
<propertyregex property="scripts.sha" input="${scripts.fullsha}" regexp=".{${hash.length}}" select="\0" />
<property name="scripts.js" value="${intermediate.dir}/${js.dir}/${scripts.sha}.js" />
<copy file="${intermediate.dir}/${js.dir}/scripts.min.js" tofile="${intermediate.dir}/${js.dir}/${scripts.sha}.js" />
<var name="matchRegex" value="<!-- scripts concatenated [\d\w\s\W]*[\d\w\s\W]*<!-- end ((scripts)|(concatenated and minified scripts))\s*-->" />
<var name="replaceRegex" value="<script async src='/${js.dir}/${scripts.sha}.js\'></script>" />
<replaceregexp match="${matchRegex}" replace="${replaceRegex}" flags="m">
<fileset dir="${intermediate.dir}" includes="${page-files}"/>
</replaceregexp>
</target>
<!--
publishes the intermediate project into a working website.
-->
<target name="-publish">
<nant buildfile="${nant.buildfile}">
<target name="publish" />
</nant>
</target>
<!--
Removes directories and files that are no longer used.
-->
<target name="-tidy">
<delete dir="${intermediate.dir}" />
</target>
<!--
copies all the images into a seperate directory so they
can be manipulated.
-->
<target name="-copyimages">
<delete dir="${project.dir}/${optimised.images.dir}" />
<copy todir="${project.dir}/${optimised.images.dir}">
<fileset dir="${project.dir}/${images.dir}">
<exclude name="**/*.md" />
</fileset>
</copy>
</target>
<!--
Optimises all the PNG images to reduce their file size, this
may take a while depending on how many images there are.
-->
<target name="-imagespng">
<delete>
<fileset dir="${project.dir}/${optimised.images.dir}/">
<include name="**/*.png" />
</fileset>
</delete>
<apply executable="${tool.optipng}" dest="${project.dir}/${optimised.images.dir}/" osfamily="windows">
<fileset dir="${project.dir}/${images.dir}/" includes="**/*.png" excludes="${images.bypass}, ${images.default.bypass}"/>
<arg value="-quiet"/>
<arg value="-o7"/>
<arg value="-out"/>
<targetfile/>
<srcfile/>
<mapper type="identity"/>
</apply>
</target>
<!--
Optimises all the images with losslessly compression.
-->
<target name="-imageslosslessly">
<java jar="${tool.smushit}"
fork="true"
failonerror="false"
maxmemory="128m">
<arg value="-imageDir=${project.dir}/${optimised.images.dir}"/>
<arg value="-verbose=true" />
<arg value="-imgExtensions=png,jpeg,jpg" />
</java>
</target>
</project>