aboutsummaryrefslogtreecommitdiffstats
path: root/gradle/publish-npm-js.gradle
diff options
context:
space:
mode:
Diffstat (limited to 'gradle/publish-npm-js.gradle')
-rw-r--r--gradle/publish-npm-js.gradle52
1 files changed, 52 insertions, 0 deletions
diff --git a/gradle/publish-npm-js.gradle b/gradle/publish-npm-js.gradle
new file mode 100644
index 00000000..a2991db4
--- /dev/null
+++ b/gradle/publish-npm-js.gradle
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016-2019 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 authToken = prop("kotlin.npmjs.auth.token", "")
+def dryRun = prop("dryRun", "false")
+
+// Note: publish transformed files using dependency on sourceSets.main.output
+task preparePublishNpm(type: Copy) {
+ from(npmTemplateDir) {
+ // Postpone expansion of package.json until we configure version property in build.gradle
+ def copySpec = it
+ afterEvaluate {
+ copySpec.expand(project.properties + [kotlinDependency: "\"kotlin\": \"$kotlin_version\""])
+ }
+ }
+ // we must publish output that is transformed by atomicfu
+ from(kotlin.targets.js.compilations.main.output.allOutputs)
+ into npmDeployDir
+}
+
+task publishNpm(type: NpmTask, dependsOn: [preparePublishNpm]) {
+ workingDir = npmDeployDir
+
+ doFirst {
+ def npmDeployTag = distTag(version)
+ def deployArgs = ['publish',
+ "--//registry.npmjs.org/:_authToken=$authToken",
+ "--tag=$npmDeployTag"]
+ if (dryRun == "true") {
+ println("$npmDeployDir \$ npm arguments: $deployArgs")
+ args = ['pack']
+ } else {
+ args = deployArgs
+ }
+ }
+}