-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.xml
300 lines (267 loc) · 10.8 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?xml version="1.0"?>
<project name="awld.js" default="build-dev">
<!-- define ant-contrib tasks -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- get properties -->
<property name="config.dir" value="config" />
<property file="${config.dir}/build.properties" />
<property name="src.dir" value="src" />
<property name="release.dir" value="release" />
<property name="current.release.dir" value="${release.dir}/${version.number}"/>
<property name="latest.release.dir" value="${release.dir}/latest"/>
<property name="tmp.dir" value="tmp" />
<property name="js.build" value="${current.release.dir}/awld.js" />
<!-- Build targets -->
<target name="build-production">
<echo>Building production release</echo>
<property name="js.settings" value="${config.dir}/settings.production.js"/>
<property name="js.uglify.compress" value="true"/>
<property name="css.less.compress" value="true"/>
<property name="html.compress" value="true"/>
<!-- This won't work with more than 1 ui module -->
<property name="js.rjs.ui" value="${production.rjs.ui}"/>
<property name="js.rjs.ui.build" value="${tmp.dir}/${production.rjs.ui}.js"/>
<property name="js.uglify.files" value="${production.files.head},
${js.rjs.ui.build},
${production.files.main}"/>
<ant target="-build"/>
</target>
<target name="build-dev"
depends="build-less,
build-templates"/>
<target name="-build"
depends="build-release,
build-templates,
build-less,
-process-rjs-ui,
-uglify-concat-js,
-insert-version,
-copy-modules,
-copy-to-latest,
clean-build"/>
<target name="build-release">
<echo>Set up release directories</echo>
<delete dir="${current.release.dir}"/>
<delete dir="${latest.release.dir}"/>
<mkdir dir="${current.release.dir}"/>
<mkdir dir="${tmp.dir}"/>
</target>
<target name="build-less">
<echo>Processing .less files</echo>
<condition property="css.compress.argument" value="--yui-compress" else="">
<isset property="css.less.compress"/>
</condition>
<for param="file">
<fileset dir="${src.dir}" includes="**/*.less" />
<sequential>
<echo>-- Processing @{file}</echo>
<propertyregex override="yes"
property="css.file" input="@{file}"
regexp="(.*)\.less" replace="\1.css"/>
<exec executable="${lessc}" failonerror="true">
<arg line="${css.compress.argument}"/>
<arg line="@{file} > ${css.file}"/>
</exec>
</sequential>
</for>
</target>
<target name="build-templates">
<echo>Processing templates</echo>
<for param="file">
<fileset dir="${src.dir}" includes="**/*.html" />
<sequential>
<echo>-- Processing @{file}</echo>
<local name="file.compressed"/>
<property name="file.compressed" value="@{file}c"/>
<!-- Compress HTML -->
<if>
<isset property="html.compress"/>
<then>
<java jar="${htmlcompressor.jar}" fork="true" failonerror="true">
<arg line="--remove-quotes"/>
<arg line="-o ${file.compressed} @{file}"/>
</java>
</then>
<else>
<copy file="@{file}" tofile="${file.compressed}" overwrite="true"/>
</else>
</if>
<if>
<isset property="use.handlebars"/>
<then>
<handlebars file="${file.compressed}" outfile="@{file}.js"/>
<!-- Remove temp file -->
<if>
<isset property="html.compress"/>
<then>
<delete file="${file.compressed}"/>
</then>
</if>
</then>
</if>
</sequential>
</for>
</target>
<target name="-process-rjs-ui">
<rjs module="${js.rjs.ui}"/>
</target>
<target name="-copy-modules">
<copy todir="${current.release.dir}/modules">
<fileset dir="${src.dir}/modules"/>
</copy>
<copy todir="${current.release.dir}/lib">
<fileset dir="${src.dir}/lib"/>
</copy>
<copy todir="${current.release.dir}/ui">
<fileset dir="${src.dir}/ui"/>
</copy>
<!-- Now process require module files -->
<exec executable="node" failonerror="true" outputproperty="js.rjs.modules">
<arg line="${config.dir}/get_registry.js"/>
</exec>
<!-- copy, overwriting -->
<for list="${js.rjs.modules}" param="file" trim="true">
<sequential>
<echo>Optimizing module @{file}</echo>
<rjs module="modules/@{file}"/>
<copy tofile="${current.release.dir}/modules/@{file}.js" overwrite="true">
<fileset file="${tmp.dir}/modules/@{file}.js"/>
</copy>
</sequential>
</for>
</target>
<target name="-copy-to-latest">
<copy todir="${latest.release.dir}">
<fileset dir="${current.release.dir}"/>
</copy>
</target>
<target name="clean-build">
<delete dir="${tmp.dir}"/>
</target>
<target name="-uglify-concat-js">
<echo>Minifying and concatenating JS files</echo>
<!-- Compress and add extensions and apps -->
<condition property="js.compress.argument" value="-nc" else="-ns -b">
<isset property="js.uglify.compress"/>
</condition>
<for list="${js.uglify.files}" param="file" trim="true">
<sequential>
<echo>Adding @{file}</echo>
<concat destfile="${js.build}.tmp" append="yes">
<fileset file="@{file}"/>
</concat>
</sequential>
</for>
<echo>Compressing ${js.build}</echo>
<exec executable="${uglify.js}" failonerror="true">
<arg line="--define-from-module "${basedir}/${js.settings}""/>
<arg line="${js.compress.argument}"/>
<arg line="${js.build}.tmp > ${js.build}"/>
</exec>
<delete file="${js.build}.tmp"/>
</target>
<target name="-insert-version">
<replace file="${js.build}" token="AWLD_VERSION" value="'${version.number}'"/>
</target>
<!-- Server targets -->
<target name="start-test-server">
<exec executable="cmd.exe">
<arg line="/K start node ${devserver.js} -s ${test.server.port} -r ." />
</exec>
</target>
<target name="launch-in-browser">
<exec executable="cmd.exe">
<arg line="/K start http://localhost:${test.server.port}/test/pages" />
</exec>
</target>
<target name="serve-test"
depends="build-tests,
start-test-server,
launch-in-browser" />
<!-- Test targets -->
<target name="build-tests" depends="build-production">
<!-- Copy files for "custom" setup test -->
<copy todir="test/pages/custom">
<fileset dir="${src.dir}" />
</copy>
<move file="test/pages/custom/modules" tofile="test/pages/custom/m"/>
<move file="test/pages/custom/lib" tofile="test/pages/custom/l"/>
</target>
<target name="clean-tests">
<delete includeemptydirs="true">
<fileset dir="test/pages/custom">
<include name="**/*" />
<exclude name="**/customModule.js" />
</fileset>
</delete>
</target>
<target name="run-tests" depends="build-tests, start-test-server">
<echo>Running tests</echo>
<property name="suite" value="test/suites"/>
<exec executable="python" failonerror="true">
<arg file="${casper.js}" />
<arg file="test/run.js" />
<arg file="${suite}" />
</exec>
<ant target="clean-tests"/>
</target>
<target name="jshint">
<for param="file">
<fileset dir="${src.dir}">
<include name="**/*.js"/>
<exclude name="**/fragments/*"/>
<exclude name="**/lib/**"/>
<exclude name="**/text.js"/>
</fileset>
<sequential>
<echo>jshint: @{file}</echo>
<exec executable="${jshint}" failonerror="true">
<arg line="@{file}"/>
</exec>
</sequential>
</for>
</target>
<!-- Macros -->
<macrodef name="rjs">
<attribute name="module" default=""/>
<sequential>
<echo>Processing @{module}</echo>
<exec executable="${r.js}" failonerror="true">
<arg line="-o baseUrl=./src exclude=text"/>
<arg line="paths.jquery=empty:"/>
<arg line="paths.handlebars=lib/handlebars.runtime"/>
<arg line="paths.mustache=lib/mustache.0.5.0-dev"/>
<arg line="name=@{module} out=${tmp.dir}/@{module}.js"/>
</exec>
</sequential>
</macrodef>
<macrodef name="handlebars">
<attribute name="file"/>
<attribute name="outfile"/>
<sequential>
<local name="template.name"/>
<basename file="@{file}" property="template.name"/>
<!-- Compile Handlebars -->
<exec executable="${handlebars}" failonerror="true">
<arg line="@{file} -f @{outfile}"/>
</exec>
<!-- Convert for Require.js -->
<replaceregexp file="@{outfile}"
match="^\(function\(\)"
replace="define('ui/${template.name}', ['handlebars'], function(Handlebars)"
/>
<replaceregexp file="@{outfile}"
match="templates\['[^']*'\] = "
replace="return "
/>
<replaceregexp file="@{outfile}"
match="\(\);$"
replace=";"
/>
</sequential>
</macrodef>
</project>