-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
90 lines (80 loc) · 3.48 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
import org.gradle.internal.logging.text.StyledTextOutput
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.gradle.kotlin.dsl.support.serviceOf
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
val out: StyledTextOutput = project.serviceOf<StyledTextOutputFactory>().create("output")
plugins {
kotlin("multiplatform") version "1.9.23"
}
// Generate the yarn file automatically
project.rootProject.plugins.withType(YarnPlugin::class.java) {
with(project.rootProject.the<YarnRootExtension>()) {
yarnLockMismatchReport = YarnLockMismatchReport.NONE
yarnLockAutoReplace = true
}
}
group = "hello_kotlin_js"
version = "1.0"
repositories {
mavenCentral()
}
kotlin {
js(IR) {
nodejs {}
binaries.executable()
useCommonJs()
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
}
}
val jsMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.8.0")
implementation("org.jetbrains.kotlin-wrappers:kotlin-node:20.11.30-pre.739")
// Dukat integration was supposed to give TypeScript -> Kotlin types, but it has been deprecated
// ==========
// Please note, Dukat integration in Gradle plugin does not work now.
// It is in redesigning process.
// ==========
// 'npm(String, String, Boolean): Dependency' is deprecated. Dukat integration is in redesigning process. Now it does not work.
// implementation(npm("axios", "1.6.8", generateExternals = true))
implementation(npm("axios", "1.6.8"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test")) // Brings all the platform dependencies automatically
}
}
val jsTest by getting {
dependencies {
implementation(kotlin("test")) // Brings all the platform dependencies automatically
}
}
}
}
// Just a nice to have, gives a slightly prettier output when running the tests
tasks.withType<AbstractTestTask> {
afterSuite(KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
fun status(prefix: String, resultType: TestResult.ResultType, header: Boolean = false): StyledTextOutput {
val progressStatus = if (header) Style.Header else Style.Info
return when (resultType) {
TestResult.ResultType.SUCCESS -> out.style(progressStatus).text(prefix).style(Style.Success).text(resultType)
TestResult.ResultType.FAILURE -> out.style(progressStatus).text(prefix).style(Style.Failure).text(resultType)
TestResult.ResultType.SKIPPED -> out.style(progressStatus).text(prefix).style(Style.Info).text(resultType)
}
}
fun col(text: String) = text.padEnd(11, ' ')
if (desc.parent == null) {
status("${col("TEST RESULT")} : ", result.resultType, true).println()
} else {
status("${col(desc.displayName)} : ", result.resultType).println()
}
}))
}