forked from liferay/liferay-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-common-node.xml
286 lines (247 loc) · 8 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
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="build-common-node" xmlns:antelope="antlib:ise.antelope.tasks">
<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 string="${nodejs.url}" property="nodejs.file.beginindex">
<antelope:lastindexof string="/" />
</antelope:stringutil>
<math
datatype="int"
operand1="${nodejs.file.beginindex}"
operand2="1"
operation="+"
result="nodejs.file.beginindex"
/>
<antelope:stringutil string="${nodejs.url}" property="nodejs.file">
<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 string="${nodejs.file}" property="nodejs.dir.endindex">
<antelope:lastindexof string=".tar.gz" />
</antelope:stringutil>
<antelope:stringutil string="${nodejs.file}" property="nodejs.dir">
<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" />
</then>
<else>
<move file="${sdk.tools.dir}/${nodejs.file}" todir="${sdk.tools.dir}/node-v${nodejs.version}" />
</else>
</if>
<if>
<os family="windows" />
<then>
<if>
<not>
<available file="${sdk.tools.dir}/npm-${nodejs.npm.version}.zip" />
</not>
<then>
<mirrors-get dest="${sdk.tools.dir}/npm-${nodejs.npm.version}.zip" src="${nodejs.npm.url}" />
</then>
</if>
<unzip
dest="${sdk.tools.dir}/node-v${nodejs.version}"
src="${sdk.tools.dir}/npm-${nodejs.npm.version}.zip"
/>
</then>
</if>
<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>
<loadfile failonerror="false" property="package.json.content" srcFile="${sdk.tools.dir}/node-v${nodejs.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-v${nodejs.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>
<download-node />
<if>
<not>
<equals arg1="@{node.command.args}" arg2="" />
</not>
<then>
<echo>@{node.command.args}</echo>
</then>
</if>
<if>
<os family="unix" />
<then>
<exec dir="@{node.working.dir}" executable="${sdk.tools.dir}/node-v${nodejs.version}/bin/@{node.command}">
<arg line="@{node.command.args} @{node.args}" />
</exec>
</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>
<exec dir="@{node.working.dir}" executable="${sdk.tools.dir}/node-v${nodejs.version}/@{node.command}.${node.command.extension}">
<arg line="@{node.command.args} @{node.args}" />
</exec>
</else>
</if>
</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" setonempty="false" refid="transpile.fileset" >
<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>