/* * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ def prop(name, defVal) { def value = project.properties[name] if (value == null) return defVal return value } def distTag(version) { def i = version.indexOf('-') if (i > 0) return version.substring(i + 1) return "latest" } def npmTemplateDir = file("$projectDir/npm") def npmDeployDir = file("$buildDir/npm") def npmDeployTag = distTag(version) def authToken = prop("kotlin.npmjs.auth.token", "") def dryRun = prop("dryRun", "false") def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy") ? compileKotlinJsLegacy : compileKotlinJs task preparePublishNpm(type: Copy, dependsOn: [compileJsLegacy]) { from(npmTemplateDir) { expand (project.properties + [kotlinDependency: "\"kotlin\": \"$kotlin_version\""]) } from(compileJsLegacy.destinationDir) into npmDeployDir } task performPublishNpm(type: NpmTask, dependsOn: [preparePublishNpm]) { workingDir = npmDeployDir def deployArgs = ['publish', "--//registry.npmjs.org/:_authToken=$authToken", "--tag=$npmDeployTag"] doFirst { if (dryRun == "true") { println("$npmDeployDir \$ npm arguments: $deployArgs") args = ['pack'] } else { args = deployArgs } } if (authToken == "") { enabled = false // skip npm publishing when token is not set } } task publishNpm(dependsOn: performPublishNpm) { doFirst { if (!performPublishNpm.enabled) { println("NOTE: publishNpm is skipped because 'kotlin.npmjs.auth.token' is not set") } } }