This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.xml
273 lines (193 loc) · 9.3 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
<?xml version="1.0" encoding="UTF-8"?>
<project default="build" basedir=".">
<property name="module.build.dir" value="${basedir}/build" />
<tstamp>
<format property="now" pattern="yyyyMMddHHmm" />
</tstamp>
<macrodef name="exec-node">
<attribute name="module" description="The name of the NodeJS module to execute" />
<attribute name="failonerror" default="true" description="Fail if the exit code is not 0" />
<attribute name="dir" default="${basedir}" description="" />
<element name="args" implicit="yes" description="Argument to pass to the exec task" />
<sequential>
<exec executable="cmd.exe" failonerror="@{failonerror}" osfamily="winnt" dir="@{dir}">
<arg line="/c @{module}" />
<args/>
<!-- Windows cmd output workaround: http://stackoverflow.com/a/10359327/227349 -->
<!-- Forces node's stderror and stdout to a temporary file -->
<arg line=" > _tempfile.out 2<&1" />
<!-- If command exits with an error, then output the temporary file -->
<!-- to stdout delete the temporary file and finally exit with error level 1 -->
<!-- so that the apply task can catch the error if @failonerror="true" -->
<arg line=" || (type _tempfile.out & del _tempfile.out & exit /b 1)" />
<!-- Otherwise, just type the temporary file and delete it-->
<arg line=" & type _tempfile.out & del _tempfile.out &" />
</exec>
<exec executable="@{module}" failonerror="@{failonerror}" osfamily="unix" dir="@{dir}">
<args/>
</exec>
</sequential>
</macrodef>
<macrodef name="exec-node-out">
<attribute name="module" description="The name of the NodeJS module to execute" />
<attribute name="failonerror" default="true" description="Fail if the exit code is not 0" />
<attribute name="dir" default="${basedir}" description="" />
<attribute name="outputproperty" description="" />
<element name="args" implicit="yes" description="Argument to pass to the exec task" />
<sequential>
<exec executable="cmd.exe" failonerror="@{failonerror}" osfamily="winnt" dir="@{dir}" outputproperty="@{outputproperty}">
<arg line="/c @{module}" />
<args/>
<!-- Windows cmd output workaround: http://stackoverflow.com/a/10359327/227349 -->
<!-- Forces node's stderror and stdout to a temporary file -->
<arg line=" > _tempfile.out 2<&1" />
<!-- If command exits with an error, then output the temporary file -->
<!-- to stdout delete the temporary file and finally exit with error level 1 -->
<!-- so that the apply task can catch the error if @failonerror="true" -->
<arg line=" || (type _tempfile.out & del _tempfile.out & exit /b 1)" />
<!-- Otherwise, just type the temporary file and delete it-->
<arg line=" & type _tempfile.out & del _tempfile.out &" />
</exec>
<exec executable="@{module}" failonerror="@{failonerror}" osfamily="unix" dir="@{dir}" outputproperty="@{outputproperty}">
<args/>
</exec>
</sequential>
</macrodef>
<target name="build" depends="clean, init, npm-install-dev, test" >
<echo message="Building ${package.name}" />
<antcall target="clean" />
<antcall target="npm-install" />
<antcall target="stage" />
<antcall target="generate-build-number" />
<antcall target="package" />
</target>
<target name="ci" depends="init, npm-install-dev, jshint, test" >
<echo message="Running Continuous Integration tests on ${package.name}" />
</target>
<target name="clean" depends="init">
<echo message="Cleaning ${package.name}" />
<!-- Remove build directories -->
<delete dir="${module.build.dir}" />
<delete dir="${basedir}/coverage" />
<delete dir="${basedir}/node_modules" />
</target>
<target name="dev-package" depends="init, npm-install-dev, stage, generate-build-number, package">
<echo message="Development package of ${package.name}" />
</target>
<target name="generate-build-number" depends="init">
<echo message="Generating build number" />
<property name="build.number" value="${now}" />
<echo message="${build.number}" file="${staging.dir}/build-number" />
<copy file="${staging.dir}/package.json" tofile="${staging.dir}/package.json.tmp" />
<delete file="${staging.dir}/package.json" />
<move file="${staging.dir}/package.json.tmp" tofile="${staging.dir}/package.json" />
</target>
<target name="init" depends="package-json">
<echo message="Initializing build for ${package.name}" />
<property name="staging.dir" value="${module.build.dir}/staging" />
<property name="dist.dir" value="${module.build.dir}/dist" />
<mkdir dir="${module.build.dir}" />
<mkdir dir="${staging.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<target name="jshint" depends="init, npm-install-dev">
<echo message="JSHinting ${package.name}" />
<exec-node module="node">
<arg value="node_modules/.bin/jshint" />
<arg value="./" />
</exec-node>
</target>
<target name="npm-install" depends="init">
<echo message="Resolving public dependencies for ${package.name}" />
<exec-node module="npm">
<arg value="install" />
<arg value="--production" />
</exec-node>
</target>
<target name="npm-install-dev" depends="init">
<echo message="Resolving dev dependencies for ${package.name}" />
<exec-node module="npm">
<arg value="install" />
</exec-node>
</target>
<target name="package" depends="init, stage">
<echo message="Packaging ${package.name} to a zip" />
<exec-node-out module="npm" dir="${dist.dir}" outputproperty="pack.out">
<arg value="pack" />
<arg value="${staging.dir}" />
</exec-node-out>
<copy file="${dist.dir}/${pack.out}" tofile="${dist.dir}/${package.name}-latest.tgz" />
</target>
<target name="package-json">
<echo message="Reading package.json" />
<script language="javascript">
importClass(java.io.File);
importClass(java.io.FileReader);
importClass(java.io.BufferedReader);
var file = new File(project.getProperty("basedir") + "/" + "package.json");
fr = new FileReader(file);
br = new BufferedReader(fr);
var data = "";
var line;
while ((line = br.readLine()) != null) {
data += line;
}
var properties = eval("(" + data + ")");
for (var i in properties) {
if (typeof properties[i] === 'string') {
project.setProperty("package." + i, properties[i]);
} else if (typeof properties[i] === 'object') {
for (var x in properties[i]) {
if (typeof properties[i][x] === 'string') {
project.setProperty("package." + i + "." + x, properties[i][x]);
}
}
}
}
</script>
</target>
<target name="publish" depends="clean, init">
<echo message="Publishing a new version of ${package.name}" />
<input message="What do you want to deploy? [major|minor|patch|build|_version_]" addproperty="npm.deploy" />
<!-- Create the tag -->
<exec-node module="npm" dir="${basedir}">
<arg value="version" />
<arg value="${npm.deploy}" />
</exec-node>
<antcall target="build" />
<!-- Publish to NPM -->
<exec-node module="npm">
<arg value="publish" />
<arg value="${dist.dir}/${package.name}-latest.tgz" />
</exec-node>
<!-- Push the tag -->
<exec-node module="git">
<arg value="push" />
<arg value="--tags" />
</exec-node>
<!-- Push the change -->
<exec-node module="git">
<arg value="push" />
</exec-node>
</target>
<target name="stage" depends="init">
<echo message="Staging ${package.name}" />
<echo message="${module.build.dir}" />
<copy todir="${staging.dir}" includeEmptyDirs="true">
<fileset dir=".">
<exclude name="build.xml" />
<exclude name="**/*build*/**" />
<exclude name="**/*coverage*/**" />
<exclude name="**/*nbproject*/**" />
<exclude name="**/*test*/**" />
<exclude name="**/.*/**" />
</fileset>
</copy>
</target>
<target name="test" depends="init, npm-install-dev">
<echo message="Running unit tests for ${package.name} with Mocha" />
<exec-node module="npm">
<arg value="test" />
</exec-node>
</target>
</project>