Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 2 | * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 3 | */ |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 4 | |
| 5 | def prop(name, defVal) { |
| 6 | def value = project.properties[name] |
| 7 | if (value == null) return defVal |
| 8 | return value |
| 9 | } |
| 10 | |
| 11 | def distTag(version) { |
| 12 | def i = version.indexOf('-') |
| 13 | if (i > 0) return version.substring(i + 1) |
| 14 | return "latest" |
| 15 | } |
| 16 | |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 17 | def npmTemplateDir = file("$projectDir/npm") |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 18 | def npmDeployDir = file("$buildDir/npm") |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 19 | |
| 20 | def authToken = prop("kotlin.npmjs.auth.token", "") |
| 21 | def dryRun = prop("dryRun", "false") |
| 22 | |
Roman Elizarov | d01f926 | 2018-09-05 13:02:23 +0300 | [diff] [blame] | 23 | // Note: publish transformed files using dependency on sourceSets.main.output |
| 24 | task preparePublishNpm(type: Copy) { |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 25 | from(npmTemplateDir) { |
Roman Elizarov | 504c876 | 2019-04-24 12:04:02 +0300 | [diff] [blame] | 26 | // Postpone expansion of package.json until we configure version property in build.gradle |
| 27 | def copySpec = it |
| 28 | afterEvaluate { |
| 29 | copySpec.expand(project.properties + [kotlinDependency: "\"kotlin\": \"$kotlin_version\""]) |
| 30 | } |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 31 | } |
Roman Elizarov | 504c876 | 2019-04-24 12:04:02 +0300 | [diff] [blame] | 32 | // we must publish output that is transformed by atomicfu |
| 33 | from(kotlin.targets.js.compilations.main.output.allOutputs) |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 34 | into npmDeployDir |
| 35 | } |
| 36 | |
| 37 | task publishNpm(type: NpmTask, dependsOn: [preparePublishNpm]) { |
| 38 | workingDir = npmDeployDir |
Vsevolod Tolstopyatov | 390c722 | 2019-04-23 18:42:11 +0300 | [diff] [blame] | 39 | |
Ilya Gorbunov | 58fa752 | 2018-04-18 18:21:02 +0300 | [diff] [blame] | 40 | doFirst { |
Vsevolod Tolstopyatov | 390c722 | 2019-04-23 18:42:11 +0300 | [diff] [blame] | 41 | def npmDeployTag = distTag(version) |
| 42 | def deployArgs = ['publish', |
| 43 | "--//registry.npmjs.org/:_authToken=$authToken", |
| 44 | "--tag=$npmDeployTag"] |
Ilya Gorbunov | 58fa752 | 2018-04-18 18:21:02 +0300 | [diff] [blame] | 45 | if (dryRun == "true") { |
| 46 | println("$npmDeployDir \$ npm arguments: $deployArgs") |
| 47 | args = ['pack'] |
| 48 | } else { |
| 49 | args = deployArgs |
| 50 | } |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 51 | } |
| 52 | } |