-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
72 lines (58 loc) · 2.53 KB
/
build.gradle.kts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import io.github.gciatto.kt.node.Bugs
import io.github.gciatto.kt.node.People
plugins {
kotlin("js") version "1.8.0"
// https://github.com/gciatto/kt-npm-publish
id("io.github.gciatto.kt-npm-publish") version "0.3.9"
}
group = "me.vergedx"
version = "1.0.0" // https://semver.org/lang/zh-CN/
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test-js"))
// https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-node
implementation("org.jetbrains.kotlin-wrappers:kotlin-node:18.11.18-pre.472")
}
kotlin {
js(IR) { // https://discuss.kotlinlang.org/t/kotlin-js-1-4-how-to-output-a-npm-package/19128
binaries.executable()
// https://www.kotlincn.net/docs/reference/js-modules.html
useCommonJs()
// http://www.kotlincn.net/docs/reference/js-project-setup.html#packagejson-customization
nodejs {
compilations["main"].packageJson {
// https://docs.npmjs.com/cli/v7/configuring-npm/package-json#bin
customField("bin", mapOf("lkf" to "./kotlin/looks-fun.js"))
}
}
}
}
val github = "https://github.com/Vanilla-s-Lab/looks-fun"
val (myName, myEmail) = "Vanilla" to "[email protected]"
val myGithub = "https://github.com/VergeDX"
npmPublishing {
val npmToken = properties["npmToken"] ?: ""
token.set(npmToken as String)
// https://github.com/gciatto/kt-npm-publish
liftPackageJson { // Hook in liftJsSources is too early, .js will be overwrite.
val pjName = project.name
val mainJs = file("${buildDir.path}/js/packages/$pjName/kotlin/${pjName}.js")
val bakByteArray = mainJs.readBytes()
// https://docs.npmjs.com/cli/v7/configuring-npm/package-json#bin
val shebang = "#!/usr/bin/env node" + "\n\n"
mainJs.writeBytes(shebang.toByteArray() + bakByteArray)
// https://docs.npmjs.com/cli/v7/configuring-npm/package-json
description = "A CLI tool to lookup 43 kinds of Java Standard Functional Interface."
keywords = listOf("Java", "Kotlin").toMutableList()
homepage = github
bugs = Bugs("$github/issues", myEmail)
license = "MIT"
people = listOf(People(myName, myEmail, myGithub)).toMutableList()
}
}
// https://kotlinlang.org/docs/js-project-setup.html#use-pre-installed-node-js
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().download = false
}