aboutsummaryrefslogtreecommitdiff
path: root/gradle/publish-npm-js.gradle
blob: dbf7b64c2ff5ca67739899b3420da8e7478898a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

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")

task preparePublishNpm(type: Copy, dependsOn: [compileKotlin2Js]) {
    from(npmTemplateDir) {
        expand (project.properties + [kotlinDependency: "\"kotlin\": \"$kotlin_version\""])
    }
    from("$buildDir/classes/kotlin/main")
    into npmDeployDir
}

task publishNpm(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
        }
    }
}