-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
335 lines (253 loc) · 10.2 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?xml version="1.0" encoding="utf-8"?>
<project
name="build"
basedir="."
default="build.all"
>
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!-- ///////////////////////////////////// PROPERTIES ////////////////////////////////////// -->
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!--
The file contains a single property named typescript.compiler.path which can contain
user name of system login which you may don't want to publish on the web.
Instructions given in the user.properties.sample file included in the project.
-->
<property file="build/user.properties" />
<!--
Standard project properties, including name of the release file to build.
-->
<property file="build/build.properties" />
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!-- //////////////////////////////////////// MACRO //////////////////////////////////////// -->
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!--
Recursively read a source directory for TypeScript files, generate a compile list in the
format needed by the TypeScript compiler adding every parameters it take.
-->
<macrodef name="TypeScriptCompileDir">
<!-- required attribute -->
<attribute name="src" />
<!-- optional attributes -->
<attribute name="out" default="" />
<attribute name="module" default="" />
<attribute name="comments" default="" />
<attribute name="declarations" default="" />
<attribute name="nolib" default="" />
<attribute name="target" default="" />
<sequential>
<!-- local properties -->
<local name="out.arg"/>
<local name="module.arg"/>
<local name="comments.arg"/>
<local name="declarations.arg"/>
<local name="nolib.arg"/>
<local name="target.arg"/>
<local name="typescript.file.list"/>
<local name="tsc.compile.file"/>
<property name="tsc.compile.file" value="@{src}compile.list" />
<!-- Optional arguments are not written to compile file when attributes not set -->
<condition property="out.arg" value="" else='--out "@{out}"'>
<equals arg1="@{out}" arg2="" />
</condition>
<condition property="module.arg" value="" else="--module @{module}">
<equals arg1="@{module}" arg2="" />
</condition>
<condition property="comments.arg" value="" else="--comments">
<equals arg1="@{comments}" arg2="" />
</condition>
<condition property="declarations.arg" value="" else="--declarations">
<equals arg1="@{declarations}" arg2="" />
</condition>
<condition property="nolib.arg" value="" else="--nolib">
<equals arg1="@{nolib}" arg2="" />
</condition>
<!-- Could have been defaulted to ES3 but let the compiler uses its own default is quite better -->
<condition property="target.arg" value="" else="--target">
<equals arg1="@{target}" arg2="" />
</condition>
<!-- Recursively read TypeScript source directory and generate a compile list -->
<pathconvert property="typescript.file.list" dirsep="\" pathsep="${line.separator}">
<fileset dir="@{src}">
<include name="**/*.ts" />
</fileset>
<!-- In case regexp doesn't work on your computer, comment <mapper /> and uncomment <regexpmapper /> -->
<mapper type="regexp" from="^(.*)$" to='"\1"' />
<!--regexpmapper from="^(.*)$" to='"\1"' /-->
</pathconvert>
<!-- Write to the file -->
<echo message="Writing tsc command line arguments to : ${tsc.compile.file}" />
<echo file="${tsc.compile.file}" message="${typescript.file.list}${line.separator}${out.arg}${line.separator}${module.arg}${line.separator}${comments.arg}${line.separator}${declarations.arg}${line.separator}${nolib.arg}${line.separator}${target.arg}" append="false" />
<!-- Compile using the generated compile file -->
<echo message="Calling ${typescript.compiler.path} with ${tsc.compile.file}" />
<exec dir="@{src}" executable="${typescript.compiler.path}">
<arg value="@${tsc.compile.file}"/>
</exec>
<!-- Finally delete the compile file -->
<echo message="${tsc.compile.file} deleted" />
<delete file="${tsc.compile.file}" />
</sequential>
</macrodef>
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!-- /////////////////////////////////////// COMPILE /////////////////////////////////////// -->
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<target name="compile.src" description="Concatenate and minifiy a set of files">
<!--
Because the TypeScript compiler doesn't know how to output a specific file to a specific
path. We let it output JavaScript compiled files beside TypeScript files. As the
TypeScript files must be removed at the end of the operation, it's better to work on a
copy of the source files for obvious reasons. The generated directory will also be used
to debug plain JavaScript files stored in their respective class path.
Ant can fix the problem using <apply /> and <redirector /> but it is way too slow
because it process each file independently in a tsc call for each file.
-->
<copy todir="${src-js.dir}" overwrite="true">
<fileset dir="${src.dir}">
<include name="**/*.ts" />
</fileset>
</copy>
<!-- Compile a single JavaScript file in the bin dir for release -->
<TypeScriptCompileDir
src="${src-js.dir}"
out="${release-file-path}"
declarations="${release-declaration-file-path}"
module="amd"
/>
<!-- Compile plain JavaScript files in their respective directories for debug -->
<TypeScriptCompileDir
src="${src-js.dir}"
module="amd"
/>
<antcall target="clean.src-js" />
</target>
<target name="compile.test" description="Concatenate and minifiy a set of files">
<!--
Because the TypeScript compiler doesn't know how to output a specific file to a specific
path. We let it output JavaScript compiled files beside TypeScript files. As the
TypeScript files must be removed at the end of the operation, it's better to work on a
copy of the source files for obvious reasons. The generated directory will also be used
to debug plain JavaScript files stored in their respective class path.
Ant can fix the problem using <apply /> and <redirector /> but it is way too slow
because it process each file independently in a tsc call for each file.
-->
<copy todir="${test-src-js.dir}" overwrite="true">
<fileset dir="${test-src.dir}">
<include name="**/*.ts" />
</fileset>
</copy>
<!-- Compile plain JavaScript files in their respective directories for debug -->
<TypeScriptCompileDir
src="${test-src-js.dir}"
module="amd"
/>
<antcall target="clean.test-src-js" />
</target>
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!-- /////////////////////////////////////// MINIFY //////////////////////////////////////// -->
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<target name="compress" description="Minifiy the release JavaScript file">
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<pathelement path="${yuicompressor.file}" />
<pathelement path="${yuiant.file}" />
</classpath>
</taskdef>
<yuicompress
charset="UTF-8"
linebreak="500"
warn="false"
munge="yes"
preserveallsemicolons="false"
preservestringlitterals="false"
outputfolder="${bin.dir}"
outputsuffix="-min"
>
<fileset dir="${bin.dir}">
<include name="*.js"/>
</fileset>
</yuicompress>
</target>
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!-- //////////////////////////////////////// CLEAN //////////////////////////////////////// -->
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<target
name="clean.all"
description="Clean bin directory"
depends=
"
clean.bin,
clean.test-src-js,
remove.src-js,
remove.test-src-js
"
/>
<target name="clean.bin" description="Clean bin directory">
<delete>
<fileset dir="${bin.dir}">
<include name="*.js" />
<include name="*.ts" />
</fileset>
</delete>
</target>
<target name="clean.src-js" description="Clean src-js output directory from its TypeScript files">
<delete>
<fileset dir="${src-js.dir}">
<include name="**/*.ts" />
</fileset>
</delete>
</target>
<target name="clean.test-src-js" description="Clean test src-js output directory from its TypeScript files ">
<delete>
<fileset dir="${test-src-js.dir}">
<include name="**/*.ts" />
</fileset>
</delete>
</target>
<target name="remove.src-js" description="Remove the src-js output directory from the project">
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${src-js.dir}" />
</delete>
</target>
<target name="remove.test-js" description="Remove the test-js output directory from the project">
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${test-src-js.dir}/" />
</delete>
</target>
<target name="remove.test-src-js" description="Remove the test-src-js output directory from the project">
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${test-src-js.dir}/" />
</delete>
</target>
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<!-- //////////////////////////////////////// BUILD //////////////////////////////////////// -->
<!-- /////////////////////////////////////////////////////////////////////////////////////// -->
<target
name="build.src"
description="Compile src from TypeScript to JavaScript, concatenate and minify it into a single file"
depends=
"
clean.bin,
remove.src-js,
compile.src,
compress
"
/>
<target
name="build.test"
description="Compile tests from TypeScript to JavaScript"
depends=
"
clean.bin,
remove.test-js,
compile.test
"
/>
<target
name="build.all"
description="Compile TypeScript to JavaScript, concatenate JavaScript and minify sets of JavaScript files"
depends=
"
build.src,
build.test
"
/>
</project>