| @@ -1,3 +1,7 | |||||
|
|
1 | plugins { | |||
|
|
2 | id "org.implab.gradle-typescript" version "1.0-SNAPSHOT" | |||
|
|
3 | } | |||
|
|
4 | ||||
| 1 | // если версия явно не заданы вычисляем ее из тэга ревизии v.{num}*** |
|
5 | // если версия явно не заданы вычисляем ее из тэга ревизии v.{num}*** | |
| 2 | // результатом будет версия '{num}.{distance}' где distance - расстояние от |
|
6 | // результатом будет версия '{num}.{distance}' где distance - расстояние от | |
| 3 | // текущей ревизии до ревизии с тэгом |
|
7 | // текущей ревизии до ревизии с тэгом | |
| @@ -46,90 +50,34 if(!["es3", "es5", "es6", "es2016", "es2 | |||||
| 46 | throw new Exception("Invalid target specified: $target") |
|
50 | throw new Exception("Invalid target specified: $target") | |
| 47 |
|
51 | |||
| 48 | def targetLibs = [ |
|
52 | def targetLibs = [ | |
| 49 | "es3" : "es5,es2015.promise,es2015.symbol,dom,scripthost", |
|
53 | "es3" : ["es5", "es2015.promise", "es2015.symbol", "dom", "scripthost"], | |
| 50 | "es5" : "es5,es2015.promise,es2015.symbol,dom,scripthost" |
|
54 | "es5" : ["es5", "es2015.promise", "es2015.symbol", "dom", "scripthost"] | |
| 51 | ]; |
|
55 | ]; | |
| 52 |
|
56 | |||
| 53 | ext.packageName="@$npmScope/$npmName"; |
|
57 | ext { | |
|
|
58 | packageName = "@$npmScope/$npmName" | |||
|
|
59 | } | |||
| 54 |
|
60 | |||
| 55 | def srcDir = "$projectDir/src" |
|
61 | def srcDir = "$projectDir/src" | |
| 56 | def typingsDir = "$srcDir/typings" |
|
62 | def typingsDir = "$srcDir/typings" | |
| 57 | def distDir = "$buildDir/dist" |
|
63 | def distDir = "$buildDir/dist" | |
| 58 | def testDir = "$buildDir/test" |
|
64 | def testDir = "$buildDir/test" | |
| 59 | def lib = targetLibs[target] ?: "${target},dom"; |
|
65 | def jstarget = target; | |
| 60 |
|
||||
| 61 | println "lib: $lib"; |
|
|||
| 62 |
|
||||
| 63 | def sourceSets = ["main", "amd", "cjs"]; |
|
|||
| 64 | def testSets = ["test", "testAmd", "testCjs"]; |
|
|||
| 65 |
|
||||
| 66 | task beforeBuild { |
|
|||
| 67 | } |
|
|||
| 68 |
|
||||
| 69 | def createSoursetTasks = { String name, String outDir -> |
|
|||
| 70 | def setName = name.capitalize(); |
|
|||
| 71 |
|
66 | |||
| 72 | def compileDir = "$buildDir/compile/$name" |
|
67 | sources { | |
| 73 | def declDir = "$typingsDir/$name" |
|
|||
| 74 | def setDir = "$projectDir/src/$name" |
|
|||
| 75 | def jsDir = outDir; |
|
|||
| 76 |
|
||||
| 77 | def beforeBuildTask = task "beforeBuild$setName"(dependsOn: beforeBuild) { |
|
|||
| 78 | } |
|
|||
| 79 |
|
68 | |||
| 80 | def copyJsTask = task "copyJs$setName"(dependsOn: beforeBuildTask, type: Copy) { |
|
|||
| 81 | from "$setDir/js" |
|
|||
| 82 | into jsDir |
|
|||
| 83 | } |
|
|||
| 84 |
|
||||
| 85 | def lintJsTask = task "lintJs$setName"(dependsOn: beforeBuildTask, type: Exec) { |
|
|||
| 86 | inputs.dir("$setDir/js/").skipWhenEmpty(); |
|
|||
| 87 | commandLine "eslint", '--format', 'stylish', "$setDir/js/" |
|
|||
| 88 | } |
|
69 | } | |
| 89 |
|
70 | |||
| 90 | def compileTsTask = task "compileTs$setName"(dependsOn: beforeBuildTask, type: Exec) { |
|
71 | typescript { | |
| 91 | inputs.dir("$setDir/ts").skipWhenEmpty() |
|
72 | compilerOptions { | |
| 92 | inputs.file("$srcDir/tsconfig.json") |
|
73 | lib = targetLibs[target] ?: [target, "dom"] | |
| 93 | inputs.file("$setDir/tsconfig.json") |
|
74 | target = jstarget | |
| 94 | outputs.dir(compileDir) |
|
75 | module = jsmodule | |
| 95 | outputs.dir(declDir) |
|
76 | types = [] | |
| 96 |
|
||||
| 97 | commandLine 'node_modules/.bin/tsc', |
|
|||
| 98 | '-p', "$setDir/tsconfig.json", |
|
|||
| 99 | '-t', target, |
|
|||
| 100 | '-m', jsmodule, |
|
|||
| 101 | '-d', |
|
|||
| 102 | '--sourceMap', |
|
|||
| 103 | '--sourceRoot', "file://$setDir/ts", |
|
|||
| 104 | '--outDir', compileDir, |
|
|||
| 105 | '--declarationDir', declDir |
|
|||
| 106 |
|
||||
| 107 | if (lib) |
|
|||
| 108 | args '--lib', lib |
|
|||
| 109 | } |
|
77 | } | |
| 110 |
|
78 | tsLintCmd = "tslint" | ||
| 111 | def copyTsOutputTask = task "copyTsOutput$setName"(dependsOn: compileTsTask, type: Copy) { |
|
79 | esLintCmd = "eslint" | |
| 112 | from compileDir |
|
80 | npmCmd = "npm" | |
| 113 | into jsDir |
|
|||
| 114 | } |
|
|||
| 115 |
|
||||
| 116 | def copyTypingsTask = task "copyTypings$setName"(dependsOn: compileTsTask, type: Copy) { |
|
|||
| 117 | from declDir |
|
|||
| 118 | into jsDir |
|
|||
| 119 | } |
|
|||
| 120 |
|
||||
| 121 | def copyResourcesTask = task "copyResources$setName"(dependsOn: beforeBuildTask, type: Copy) { |
|
|||
| 122 | from "$setDir/resources" |
|
|||
| 123 | into outDir |
|
|||
| 124 | } |
|
|||
| 125 |
|
||||
| 126 | task "build$setName" { |
|
|||
| 127 | dependsOn copyTypingsTask, |
|
|||
| 128 | copyTsOutputTask, |
|
|||
| 129 | copyJsTask, |
|
|||
| 130 | copyResourcesTask, |
|
|||
| 131 | lintJsTask |
|
|||
| 132 | } |
|
|||
| 133 | } |
|
81 | } | |
| 134 |
|
82 | |||
| 135 | task printVersion { |
|
83 | task printVersion { | |
| @@ -167,58 +115,7 task _initBuild { | |||||
| 167 | } |
|
115 | } | |
| 168 | } |
|
116 | } | |
| 169 |
|
117 | |||
| 170 | task cleanNpm { |
|
118 | /* | |
| 171 | doLast { |
|
|||
| 172 | delete 'node_modules' |
|
|||
| 173 | } |
|
|||
| 174 | } |
|
|||
| 175 |
|
||||
| 176 | task _npmInstall() { |
|
|||
| 177 | inputs.file("package.json") |
|
|||
| 178 | outputs.dir("node_modules") |
|
|||
| 179 | doLast { |
|
|||
| 180 | exec { |
|
|||
| 181 | commandLine 'npm', 'install' |
|
|||
| 182 | } |
|
|||
| 183 | } |
|
|||
| 184 | } |
|
|||
| 185 |
|
||||
| 186 | beforeBuild { |
|
|||
| 187 | dependsOn _initBuild |
|
|||
| 188 | dependsOn _npmInstall |
|
|||
| 189 | } |
|
|||
| 190 |
|
||||
| 191 | sourceSets.each { createSoursetTasks(it, distDir) } |
|
|||
| 192 |
|
||||
| 193 | testSets.each { createSoursetTasks(it, testDir) } |
|
|||
| 194 |
|
||||
| 195 | compileTsAmd { |
|
|||
| 196 | dependsOn compileTsMain |
|
|||
| 197 | } |
|
|||
| 198 |
|
||||
| 199 | compileTsCjs { |
|
|||
| 200 | dependsOn compileTsMain |
|
|||
| 201 | } |
|
|||
| 202 |
|
||||
| 203 | task build(dependsOn: buildMain) { |
|
|||
| 204 | if (jsmodule == "amd") |
|
|||
| 205 | dependsOn buildAmd |
|
|||
| 206 | if (jsmodule == "commonjs") |
|
|||
| 207 | dependsOn buildCjs |
|
|||
| 208 | } |
|
|||
| 209 |
|
||||
| 210 | compileTsTest { |
|
|||
| 211 | dependsOn build |
|
|||
| 212 | } |
|
|||
| 213 |
|
||||
| 214 | compileTsTestAmd { |
|
|||
| 215 | dependsOn compileTsTest |
|
|||
| 216 | } |
|
|||
| 217 |
|
||||
| 218 | compileTsTestCjs { |
|
|||
| 219 | dependsOn compileTsTest |
|
|||
| 220 | } |
|
|||
| 221 |
|
||||
| 222 | task _installLocalCjsDependency(dependsOn: [buildTestCjs, "_packageMeta"], type: Exec) { |
|
119 | task _installLocalCjsDependency(dependsOn: [buildTestCjs, "_packageMeta"], type: Exec) { | |
| 223 | inputs.file("$distDir/package.json") |
|
120 | inputs.file("$distDir/package.json") | |
| 224 | outputs.upToDateWhen { |
|
121 | outputs.upToDateWhen { | |
| @@ -230,7 +127,7 task _installLocalCjsDependency(dependsO | |||||
| 230 | commandLine 'npm', 'install', '--no-save', '--force', distDir |
|
127 | commandLine 'npm', 'install', '--no-save', '--force', distDir | |
| 231 |
|
|
128 | } | |
| 232 |
|
|
129 | ||
| 233 | task test(dependsOn: [buildTest], type: Exec) { |
|
130 | task _test(dependsOn: [buildTest], type: Exec) { | |
| 234 | if (jsmodule == "amd") |
|
131 | if (jsmodule == "amd") | |
| 235 | dependsOn buildTestAmd |
|
132 | dependsOn buildTestAmd | |
| 236 | if (jsmodule == "commonjs") { |
|
133 | if (jsmodule == "commonjs") { | |
| @@ -240,37 +137,7 task test(dependsOn: [buildTest], type: | |||||
| 240 |
|
|
137 | ||
| 241 | commandLine 'node', "$testDir/run-tests.js" |
|
138 | commandLine 'node', "$testDir/run-tests.js" | |
| 242 |
|
|
139 | } | |
| 243 |
|
140 | */ | ||
| 244 | task _packageMeta(type: Copy) { |
|
|||
| 245 | mustRunAfter build |
|
|||
| 246 |
|
||||
| 247 | inputs.property("version", version) |
|
|||
| 248 | from('.') { |
|
|||
| 249 | include '.npmignore', 'readme.md', 'license', 'history.md' |
|
|||
| 250 | } |
|
|||
| 251 | from("$srcDir/package.${jsmodule}.tmpl.json") { |
|
|||
| 252 | expand project.properties |
|
|||
| 253 | rename { "package.json" } |
|
|||
| 254 | } |
|
|||
| 255 | into distDir |
|
|||
| 256 | } |
|
|||
| 257 |
|
||||
| 258 | task pack(dependsOn: [build, _packageMeta], type: Exec) { |
|
|||
| 259 | workingDir distDir |
|
|||
| 260 | outputs.file("$npmScope-$npmName-${version}.tgz") |
|
|||
| 261 |
|
||||
| 262 | commandLine 'npm', 'pack' |
|
|||
| 263 | } |
|
|||
| 264 |
|
||||
| 265 | task publish(dependsOn: [build, _packageMeta], type: Exec) { |
|
|||
| 266 | doFirst { |
|
|||
| 267 | if (!isRelease) |
|
|||
| 268 | throw new Exception("Can't publish an unreleased version"); |
|
|||
| 269 | } |
|
|||
| 270 | workingDir distDir |
|
|||
| 271 |
|
||||
| 272 | commandLine 'npm', 'publish', '--access', 'public' |
|
|||
| 273 | } |
|
|||
| 274 |
|
141 | |||
| 275 | task markRelease(type: Exec) { |
|
142 | task markRelease(type: Exec) { | |
| 276 | onlyIf { tagDistance > 1 } |
|
143 | onlyIf { tagDistance > 1 } | |
| @@ -1,5 +1,5 | |||||
| 1 | distributionBase=GRADLE_USER_HOME |
|
1 | distributionBase=GRADLE_USER_HOME | |
| 2 | distributionPath=wrapper/dists |
|
2 | distributionPath=wrapper/dists | |
| 3 |
distributionUrl=https\://services.gradle.org/distributions/gradle- |
|
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip | |
| 4 | zipStoreBase=GRADLE_USER_HOME |
|
4 | zipStoreBase=GRADLE_USER_HOME | |
| 5 | zipStorePath=wrapper/dists |
|
5 | zipStorePath=wrapper/dists | |
| @@ -90,7 +90,7 | |||||
| 90 | }, |
|
90 | }, | |
| 91 | "duplexer": { |
|
91 | "duplexer": { | |
| 92 | "version": "0.1.1", |
|
92 | "version": "0.1.1", | |
| 93 |
"resolved": "http |
|
93 | "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", | |
| 94 | "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", |
|
94 | "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", | |
| 95 | "dev": true |
|
95 | "dev": true | |
| 96 | }, |
|
96 | }, | |
| @@ -144,7 +144,7 | |||||
| 144 | "dependencies": { |
|
144 | "dependencies": { | |
| 145 | "tape": { |
|
145 | "tape": { | |
| 146 | "version": "2.3.3", |
|
146 | "version": "2.3.3", | |
| 147 |
"resolved": "http |
|
147 | "resolved": "http://registry.npmjs.org/tape/-/tape-2.3.3.tgz", | |
| 148 | "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=", |
|
148 | "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=", | |
| 149 | "dev": true, |
|
149 | "dev": true, | |
| 150 | "requires": { |
|
150 | "requires": { | |
| @@ -277,7 +277,7 | |||||
| 277 | }, |
|
277 | }, | |
| 278 | "minimist": { |
|
278 | "minimist": { | |
| 279 | "version": "0.0.5", |
|
279 | "version": "0.0.5", | |
| 280 |
"resolved": "http |
|
280 | "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz", | |
| 281 | "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=", |
|
281 | "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=", | |
| 282 | "dev": true |
|
282 | "dev": true | |
| 283 | }, |
|
283 | }, | |
| @@ -316,7 +316,7 | |||||
| 316 | }, |
|
316 | }, | |
| 317 | "readable-stream": { |
|
317 | "readable-stream": { | |
| 318 | "version": "1.1.14", |
|
318 | "version": "1.1.14", | |
| 319 |
"resolved": "http |
|
319 | "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", | |
| 320 | "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", |
|
320 | "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", | |
| 321 | "dev": true, |
|
321 | "dev": true, | |
| 322 | "requires": { |
|
322 | "requires": { | |
| @@ -369,7 +369,7 | |||||
| 369 | }, |
|
369 | }, | |
| 370 | "string_decoder": { |
|
370 | "string_decoder": { | |
| 371 | "version": "0.10.31", |
|
371 | "version": "0.10.31", | |
| 372 |
"resolved": "http |
|
372 | "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", | |
| 373 | "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", |
|
373 | "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", | |
| 374 | "dev": true |
|
374 | "dev": true | |
| 375 | }, |
|
375 | }, | |
| @@ -432,7 +432,7 | |||||
| 432 | }, |
|
432 | }, | |
| 433 | "through2": { |
|
433 | "through2": { | |
| 434 | "version": "0.2.3", |
|
434 | "version": "0.2.3", | |
| 435 |
"resolved": "http |
|
435 | "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz", | |
| 436 | "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=", |
|
436 | "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=", | |
| 437 | "dev": true, |
|
437 | "dev": true, | |
| 438 | "requires": { |
|
438 | "requires": { | |
General Comments 0
You need to be logged in to leave comments.
Login now
