forked from Kotlin/kotlinx.html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpm_publish.xml
147 lines (116 loc) · 5.67 KB
/
npm_publish.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
<project name="Node.js utils" xmlns:if="ant:if" xmlns:unless="ant:unless">
<!-- Expected that these properties will be overridden by system properties -->
<property name="kotlin.deploy.version" value="0.0.0"/>
<property name="kotlin.deploy.tag" value="dev"/>
<property name="kotlin.npmjs.auth.token" value="AUTH"/>
<!-- Based on https://github.com/JetBrains/kotlin/blob/master/common.xml -->
<condition property="isWindows">
<os family="windows"/>
</condition>
<condition property="isMac">
<os family="mac"/>
</condition>
<condition property="isLinux">
<and>
<os family="unix"/>
<not>
<os family="mac"/>
</not>
</and>
</condition>
<property name="output" value="${basedir}/js/target/"/>
<property name="dependencies" value="${output}/dependencies"/>
<target name="make-dependency-dirs">
<mkdir dir="${dependencies}"/>
<mkdir dir="${dependencies}/download"/>
</target>
<!-- Based on https://github.com/JetBrains/kotlin/blob/master/node_utils.xml -->
<property name="node.version" value="v6.3.1"/>
<property name="node.dir" value="${dependencies}/node"/>
<property name="node.executable" value="${node.dir}/bin/node"/>
<target name="download-nodejs-and-npm" depends="make-dependency-dirs">
<property name="linux-x86" value="linux-x86"/>
<property name="platform" value="win-x86" if:set="isWindows"/>
<property name="platform" value="darwin-x64" if:set="isMac"/>
<property name="platform" value="${linux-x86}" if:set="isLinux"/>
<property name="node.tar.gz" value="${dependencies}/download/node.tar.gz"/>
<property name="node.exe" value="${node.executable}.exe"/>
<property name="node.name.prefix" value="${platform}" unless:set="isWindows"/>
<property name="node.name.prefix" value="${linux-x86}" if:set="isWindows"/>
<property name="node.full.name" value="node-${node.version}-${node.name.prefix}"/>
<property name="url.node.tar.gz" value="https://nodejs.org/dist/${node.version}/${node.full.name}.tar.gz"/>
<property name="url.node.exe" value="https://nodejs.org/dist/${node.version}/${platform}/node.exe"/>
<get src="${url.node.tar.gz}" dest="${node.tar.gz}" usetimestamp="true"/>
<exec executable="tar" unless:set="isWindows">
<arg value="-zxf"/>
<arg path="${node.tar.gz}"/>
<arg value="-C"/>
<arg path="${dependencies}"/>
</exec>
<untar src="${node.tar.gz}" dest="${dependencies}" compression="gzip" if:set="isWindows"/>
<move file="${dependencies}/${node.full.name}" tofile="${dependencies}/node"/>
<delete dir="${dependencies}/${node.full.name}"/>
<delete file="${node.tar.gz}"/>
<sequential if:set="isWindows">
<get src="${url.node.exe}" dest="${node.exe}" usetimestamp="true"/>
<delete file="${node.executable}"/>
</sequential>
</target>
<macrodef name="node">
<attribute name="dir" default="."/>
<attribute name="failonerror" default="true"/>
<element name="args" implicit="true"/>
<sequential>
<exec executable="${node.executable}" dir="@{dir}" failonerror="@{failonerror}">
<args/>
</exec>
</sequential>
</macrodef>
<macrodef name="npm">
<attribute name="command"/>
<attribute name="dir" default="."/>
<attribute name="failonerror" default="true"/>
<element name="args" optional="true" implicit="true"/>
<sequential>
<node dir="@{dir}" failonerror="@{failonerror}">
<arg file="${node.dir}/lib/node_modules/npm/bin/npm-cli.js"/>
<arg value="@{command}"/>
<args/>
</node>
</sequential>
</macrodef>
<macrodef name="publish-to-npm">
<attribute name="template"/>
<attribute name="version"/>
<attribute name="tag"/>
<element name="actions" optional="true" implicit="true"/>
<sequential>
<property name="deploy_to_npm_dir" value="${output}/deploy_to_npm"/>
<property name="package_deploy_dir" value="${deploy_to_npm_dir}/@{template}"/>
<delete dir="${deploy_to_npm_dir}"/>
<mkdir dir="${deploy_to_npm_dir}"/>
<copy todir="${package_deploy_dir}">
<fileset dir="js/npm.templates/@{template}"/>
</copy>
<actions/>
<npm command="version" dir="${package_deploy_dir}">
<arg value="@{version}"/>
</npm>
<npm command="publish" dir="${package_deploy_dir}">
<arg value="--//registry.npmjs.org/:_authToken=${kotlin.npmjs.auth.token}"/>
<arg value="--tag"/>
<arg value="@{tag}"/>
</npm>
</sequential>
</macrodef>
<target name="publish-kotlinx-html-to-npm" depends="download-nodejs-and-npm">
<publish-to-npm template="kotlinx-html" version="${kotlin.deploy.version}" tag="${kotlin.deploy.tag}">
<copy file="${output}/classes/kotlinx-html-js.js" todir="${package_deploy_dir}" failonerror="true" />
<copy file="${output}/classes/kotlinx-html-js.js.map" todir="${package_deploy_dir}" failonerror="true" />
<copy file="${output}/classes/kotlinx-html-js.meta.js" todir="${package_deploy_dir}" failonerror="true" />
<copy todir="${package_deploy_dir}/kotlinx-html-js" failonerror="true">
<fileset dir="${output}/classes/kotlinx-html-js"/>
</copy>
</publish-to-npm>
</target>
</project>