blob: a2991db492883a21c06081eef1798b512567568d [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +03002 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03003 */
Roman Elizarov94fb2a32018-03-05 17:32:59 +03004
5def prop(name, defVal) {
6 def value = project.properties[name]
7 if (value == null) return defVal
8 return value
9}
10
11def distTag(version) {
12 def i = version.indexOf('-')
13 if (i > 0) return version.substring(i + 1)
14 return "latest"
15}
16
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030017def npmTemplateDir = file("$projectDir/npm")
Roman Elizarov94fb2a32018-03-05 17:32:59 +030018def npmDeployDir = file("$buildDir/npm")
Roman Elizarov94fb2a32018-03-05 17:32:59 +030019
20def authToken = prop("kotlin.npmjs.auth.token", "")
21def dryRun = prop("dryRun", "false")
22
Roman Elizarovd01f9262018-09-05 13:02:23 +030023// Note: publish transformed files using dependency on sourceSets.main.output
24task preparePublishNpm(type: Copy) {
Roman Elizarov94fb2a32018-03-05 17:32:59 +030025 from(npmTemplateDir) {
Roman Elizarov504c8762019-04-24 12:04:02 +030026 // 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 Elizarov94fb2a32018-03-05 17:32:59 +030031 }
Roman Elizarov504c8762019-04-24 12:04:02 +030032 // we must publish output that is transformed by atomicfu
33 from(kotlin.targets.js.compilations.main.output.allOutputs)
Roman Elizarov94fb2a32018-03-05 17:32:59 +030034 into npmDeployDir
35}
36
37task publishNpm(type: NpmTask, dependsOn: [preparePublishNpm]) {
38 workingDir = npmDeployDir
Vsevolod Tolstopyatov390c7222019-04-23 18:42:11 +030039
Ilya Gorbunov58fa7522018-04-18 18:21:02 +030040 doFirst {
Vsevolod Tolstopyatov390c7222019-04-23 18:42:11 +030041 def npmDeployTag = distTag(version)
42 def deployArgs = ['publish',
43 "--//registry.npmjs.org/:_authToken=$authToken",
44 "--tag=$npmDeployTag"]
Ilya Gorbunov58fa7522018-04-18 18:21:02 +030045 if (dryRun == "true") {
46 println("$npmDeployDir \$ npm arguments: $deployArgs")
47 args = ['pack']
48 } else {
49 args = deployArgs
50 }
Roman Elizarov94fb2a32018-03-05 17:32:59 +030051 }
52}