##// END OF EJS Templates
build.gradle cleanup and refactoring
cin -
r97:8c240739e273 ts-plugin
parent child
Show More
@@ -0,0 +1,32
1 package org.implab.gradle.hg;
2
3 import org.gradle.api.Plugin;
4 import org.gradle.api.Project;
5
6 public class MercurialPlugin implements Plugin<Project> {
7 public void apply(Project project) {
8 if (!project.version) {
9
10 def rev = ["hg", "log", "-r", ".", "--template", "{latesttag('re:^v') % '{tag}-{distance}'}"].execute().text.trim();
11
12 def tagVersion;
13 def tagDistance;
14
15 def match = (rev =~ /^v(\d+\.\d+\.\d+).*-(\d+)$/);
16
17 if (match.size()) {
18 tagVersion = match[0][1];
19 tagDistance = match[0][2].toInteger();
20 } else {
21 throw new Exception("A version must be specied");
22 }
23
24 project.version = tagVersion;
25
26 if (tagDistance > 0)
27 project.version++;
28 } else {
29 println "explicit version: $project.version";
30 }
31 }
32 } No newline at end of file
@@ -0,0 +1,1
1 implementation-class=org.implab.gradle.hg.MercurialPlugin No newline at end of file
@@ -1,5 +1,6
1 syntax: glob
1 syntax: glob
2 .gradle/
2 .gradle/
3 build/
3 build/
4 node_modules/
4 node_modules/
5 src/typings/
5 src/typings/
6 ivy-repo/
@@ -1,323 +1,236
1 plugins {
1 plugins {
2 id "org.implab.gradle-typescript" version "1.0.1-rc3"
2 id "org.implab.gradle-typescript" version "1.0.1-rc3"
3 id "org.implab.gradle-hg"
3 id "ivy-publish"
4 id "ivy-publish"
4 }
5 }
5
6
6 // Ссли вСрсия явно Π½Π΅ Π·Π°Π΄Π°Π½Ρ‹ вычисляСм Π΅Π΅ ΠΈΠ· тэга Ρ€Π΅Π²ΠΈΠ·ΠΈΠΈ v.{num}***
7 // Ссли вСрсия явно Π½Π΅ Π·Π°Π΄Π°Π½Ρ‹ вычисляСм Π΅Π΅ ΠΈΠ· тэга Ρ€Π΅Π²ΠΈΠ·ΠΈΠΈ v.{num}***
7 // Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ΠΎΠΌ Π±ΡƒΠ΄Π΅Ρ‚ вСрсия '{num}.{distance}' Π³Π΄Π΅ distance - расстояниС ΠΎΡ‚
8 // Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ΠΎΠΌ Π±ΡƒΠ΄Π΅Ρ‚ вСрсия '{num}.{distance}' Π³Π΄Π΅ distance - расстояниС ΠΎΡ‚
8 // Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Ρ€Π΅Π²ΠΈΠ·ΠΈΠΈ Π΄ΠΎ Ρ€Π΅Π²ΠΈΠ·ΠΈΠΈ с тэгом
9 // Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Ρ€Π΅Π²ΠΈΠ·ΠΈΠΈ Π΄ΠΎ Ρ€Π΅Π²ΠΈΠ·ΠΈΠΈ с тэгом
9 def tagDistance = 0;
10 def tagDistance = 0;
10
11
11 ext {
12 ext {
12 packageName = "@$npmScope/$name"
13 packageName = "@$npmScope/$name"
13 lint = project.hasProperty('lint') ? lint : false
14 lint = project.hasProperty('lint') ? lint : false
14 }
15 }
15
16
16 if (!version) {
17
18 def rev = ["hg", "log", "-r", ".", "--template", "{latesttag('re:^v') % '{tag}-{distance}'}"].execute().text.trim();
19
20 def tagVersion;
21
22 def match = (rev =~ /^v(\d+\.\d+\.\d+).*-(\d+)$/);
23
24 if (match.size()) {
25 tagVersion = match[0][1];
26 tagDistance = match[0][2].toInteger();
27 } else {
28 throw new Exception("A version must be specied");
29 }
30
31 version = tagVersion;
32
33 if (tagDistance > 0)
34 version++;
35 } else {
36 println "explicit version: $version";
37 }
38
39 if (hasProperty('versionSuffix') && versionSuffix) {
40 version += "-$versionSuffix"
41 }
42
43 configurations {
17 configurations {
44
18
45 }
19 }
46
20
47 sources {
21 sources {
48 amd {
22 amd {
49 typings {
23 typings {
50 srcDir main.output.typingsDir
24 srcDir main.output.typingsDir
51 }
25 }
52 }
26 }
53
27
54 cjs {
28 cjs {
55 typings {
29 typings {
56 srcDir main.output.typingsDir
30 srcDir main.output.typingsDir
57 }
31 }
58 }
32 }
59
33
60 testAmd {
34 testAmd {
61 typings {
35 typings {
62 srcDir main.output.typingsDir
36 srcDir main.output.typingsDir
63 srcDir amd.output.typingsDir
37 srcDir amd.output.typingsDir
64 srcDir test.output.typingsDir
38 srcDir test.output.typingsDir
65 }
39 }
66 }
40 }
67
41
68 testCjs {
42 testCjs {
69 typings {
43 typings {
70 srcDir main.output.typingsDir
44 srcDir main.output.typingsDir
71 srcDir cjs.output.typingsDir
45 srcDir cjs.output.typingsDir
72 srcDir test.output.typingsDir
46 srcDir test.output.typingsDir
73 }
47 }
74 }
48 }
75 }
49 }
76
50
77 typescript {
51 typescript {
78 compilerOptions {
52 compilerOptions {
79 types = []
53 types = []
80 declaration = true
54 declaration = true
81 sourceMap = true
55 sourceMap = true
82 sourceRoot = "."
56 sourceRoot = "."
83 }
57 }
84 tscCmd = "$projectDir/node_modules/.bin/tsc"
58 tscCmd = "$projectDir/node_modules/.bin/tsc"
85 tsLintCmd = "$projectDir/node_modules/.bin/tslint"
59 tsLintCmd = "$projectDir/node_modules/.bin/tslint"
86 esLintCmd = "$projectDir/node_modules/.bin/eslint"
60 esLintCmd = "$projectDir/node_modules/.bin/eslint"
87 npmCmd = "npm"
61 npmCmd = "npm"
88 }
62 }
89
63
90 tasks.matching{ it.name =~ /^configureTs/ }.configureEach {
64 tasks.matching{ it.name =~ /^configureTs/ }.configureEach {
91 dependsOn "prepare"
65 dependsOn "prepare"
92 }
66 }
93
67
94 tasks.matching{ it.name =~ /^lint/ }.configureEach {
68 tasks.matching{ it.name =~ /^lint/ }.configureEach {
95 onlyIf { lint }
69 onlyIf { lint }
96 }
70 }
97
71
98 task prepare {
72 task prepare {
99
73
100 }
74 }
101
75
102 task printVersion {
76 task printVersion {
103 dependsOn prepare
77 dependsOn prepare
104
78
105 doLast {
79 doLast {
106 println "version: ${-> version}";
80 println "version: ${-> version}";
107 println "tagDistance: ${-> tagDistance}";
108 println "packageName: ${-> packageName}";
81 println "packageName: ${-> packageName}";
109 println "target: ${-> typescript.compilerOptions.target}";
82 println "target: ${-> typescript.compilerOptions.target}";
110 println "module: ${-> typescript.compilerOptions.module}";
83 println "module: ${-> typescript.compilerOptions.module}";
111 }
84 }
112 }
85 }
113
86
114 task clean {
87 task clean {
115 prepare.mustRunAfter it
88 prepare.mustRunAfter it
116
89
117 doLast {
90 doLast {
118 delete buildDir
91 delete buildDir
119 }
92 }
120 }
93 }
121
94
122 npmPackMeta {
95 npmPackMeta {
123 meta {
96 meta {
124 name = packageName
97 name = packageName
125 }
98 }
126 }
99 }
127
100
128 configureTsCjs {
101 configureTsCjs {
129 dependsOn sources.main.output
102 dependsOn sources.main.output
130 compilerOptions {
103 compilerOptions {
131 types += [ "node" ]
104 types += [ "node" ]
132 }
105 }
133 }
106 }
134
107
135 configureTsAmd {
108 configureTsAmd {
136 dependsOn sources.main.output
109 dependsOn sources.main.output
137 compilerOptions {
110 compilerOptions {
138 types += [ "requirejs", "dojo-typings" ]
111 types += [ "requirejs", "dojo-typings" ]
139 }
112 }
140 }
113 }
141
114
142 test {
115 test {
143 workingDir layout.buildDirectory.dir("test");
116 workingDir layout.buildDirectory.dir("test");
144 commandLine "node", "tests/index.js"
117 commandLine "node", "tests/index.js"
145 }
118 }
146
119
147 task assembleAmd {
148 dependsOn sources.amd.output
149 assemble.mustRunAfter it
150
151 doLast {
152 assemble {
120 assemble {
153 from(sources.amd.output.compiledDir)
121 from sources.amd.output.compiledDir
154 }
122 from sources.cjs.output.compiledDir
155 }
156 }
157
158 task assembleCjs {
159 dependsOn sources.cjs.output
160 assemble.mustRunAfter it
161
162 doLast {
163 assemble {
164 from(sources.cjs.output.compiledDir)
165 }
166 }
167 }
123 }
168
124
169 task assembleTestAmd {
170 dependsOn sources.amd.output
171 dependsOn sources.testAmd.output
172 assembleTest.mustRunAfter it
173
174 doLast {
175 assembleTest {
125 assembleTest {
176 from(sources.amd.output.compiledDir)
126 from sources.amd.output.compiledDir
177 from(sources.testAmd.output.compiledDir)
127 from sources.cjs.output.compiledDir
178 }
128 from sources.testAmd.output.compiledDir
179 }
129 from sources.testCjs.output.compiledDir
180 }
130 }
181
131
182 task assembleTestCjs {
132 task prepareNode {
183 dependsOn sources.cjs.output
184 dependsOn sources.testCjs.output
185 assembleTest.mustRunAfter it
186
187 doLast {
188 assembleTest {
189 from(sources.cjs.output.compiledDir)
190 from(sources.testCjs.output.compiledDir)
191 }
192 }
193 }
194
195 task prepareTargetEs5 {
196 prepare.mustRunAfter it
133 prepare.mustRunAfter it
197
134
198 doLast {
135 doLast {
199 typescript {
136 typescript {
200 compilerOptions {
137 compilerOptions {
201 target = "es5"
138 module = "commonjs"
202 lib = ["es5", "dom", "scripthost", "es2015.promise", "es2015.symbol", "es2015.iterable"]
203 }
204 }
205 }
206 }
207
208 task prepareTargetEsNext {
209 prepare.mustRunAfter it
210
211 doLast {
212 typescript {
213 compilerOptions {
214 target = "es2017"
139 target = "es2017"
215 lib = ["es2017", "dom", "scripthost"]
140 lib = ["es2017", "dom", "scripthost"]
216 }
141 }
217 }
142 }
218 }
143 }
219 }
144 }
220
145
221 task prepareNode {
222 dependsOn prepareTargetEsNext
223 prepare.mustRunAfter it
224
225 doLast {
226 typescript {
227 compilerOptions {
228 module = "commonjs"
229 }
230 }
231 }
232 }
233
234 task prepareBrowser {
146 task prepareBrowser {
235 dependsOn prepareTargetEs5
236 prepare.mustRunAfter it
147 prepare.mustRunAfter it
237
148
238 doLast {
149 doLast {
239 packageName = "@$npmScope/$project.name-amd"
150 packageName = "@$npmScope/$project.name-amd"
240
151
241 typescript {
152 typescript {
242 compilerOptions {
153 compilerOptions {
243 module = "amd"
154 module = "amd"
155 target = "es5"
156 lib = ["es5", "dom", "scripthost", "es2015.promise", "es2015.symbol", "es2015.iterable"]
244 }
157 }
245 }
158 }
246 }
159 }
247 }
160 }
248
161
249 task npmPackTypingsAmd(type: Copy) {
162 task npmPackTypingsAmd(type: Copy) {
250 dependsOn sources.main.output
163 dependsOn sources.main.output
251 dependsOn sources.amd.output
164 dependsOn sources.amd.output
252 npmPack.mustRunAfter it
165 npmPack.mustRunAfter it
253
166
254 from sources.main.output.typingsDir
167 from sources.main.output.typingsDir
255 from sources.amd.output.typingsDir
168 from sources.amd.output.typingsDir
256
169
257 into "${->buildDir}/npm/pack"
170 into "${->buildDir}/npm/pack"
258 }
171 }
259
172
260 task npmPackSourcesAmd(type: Copy) {
173 task npmPackSourcesAmd(type: Copy) {
261 from sources.main.ts
174 from sources.main.ts
262 from sources.amd.ts
175 from sources.amd.ts
263
176
264 npmPack.mustRunAfter it
177 npmPack.mustRunAfter it
265
178
266 into "${->buildDir}/npm/pack"
179 into "${->buildDir}/npm/pack"
267 }
180 }
268
181
269 task assembleBrowser {
182 task assembleBrowser {
270 dependsOn prepareBrowser, assembleAmd, assemble
183 dependsOn prepareBrowser, assemble, sources.amd.output
271 }
184 }
272
185
273 task assembleNode {
186 task assembleNode {
274 dependsOn prepareNode, assembleCjs, assemble
187 dependsOn prepareNode, assemble, sources.cjs.output
275 }
188 }
276
189
277 task testBrowser {
190 task testBrowser {
278 dependsOn prepareBrowser, assembleTestAmd, test
191 dependsOn prepareBrowser, test, sources.amd.output, sources.testAmd.output
279 }
192 }
280
193
281 task testNode {
194 task testNode {
282 dependsOn prepareNode, assembleTestCjs, test
195 dependsOn prepareNode, test, sources.cjs.output, sources.testCjs.output
283 }
196 }
284
197
285 task npmPackBrowser {
198 task npmPackBrowser {
286 dependsOn assembleBrowser, npmPack, npmPackSourcesAmd, npmPackTypingsAmd
199 dependsOn assembleBrowser, npmPack, npmPackSourcesAmd, npmPackTypingsAmd
287 }
200 }
288
201
289
202
290 task packJsTar(type: Tar) {
203 task packJsTar(type: Tar) {
291 dependsOn assemble;
204 dependsOn assemble;
292
205
293 archiveBaseName = provider { packageName }
206 archiveBaseName = provider { packageName }
294
207
295 destinationDirectory = buildDir
208 destinationDirectory = buildDir
296 archiveClassifier = provider { typescript.compilerOptions.module }
209 archiveClassifier = provider { typescript.compilerOptions.module }
297 compression = Compression.GZIP
210 compression = Compression.GZIP
298
211
299 from(assemble.outputs)
212 from(assemble.outputs)
300
213
301 doLast {
214 doLast {
302 println archiveName;
215 println archiveName;
303 }
216 }
304 }
217 }
305
218
306 task packTypingsTar(type: Tar) {
219 task packTypingsTar(type: Tar) {
307 }
220 }
308
221
309 publishing {
222 publishing {
310 publications {
223 publications {
311 local(IvyPublication) {
224 local(IvyPublication) {
312 artifact(packJsTar) {
225 artifact(packJsTar) {
313 type = "js"
226 type = "js"
314 }
227 }
315 }
228 }
316 }
229 }
317
230
318 repositories {
231 repositories {
319 ivy {
232 ivy {
320 url "ivy-repo"
233 url "ivy-repo"
321 }
234 }
322 }
235 }
323 } No newline at end of file
236 }
General Comments 0
You need to be logged in to leave comments. Login now