This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
build-common-node.xml
337 lines (290 loc) · 9.32 KB
/
build-common-node.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
336
337
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="build-common-node" xmlns:antelope="antlib:ise.antelope.tasks">
<macrodef name="check-system-node">
<sequential>
<if>
<and>
<not>
<isset property="nodejs.system.version" />
</not>
<not>
<isset property="nodejs.system.version.checked" />
</not>
</and>
<then>
<exec dir="${user.dir}" executable="node" failifexecutionfails="false" outputproperty="nodejs.system.version">
<arg value="--version" />
</exec>
<property name="nodejs.system.version.checked" value="true" />
<if>
<isset property="nodejs.system.version" />
<then>
<mkdir dir="${sdk.tools.dir}/node-${nodejs.system.version}" />
</then>
</if>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="config-js-modules">
<attribute name="module.dir" />
<sequential>
<mkdir dir="@{module.dir}/.js-cache/META-INF/resources" />
<download-node-module
node.module.name="lfr-module-config-generator"
node.module.version="${nodejs.modules.version[lfr-module-config-generator]}"
/>
<node-execute
node.command="node"
node.command.args="${sdk.tools.dir}/node-v${nodejs.version}/node_modules/lfr-module-config-generator/bin/index.js -c '' -e '' -f /_/g,- -i true -m @{module.dir}/.js-cache/bower.json -o @{module.dir}/.js-cache/META-INF/config.json -r @{module.dir}/.js-cache/META-INF/resources @{module.dir}/.js-cache"
node.working.dir="${sdk.tools.dir}/node-v${nodejs.version}"
/>
</sequential>
</macrodef>
<macrodef name="download-node">
<sequential>
<if>
<and>
<os family="mac" />
<equals arg1="${sun.arch.data.model}" arg2="32" />
</and>
<then>
<propertycopy from="nodejs.url[osx32]" name="nodejs.url" />
</then>
<elseif>
<and>
<os family="mac" />
<equals arg1="${sun.arch.data.model}" arg2="64" />
</and>
<then>
<propertycopy from="nodejs.url[osx64]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<and>
<os family="unix" />
<equals arg1="${sun.arch.data.model}" arg2="32" />
</and>
<then>
<propertycopy from="nodejs.url[linux32]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<and>
<os family="unix" />
<equals arg1="${sun.arch.data.model}" arg2="64" />
</and>
<then>
<propertycopy from="nodejs.url[linux64]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<and>
<os family="windows" />
<equals arg1="${sun.arch.data.model}" arg2="32" />
</and>
<then>
<propertycopy from="nodejs.url[windows32]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<and>
<os family="windows" />
<equals arg1="${sun.arch.data.model}" arg2="64" />
</and>
<then>
<propertycopy from="nodejs.url[windows64]" name="nodejs.url" />
</then>
</elseif>
</if>
<if>
<not>
<isset property="nodejs.url" />
</not>
<then>
<fail>
.
Unable to automatically detect the current operating system and architecture.
Please manually set the property "nodejs.url" in build.properties to the
location of NodeJS. An example value for OSX on a 64 bit architecture is
${nodejs.url[osx64]}.
</fail>
</then>
</if>
<if>
<not>
<available file="${sdk.tools.dir}/node-v${nodejs.version}" />
</not>
<then>
<antelope:stringutil property="nodejs.file.beginindex" string="${nodejs.url}">
<antelope:lastindexof string="/" />
</antelope:stringutil>
<math
datatype="int"
operand1="${nodejs.file.beginindex}"
operand2="1"
operation="+"
result="nodejs.file.beginindex"
/>
<antelope:stringutil property="nodejs.file" string="${nodejs.url}">
<antelope:substring beginindex="${nodejs.file.beginindex}" />
</antelope:stringutil>
<if>
<not>
<available file="${sdk.tools.dir}/${nodejs.file}" />
</not>
<then>
<mirrors-get dest="${sdk.tools.dir}/${nodejs.file}" src="${nodejs.url}" />
</then>
</if>
<if>
<contains string="${nodejs.file}" substring=".tar.gz" />
<then>
<exec executable="tar">
<arg line="xfz ${sdk.tools.dir}/${nodejs.file} -C ${sdk.tools.dir}" />
</exec>
<antelope:stringutil property="nodejs.dir.endindex" string="${nodejs.file}">
<antelope:lastindexof string=".tar.gz" />
</antelope:stringutil>
</then>
<else>
<unzip dest="${sdk.tools.dir}" src="${sdk.tools.dir}/${nodejs.file}" />
<antelope:stringutil property="nodejs.dir.endindex" string="${nodejs.file}">
<antelope:lastindexof string=".zip" />
</antelope:stringutil>
</else>
</if>
<antelope:stringutil property="nodejs.dir" string="${nodejs.file}">
<antelope:substring endindex="${nodejs.dir.endindex}" />
</antelope:stringutil>
<delete dir="${sdk.tools.dir}/node-v${nodejs.version}" />
<move file="${sdk.tools.dir}/${nodejs.dir}" tofile="${sdk.tools.dir}/node-v${nodejs.version}" />
<mkdir dir="${sdk.tools.dir}/node-v${nodejs.version}/node_modules" />
<node-execute
node.args="config set cache ${sdk.tools.dir}/node-v${nodejs.version}/.cache --global"
node.command="npm"
node.working.dir="${sdk.tools.dir}/node-v${nodejs.version}"
/>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="download-node-module">
<attribute name="node.module.name" />
<attribute name="node.module.version" />
<sequential>
<check-system-node />
<if>
<isset property="nodejs.system.version" />
<then>
<var name="node.target.version" value="${nodejs.system.version}" />
</then>
<else>
<var name="node.target.version" value="v${nodejs.version}" />
</else>
</if>
<loadfile failonerror="false" property="package.json.content" srcFile="${sdk.tools.dir}/node-${node.target.version}/node_modules/@{node.module.name}/package.json" />
<if>
<not>
<contains string="${package.json.content}" substring=""version": "@{node.module.version}"" />
</not>
<then>
<node-execute
node.args="install @{node.module.name}@"@{node.module.version}""
node.command="npm"
node.working.dir="${sdk.tools.dir}/node-${node.target.version}"
/>
</then>
</if>
<var name="package.json.content" unset="true" />
</sequential>
</macrodef>
<macrodef name="node-execute">
<attribute default="" name="node.args" />
<attribute name="node.command" />
<attribute default="" name="node.command.args" />
<attribute default="${user.dir}" name="node.working.dir" />
<sequential>
<check-system-node />
<if>
<isset property="nodejs.system.version" />
<then>
<var name="node.executable" value="" />
<var name="node.path" value="${env.PATH}" />
</then>
<else>
<download-node />
<if>
<available file="${sdk.tools.dir}/node-v${nodejs.version}/bin" type="dir" />
<then>
<var name="node.executable" value="${sdk.tools.dir}/node-v${nodejs.version}/bin/" />
<var name="node.path" value="${env.PATH};${sdk.tools.dir}/node-v${nodejs.version}/bin" />
</then>
<else>
<var name="node.executable" value="${sdk.tools.dir}/node-v${nodejs.version}/" />
<var name="node.path" value="${env.PATH};${sdk.tools.dir}/node-v${nodejs.version}" />
</else>
</if>
</else>
</if>
<if>
<not>
<equals arg1="@{node.command.args}" arg2="" />
</not>
<then>
<echo>@{node.command.args}</echo>
</then>
</if>
<if>
<os family="unix" />
<then>
<var name="node.executable" value="${node.executable}@{node.command}" />
</then>
<else>
<var name="node.command.extension" value="cmd" />
<if>
<equals arg1="@{node.command}" arg2="node" />
<then>
<var name="node.command.extension" value="exe" />
</then>
</if>
<var name="node.executable" value="${node.executable}@{node.command}.${node.command.extension}" />
</else>
</if>
<exec dir="@{node.working.dir}" executable="${node.executable}">
<env key="PATH" path="${node.path}" />
<arg line="@{node.command.args} @{node.args}" />
</exec>
</sequential>
</macrodef>
<macrodef name="transpile-js">
<attribute name="module.dir" />
<sequential>
<mkdir dir="@{module.dir}/.js-cache" />
<mkdir dir="@{module.dir}/tmp/transpile" />
<copy todir="@{module.dir}/tmp/transpile">
<fileset dir="@{module.dir}/src" id="transpile.fileset">
<include name="**/${transpile.file.pattern}" />
</fileset>
</copy>
<download-node-module
node.module.name="babel"
node.module.version="${nodejs.modules.version[babel]}"
/>
<download-node-module
node.module.name="lfr-amd-loader"
node.module.version="${nodejs.modules.version[lfr-amd-loader]}"
/>
<pathconvert pathsep=" " property="transpile.files" refid="transpile.fileset" setonempty="false" >
<map from="@{module.dir}/src/" to="" />
</pathconvert>
<node-execute
node.command="node"
node.command.args="${sdk.tools.dir}/node-v${nodejs.version}/node_modules/babel/bin/babel/index.js --modules amd -d @{module.dir}/.js-cache ${transpile.files}"
node.working.dir="@{module.dir}/tmp/transpile"
/>
<var name="transpile.files" unset="true" />
</sequential>
</macrodef>
</project>