forked from liferay/liferay-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-common-node.xml
233 lines (200 loc) · 6.33 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
<?xml version="1.0"?>
<!DOCTYPE project>
<project name="build-common-node" xmlns:antelope="antlib:ise.antelope.tasks">
<macrodef name="download-node">
<sequential>
<if>
<os arch="x86_32" family="mac" />
<then>
<propertycopy from="nodejs.url[osx32]" name="nodejs.url" />
</then>
<elseif>
<os arch="x86_64" family="mac" />
<then>
<propertycopy from="nodejs.url[osx64]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<os arch="amd" family="unix" />
<then>
<propertycopy from="nodejs.url[linux32]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<os arch="amd64" family="unix" />
<then>
<propertycopy from="nodejs.url[linux64]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<os arch="x86" family="windows" />
<then>
<propertycopy from="nodejs.url[windows32]" name="nodejs.url" />
</then>
</elseif>
<elseif>
<os arch="amd64" family="windows" />
<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>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="download-node-module">
<attribute name="node.module.name" />
<sequential>
<if>
<not>
<available file="${sdk.tools.dir}/node-v${nodejs.version}/node_modules/@{node.module.name}" />
</not>
<then>
<node-execute
node.args="install @{node.module.name}"
node.command="npm"
node.working.dir="${sdk.tools.dir}/node-v${nodejs.version}"
/>
</then>
</if>
</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>
<exec dir="@{node.working.dir}" executable="${sdk.tools.dir}/node-v${nodejs.version}/bin/@{node.command}">
<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" />
<copy
file="@{module.dir}/bower.json"
overwrite="true"
tofile="@{module.dir}/.js-cache/bower.json"
/>
<mkdir dir="@{module.dir}/tmp/transpile" />
<copy todir="@{module.dir}/tmp/transpile">
<fileset dir="@{module.dir}/src" id="transpile.fileset">
<include name="**/*.es.js" />
</fileset>
</copy>
<download-node-module
node.module.name="babel"
/>
<download-node-module
node.module.name="lfr-amd-loader"
/>
<download-node-module
node.module.name="lfr-module-config-generator"
/>
<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" />
<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 -l -m @{module.dir}/.js-cache/bower.json -o @{module.dir}/classes/META-INF/config.json -p **/*.es.js -r @{module.dir}/.js-cache/META-INF/resources @{module.dir}/.js-cache"
node.working.dir="${sdk.tools.dir}/node-v${nodejs.version}"
/>
</sequential>
</macrodef>
</project>