Skip to content

Commit 94fb2a3

Browse files
committed
JS: Publish to npm:
* Package name is "kotlinx-coroutines-core" * JS file name is "kotlinx-coroutines-core.js" The name of JS file is also updated in Bintray upload. Fixes #229
1 parent 6140ca3 commit 94fb2a3

File tree

9 files changed

+93
-16
lines changed

9 files changed

+93
-16
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ configure(subprojects.findAll { !sourceless.contains(it.name) }) {
6161
moduleKind = "umd"
6262
sourceMap = true
6363
metaInfo = true
64+
// drop -js suffix from outputFile
65+
def baseName = project.name - "-js"
66+
outputFile = new File(outputFile.parent, baseName + ".js")
6467
}
6568
}
6669
}
@@ -182,6 +185,9 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
182185
}
183186
}
184187

188+
// main deployment task
189+
task deploy(dependsOn: getTasksByName("bintrayUpload", true) + getTasksByName("publishNpm", true))
190+
185191
apply plugin: 'base'
186192

187193
clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }

gradle/node-js.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
apply plugin: 'com.moowork.node'
3+
4+
node {
5+
version = "$node_version"
6+
npmVersion = "$npm_version"
7+
download = true
8+
}

gradle/publish-npm-js.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
def prop(name, defVal) {
3+
def value = project.properties[name]
4+
if (value == null) return defVal
5+
return value
6+
}
7+
8+
def distTag(version) {
9+
def i = version.indexOf('-')
10+
if (i > 0) return version.substring(i + 1)
11+
return "latest"
12+
}
13+
14+
def npmTemplateDir = file("$projectDir/npm")
15+
def npmDeployDir = file("$buildDir/npm")
16+
def npmDeployTag = distTag(version)
17+
18+
def authToken = prop("kotlin.npmjs.auth.token", "")
19+
def dryRun = prop("dryRun", "false")
20+
21+
task preparePublishNpm(type: Copy, dependsOn: [compileKotlin2Js]) {
22+
from(npmTemplateDir) {
23+
expand project.properties
24+
}
25+
from("$buildDir/classes/kotlin/main")
26+
into npmDeployDir
27+
}
28+
29+
task publishNpm(type: NpmTask, dependsOn: [preparePublishNpm]) {
30+
workingDir = npmDeployDir
31+
def deployArgs = ['publish',
32+
"--//registry.npmjs.org/:_authToken=$authToken",
33+
"--tag=$npmDeployTag"]
34+
if (dryRun == "true") {
35+
println("$npmDeployDir \$ npm arguments: $deployArgs")
36+
args = ['pack']
37+
} else {
38+
args = deployArgs
39+
}
40+
}

gradle/test-mocha-js.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Configures testing for JS modules
22

3-
apply plugin: 'com.moowork.node'
4-
53
task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
64
from compileKotlin2Js.destinationDir
75
into "${buildDir}/node_modules"
@@ -16,12 +14,6 @@ task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
1614
}
1715
}
1816

19-
node {
20-
version = "$node_version"
21-
npmVersion = "$npm_version"
22-
download = true
23-
}
24-
2517
// -- Testing with Mocha under Node
2618

2719
task installDependenciesMochaNode(type: NpmTask) {

js/example-frontend-js/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
apply plugin: 'kotlin-dce-js'
18-
apply plugin: 'com.moowork.node'
18+
apply from: rootProject.file('gradle/node-js.gradle')
1919

2020
dependencies {
2121
compile "org.jetbrains.kotlinx:kotlinx-html-js:$html_version"
@@ -27,12 +27,6 @@ compileKotlin2Js {
2727
}
2828
}
2929

30-
node {
31-
version = "$node_version"
32-
npmVersion = "$npm_version"
33-
download = true
34-
}
35-
3630
task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
3731
args = ["run", "bundle"]
3832
}

js/example-frontend-js/src/main/web/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
// ------ Main bundle for example application ------
1818

19-
require("example-frontend-js");
19+
require("example-frontend");
2020
require("style.css");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
2+
apply from: rootProject.file('gradle/node-js.gradle')
13
apply from: rootProject.file('gradle/test-mocha-js.gradle')
4+
apply from: rootProject.file('gradle/publish-npm-js.gradle')
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# kotlinx.coroutines
2+
3+
Library support for Kotlin coroutines in
4+
[Kotlin/JS](https://kotlinlang.org/docs/reference/js-overview.html).
5+
6+
## Documentation
7+
8+
* [Full kotlinx.coroutines API reference](http://kotlin.github.io/kotlinx.coroutines)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "kotlinx-coroutines-core",
3+
"version" : "$version",
4+
"description" : "Library support for Kotlin coroutines",
5+
"main" : "kotlinx-coroutines-core-js.js",
6+
"author": "JetBrains",
7+
"license": "Apache-2.0",
8+
"homepage": "https://github.com/Kotlin/kotlinx.coroutines",
9+
"bugs": {
10+
"url": "https://github.com/Kotlin/kotlinx.coroutines/issues"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/Kotlin/kotlinx.coroutines.git"
15+
},
16+
"keywords": [
17+
"Kotlin",
18+
"async",
19+
"coroutines",
20+
"JavaScript",
21+
"JetBrains"
22+
],
23+
"dependencies": {
24+
"kotlin": "$kotlin_version"
25+
}
26+
}

0 commit comments

Comments
 (0)