-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
142 lines (126 loc) · 3.97 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@file:Suppress("UNUSED_VARIABLE")
plugins {
val kotlinVersion = "1.6.10"
kotlin("multiplatform") version kotlinVersion
`maven-publish`
}
group = "com.harry1453.klaunchpad"
version = "0.0.6"
repositories {
mavenCentral()
}
kotlin {
explicitApi()
jvm {
compilations.forEach {
it.kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
}
js(IR) {
browser {
dceTask {
keep("KLaunchpad.connectToLaunchpadMK2", "KLaunchpad.connectToLaunchpadPro", "KLaunchpad.BLACK", "KLaunchpad.color", "KLaunchpad.faderSettings")
}
testTask {
enabled = false
}
}
binaries.executable()
binaries.library()
}
mingwX64("nativeWindows") {
compilations.getByName("main") {
val nativeTypes by cinterops.creating {
defFile(project.file("src/nativeApiMain/resources/NativeTypes.def"))
packageName("nativeApi.types")
}
}
binaries {
sharedLib {
baseName = "KLaunchpad"
}
}
}
sourceSets {
all {
languageSettings {
languageSettings.optIn("kotlin.ExperimentalStdlibApi")
languageSettings.optIn("kotlin.contracts.ExperimentalContracts")
languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
languageSettings.optIn("kotlin.js.ExperimentalJsExport")
languageSettings.optIn("kotlinx.coroutines.DelicateCoroutinesApi")
}
}
commonMain {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
}
}
commonTest {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
val nativeApiMain by creating {
dependsOn(commonMain.get())
}
val nativeWindowsMain by getting {
dependsOn(nativeApiMain)
}
}
}
tasks {
val preparePublishNpm by creating {
dependsOn("compileProductionLibraryKotlinJs")
doLast {
delete {
"$projectDir/build/js/packages/klaunchpad/package.json"
}
copy {
from("$projectDir/src/jsMain/resources/package.json")
from("$projectDir/README.md")
into("$projectDir/build/js/packages/klaunchpad/")
}
copy {
from("$projectDir/src/jsMain/resources/KLaunchpad.d.ts")
into("$projectDir/build/js/packages/klaunchpad/kotlin")
}
val path = "$projectDir/build/js/packages/klaunchpad/".replace("\\", File.separator).replace("/", File.separator)
println()
println("Ready to publish! When you are ready to publish, enter the following commands:")
println()
println("cd \"$path\"")
println("npm publish")
println()
}
}
val packageForPureJS by creating {
dependsOn("jsBrowserProductionWebpack")
doLast {
println("Pure JS library created at: $projectDir/build/distributions/klaunchpad.js")
}
}
}
// Reduces Kotlin/JS bundle size
@Suppress("SuspiciousCollectionReassignment")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile> {
kotlinOptions {
freeCompilerArgs += listOf("-Xir-per-module", "-Xir-property-lazy-initialization")
}
}
tasks.withType<Copy> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}