Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 1 | /* |
Aurimas Liutikas | 79e555e | 2021-05-17 17:41:41 +0000 | [diff] [blame] | 2 | * Copyright 2016-2021 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 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 23 | def jsLegacy = kotlin.targets.hasProperty("jsLegacy") |
| 24 | ? kotlin.targets.jsLegacy |
| 25 | : kotlin.targets.js |
| 26 | |
Roman Elizarov | d01f926 | 2018-09-05 13:02:23 +0300 | [diff] [blame] | 27 | // Note: publish transformed files using dependency on sourceSets.main.output |
| 28 | task preparePublishNpm(type: Copy) { |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 29 | from(npmTemplateDir) { |
Roman Elizarov | 504c876 | 2019-04-24 12:04:02 +0300 | [diff] [blame] | 30 | // Postpone expansion of package.json until we configure version property in build.gradle |
| 31 | def copySpec = it |
| 32 | afterEvaluate { |
| 33 | copySpec.expand(project.properties + [kotlinDependency: "\"kotlin\": \"$kotlin_version\""]) |
| 34 | } |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 35 | } |
Roman Elizarov | 504c876 | 2019-04-24 12:04:02 +0300 | [diff] [blame] | 36 | // we must publish output that is transformed by atomicfu |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 37 | from(jsLegacy.compilations.main.output.allOutputs) |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 38 | into npmDeployDir |
| 39 | } |
| 40 | |
| 41 | task publishNpm(type: NpmTask, dependsOn: [preparePublishNpm]) { |
| 42 | workingDir = npmDeployDir |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 43 | |
| 44 | def npmDeployTag = distTag(version) |
| 45 | def deployArgs = ['publish', |
| 46 | "--//registry.npmjs.org/:_authToken=$authToken", |
| 47 | "--tag=$npmDeployTag"] |
| 48 | if (dryRun == "true") { |
| 49 | println("$npmDeployDir \$ npm arguments: $deployArgs") |
| 50 | args = ['pack'] |
| 51 | } else { |
| 52 | args = deployArgs |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 53 | } |
| 54 | } |