| @@ -1,276 +1,281 | |||
|
|
1 | 1 | // если версия явно не заданы вычисляем ее из тэга ревизии v.{num}*** |
|
|
2 | 2 | // результатом будет версия '{num}.{distance}' где distance - расстояние от |
|
|
3 | 3 | // текущей ревизии до ревизии с тэгом |
|
|
4 | 4 | def tagDistance = 0; |
|
|
5 | 5 | def isRelease = false; |
|
|
6 | 6 | |
|
|
7 | 7 | if (!version) { |
|
|
8 | 8 | |
|
|
9 | 9 | def rev = ["hg", "log", "-r", ".", "--template", "{latesttag('re:^v') % '{tag}-{distance}'}"].execute().text.trim(); |
|
|
10 | 10 | |
|
|
11 | 11 | def tagVersion; |
|
|
12 | 12 | |
|
|
13 | 13 | def match = (rev =~ /^v(\d+\.\d+\.\d+).*-(\d+)$/); |
|
|
14 | 14 | |
|
|
15 | 15 | if (match.size()) { |
|
|
16 | 16 | tagVersion = match[0][1]; |
|
|
17 | 17 | tagDistance = match[0][2].toInteger(); |
|
|
18 | 18 | |
|
|
19 | 19 | version = tagVersion; |
|
|
20 | 20 | |
|
|
21 | 21 | if (tagDistance > 0) |
|
|
22 | 22 | version++; |
|
|
23 | 23 | } else { |
|
|
24 | 24 | throw new Exception("A version must be specied"); |
|
|
25 | 25 | } |
|
|
26 | 26 | } else { |
|
|
27 | 27 | println "explicit version: $version"; |
|
|
28 | 28 | } |
|
|
29 | 29 | |
|
|
30 | 30 | if (hasProperty('versionSuffix') && versionSuffix) { |
|
|
31 | 31 | version += "-$versionSuffix" |
|
|
32 | 32 | } |
|
|
33 | 33 | |
|
|
34 | 34 | if(!npmName) |
|
|
35 | 35 | npmName = name; |
|
|
36 | 36 | |
|
|
37 | 37 | if (hasProperty('release')) { |
|
|
38 | 38 | isRelease = (release != 'false') |
|
|
39 | 39 | } else { |
|
|
40 | 40 | isRelease = (tagDistance == 0); |
|
|
41 | 41 | } |
|
|
42 | 42 | |
|
|
43 | 43 | if(!["amd", "commonjs", "system", "umd", "es6", "esnext"].contains(jsmodule)) |
|
|
44 | 44 | throw new Exception("Invalid jsmodule specified: $jsmodule"); |
|
|
45 | 45 | if(!["es3", "es5", "es6", "es2016", "es2017", "esnext"].contains(target)) |
|
|
46 | 46 | throw new Exception("Invalid target specified: $target") |
|
|
47 | 47 | |
|
|
48 | 48 | def targetLibs = [ |
|
|
49 | 49 | "es3" : "es5,es2015.promise,es2015.symbol,dom,scripthost", |
|
|
50 | 50 | "es5" : "es5,es2015.promise,es2015.symbol,dom,scripthost" |
|
|
51 | 51 | ]; |
|
|
52 | 52 | |
|
|
53 | 53 | ext.packageName="@$npmScope/$npmName"; |
|
|
54 | 54 | |
|
|
55 | 55 | def srcDir = "$projectDir/src" |
|
|
56 | 56 | def typingsDir = "$srcDir/typings" |
|
|
57 | 57 | def distDir = "$buildDir/dist" |
|
|
58 | 58 | def testDir = "$buildDir/test" |
|
|
59 | 59 | def lib = targetLibs[target] ?: "${target},dom"; |
|
|
60 | 60 | |
|
|
61 | 61 | println "lib: $lib"; |
|
|
62 | 62 | |
|
|
63 | 63 | def sourceSets = ["main", "amd", "cjs"]; |
|
|
64 | 64 | def testSets = ["test", "testAmd", "testCjs"]; |
|
|
65 | 65 | |
|
|
66 | 66 | task beforeBuild { |
|
|
67 | 67 | } |
|
|
68 | 68 | |
|
|
69 | 69 | def createSoursetTasks = { String name, String outDir -> |
|
|
70 | 70 | def setName = name.capitalize(); |
|
|
71 | 71 | |
|
|
72 | 72 | def compileDir = "$buildDir/compile/$name" |
|
|
73 | 73 | def declDir = "$typingsDir/$name" |
|
|
74 | 74 | def setDir = "$projectDir/src/$name" |
|
|
75 | 75 | def jsDir = outDir; |
|
|
76 | 76 | |
|
|
77 | 77 | def beforeBuildTask = task "beforeBuild$setName"(dependsOn: beforeBuild) { |
|
|
78 | 78 | } |
|
|
79 | 79 | |
|
|
80 | 80 | def copyJsTask = task "copyJs$setName"(dependsOn: beforeBuildTask, type: Copy) { |
|
|
81 | 81 | from "$setDir/js" |
|
|
82 | 82 | into jsDir |
|
|
83 | 83 | } |
|
|
84 | 84 | |
|
|
85 | 85 | def lintJsTask = task "lintJs$setName"(dependsOn: beforeBuildTask, type: Exec) { |
|
|
86 | 86 | inputs.dir("$setDir/js/").skipWhenEmpty(); |
|
|
87 | 87 | commandLine "eslint", '--format', 'stylish', "$setDir/js/" |
|
|
88 | 88 | } |
|
|
89 | 89 | |
|
|
90 | 90 | def compileTsTask = task "compileTs$setName"(dependsOn: beforeBuildTask, type: Exec) { |
|
|
91 | 91 | inputs.dir("$setDir/ts").skipWhenEmpty() |
|
|
92 | 92 | inputs.file("$srcDir/tsconfig.json") |
|
|
93 | 93 | inputs.file("$setDir/tsconfig.json") |
|
|
94 | 94 | outputs.dir(compileDir) |
|
|
95 | 95 | outputs.dir(declDir) |
|
|
96 | 96 | |
|
|
97 | 97 | commandLine 'node_modules/.bin/tsc', |
|
|
98 | 98 | '-p', "$setDir/tsconfig.json", |
|
|
99 | 99 | '-t', target, |
|
|
100 | 100 | '-m', jsmodule, |
|
|
101 | 101 | '-d', |
|
|
102 | 102 | '--outDir', compileDir, |
|
|
103 | 103 | '--declarationDir', declDir |
|
|
104 | 104 | |
|
|
105 | 105 | if (lib) |
|
|
106 | 106 | args '--lib', lib |
|
|
107 | 107 | } |
|
|
108 | 108 | |
|
|
109 | 109 | def copyTsOutputTask = task "copyTsOutput$setName"(dependsOn: compileTsTask, type: Copy) { |
|
|
110 | 110 | from compileDir |
|
|
111 | 111 | into jsDir |
|
|
112 | 112 | } |
|
|
113 | 113 | |
|
|
114 | 114 | def copyTypingsTask = task "copyTypings$setName"(dependsOn: compileTsTask, type: Copy) { |
|
|
115 | 115 | from declDir |
|
|
116 | 116 | into jsDir |
|
|
117 | 117 | } |
|
|
118 | 118 | |
|
|
119 | 119 | def copyResourcesTask = task "copyResources$setName"(dependsOn: beforeBuildTask, type: Copy) { |
|
|
120 | 120 | from "$setDir/resources" |
|
|
121 | 121 | into outDir |
|
|
122 | 122 | } |
|
|
123 | 123 | |
|
|
124 | 124 | task "build$setName" { |
|
|
125 | 125 | dependsOn copyTypingsTask, |
|
|
126 | 126 | copyTsOutputTask, |
|
|
127 | 127 | copyJsTask, |
|
|
128 | 128 | copyResourcesTask, |
|
|
129 | 129 | lintJsTask |
|
|
130 | 130 | } |
|
|
131 | 131 | } |
|
|
132 | 132 | |
|
|
133 | 133 | task printVersion { |
|
|
134 | 134 | doLast { |
|
|
135 | 135 | println "version: $version"; |
|
|
136 | 136 | println "isRelease: $isRelease, tagDistance: $tagDistance"; |
|
|
137 | 137 | println "packageName: $packageName"; |
|
|
138 | 138 | println "bundle: ${pack.outputs.files.join(',')}"; |
|
|
139 | 139 | println "target: $target"; |
|
|
140 | 140 | println "module: $jsmodule"; |
|
|
141 | 141 | } |
|
|
142 | 142 | } |
|
|
143 | 143 | |
|
|
144 | 144 | task clean { |
|
|
145 | 145 | doLast { |
|
|
146 | 146 | delete buildDir |
|
|
147 | 147 | delete typingsDir |
|
|
148 | 148 | } |
|
|
149 | 149 | } |
|
|
150 | 150 | |
|
|
151 | 151 | task _initBuild { |
|
|
152 | 152 | mustRunAfter clean |
|
|
153 | 153 | |
|
|
154 | 154 | def buildInfoFile = "$buildDir/platform"; |
|
|
155 | 155 | inputs.property('target',target); |
|
|
156 | 156 | inputs.property('jsmodule',jsmodule); |
|
|
157 | 157 | outputs.file(buildInfoFile); |
|
|
158 | 158 | |
|
|
159 | 159 | doLast { |
|
|
160 | 160 | delete buildDir |
|
|
161 | 161 | mkdir buildDir |
|
|
162 | 162 | |
|
|
163 | 163 | def f = new File(buildInfoFile); |
|
|
164 | 164 | f << "$target-$jsmodule"; |
|
|
165 | 165 | } |
|
|
166 | 166 | } |
|
|
167 | 167 | |
|
|
168 | 168 | task cleanNpm { |
|
|
169 | 169 | doLast { |
|
|
170 | 170 | delete 'node_modules' |
|
|
171 | 171 | } |
|
|
172 | 172 | } |
|
|
173 | 173 | |
|
|
174 | 174 | task _npmInstall() { |
|
|
175 | 175 | inputs.file("package.json") |
|
|
176 | 176 | outputs.dir("node_modules") |
|
|
177 | 177 | doLast { |
|
|
178 | 178 | exec { |
|
|
179 | 179 | commandLine 'npm', 'install' |
|
|
180 | 180 | } |
|
|
181 | 181 | } |
|
|
182 | 182 | } |
|
|
183 | 183 | |
|
|
184 | 184 | beforeBuild { |
|
|
185 | 185 | dependsOn _initBuild |
|
|
186 | 186 | dependsOn _npmInstall |
|
|
187 | 187 | } |
|
|
188 | 188 | |
|
|
189 | 189 | sourceSets.each { createSoursetTasks(it, distDir) } |
|
|
190 | 190 | |
|
|
191 | 191 | testSets.each { createSoursetTasks(it, testDir) } |
|
|
192 | 192 | |
|
|
193 | 193 | compileTsAmd { |
|
|
194 | 194 | dependsOn compileTsMain |
|
|
195 | 195 | } |
|
|
196 | 196 | |
|
|
197 | 197 | compileTsCjs { |
|
|
198 | 198 | dependsOn compileTsMain |
|
|
199 | 199 | } |
|
|
200 | 200 | |
|
|
201 | 201 | task build(dependsOn: buildMain) { |
|
|
202 | 202 | if (jsmodule == "amd") |
|
|
203 | 203 | dependsOn buildAmd |
|
|
204 | 204 | if (jsmodule == "commonjs") |
|
|
205 | 205 | dependsOn buildCjs |
|
|
206 | 206 | } |
|
|
207 | 207 | |
|
|
208 | 208 | compileTsTest { |
|
|
209 | 209 | dependsOn build |
|
|
210 | 210 | } |
|
|
211 | 211 | |
|
|
212 | 212 | compileTsTestAmd { |
|
|
213 | 213 | dependsOn compileTsTest |
|
|
214 | 214 | } |
|
|
215 | 215 | |
|
|
216 | 216 | compileTsTestCjs { |
|
|
217 | 217 | dependsOn compileTsTest |
|
|
218 | 218 | } |
|
|
219 | 219 | |
|
|
220 | 220 | task _installLocalCjsDependency(dependsOn: [buildTestCjs, "_packageMeta"], type: Exec) { |
|
|
221 | 221 | inputs.file("$distDir/package.json") |
|
|
222 | 222 | outputs.upToDateWhen { |
|
|
223 | 223 | new File("$testDir/$packageName").exists() |
|
|
224 | 224 | } |
|
|
225 | 225 | |
|
|
226 | 226 | workingDir testDir |
|
|
227 | 227 | |
|
|
228 | 228 | commandLine 'npm', 'install', '--no-save', '--force', distDir |
|
|
229 | 229 | } |
|
|
230 | 230 | |
|
|
231 | 231 | task test(dependsOn: [buildTest], type: Exec) { |
|
|
232 | 232 | if (jsmodule == "amd") |
|
|
233 | 233 | dependsOn buildTestAmd |
|
|
234 | 234 | if (jsmodule == "commonjs") { |
|
|
235 | 235 | dependsOn buildTestCjs |
|
|
236 | 236 | dependsOn _installLocalCjsDependency |
|
|
237 | 237 | } |
|
|
238 | 238 | |
|
|
239 | 239 | commandLine 'node', "$testDir/run-tests.js" |
|
|
240 | 240 | } |
|
|
241 | 241 | |
|
|
242 | 242 | task _packageMeta(type: Copy) { |
|
|
243 | 243 | mustRunAfter build |
|
|
244 | 244 | |
|
|
245 | 245 | inputs.property("version", version) |
|
|
246 | 246 | from('.') { |
|
|
247 | 247 | include '.npmignore', 'readme.md', 'license', 'history.md' |
|
|
248 | 248 | } |
|
|
249 | 249 | from("package.${jsmodule}.json") { |
|
|
250 | 250 | expand project.properties |
|
|
251 | 251 | rename { "package.json" } |
|
|
252 | 252 | } |
|
|
253 | 253 | into distDir |
|
|
254 | 254 | } |
|
|
255 | 255 | |
|
|
256 | 256 | task pack(dependsOn: [build, _packageMeta], type: Exec) { |
|
|
257 | def packageFile = "$npmScope-$npmName-${version}.tgz" | |
|
|
257 | 258 | workingDir distDir |
|
|
258 | outputs.file("$npmScope-$npmName-${version}.tgz") | |
|
|
259 | outputs.file("$buildDir/$packageFile") | |
|
|
259 | 260 | |
|
|
260 | 261 | commandLine 'npm', 'pack' |
|
|
262 | doLast { | |
|
|
263 | ant.move file: "$distDir/$packageFile", | |
|
|
264 | todir: buildDir | |
|
|
265 | } | |
|
|
261 | 266 | } |
|
|
262 | 267 | |
|
|
263 | 268 | task publish(dependsOn: [build, _packageMeta], type: Exec) { |
|
|
264 | 269 | doFirst { |
|
|
265 | 270 | if (!isRelease) |
|
|
266 | 271 | throw new Exception("Can't publish an unreleased version"); |
|
|
267 | 272 | } |
|
|
268 | 273 | workingDir distDir |
|
|
269 | 274 | |
|
|
270 | 275 | commandLine 'npm', 'publish', '--access', 'public' |
|
|
271 | 276 | } |
|
|
272 | 277 | |
|
|
273 | 278 | task markRelease(type: Exec) { |
|
|
274 | 279 | onlyIf { tagDistance > 1 } |
|
|
275 | 280 | commandLine "hg", "tag", "v$version"; |
|
|
276 | 281 | } No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now
