2022-09-18 20:49:32 +02:00
|
|
|
import kafkatorio.tasks.GenerateTypeScriptTask
|
2022-07-05 23:44:23 +02:00
|
|
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|
|
|
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
|
|
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
2022-10-04 23:47:16 +02:00
|
|
|
import dev.adamko.gradle.factorio.typescriptAttributes
|
2021-11-10 17:34:01 +01:00
|
|
|
|
2022-02-09 13:16:57 +01:00
|
|
|
|
2021-10-22 18:17:48 +02:00
|
|
|
plugins {
|
2022-09-18 20:49:32 +02:00
|
|
|
id("kafkatorio.conventions.lang.kotlin-multiplatform")
|
2022-12-18 01:40:40 +01:00
|
|
|
id("dev.adamko.factorio-mod-library") // only needed for 'attributes' - need to split up the plugin?
|
2022-02-09 13:16:57 +01:00
|
|
|
kotlin("plugin.serialization")
|
2021-12-02 00:54:15 +01:00
|
|
|
distribution
|
2021-10-29 19:14:47 +02:00
|
|
|
}
|
2021-10-25 23:35:18 +02:00
|
|
|
|
2022-02-09 13:16:57 +01:00
|
|
|
|
2022-07-01 13:14:32 +02:00
|
|
|
description = "shared data structures and utilities"
|
|
|
|
|
|
|
|
|
|
|
2021-12-08 17:43:08 +01:00
|
|
|
kotlin {
|
2022-04-19 23:25:10 +02:00
|
|
|
|
2021-12-08 17:43:08 +01:00
|
|
|
js(IR) {
|
2022-06-19 10:21:59 +02:00
|
|
|
browser {}
|
2022-06-26 14:56:53 +02:00
|
|
|
// this is a library - don't set binaries.executable()
|
2021-12-08 17:43:08 +01:00
|
|
|
}
|
2022-01-09 11:06:15 +01:00
|
|
|
jvm {
|
2022-04-19 23:25:10 +02:00
|
|
|
val main by compilations.getting {
|
|
|
|
|
kotlinOptions {
|
|
|
|
|
jvmTarget = "11"
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-02 12:11:06 +02:00
|
|
|
testRuns.configureEach {
|
|
|
|
|
executionTask.configure {
|
|
|
|
|
useJUnitPlatform()
|
|
|
|
|
}
|
2022-01-09 11:06:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-08 17:43:08 +01:00
|
|
|
|
|
|
|
|
sourceSets {
|
|
|
|
|
|
2022-09-11 00:25:58 +02:00
|
|
|
configureEach {
|
2021-12-08 17:43:08 +01:00
|
|
|
languageSettings.apply {
|
|
|
|
|
optIn("kotlin.ExperimentalStdlibApi")
|
2022-07-05 23:44:23 +02:00
|
|
|
optIn("kotlin.ExperimentalUnsignedTypes")
|
2022-07-02 10:21:13 +02:00
|
|
|
optIn("kotlin.RequiresOptIn")
|
|
|
|
|
optIn("kotlin.js.ExperimentalJsExport")
|
2021-12-08 17:43:08 +01:00
|
|
|
optIn("kotlin.time.ExperimentalTime")
|
2022-07-02 10:21:13 +02:00
|
|
|
optIn("kotlinx.coroutines.FlowPreview")
|
2021-12-08 17:43:08 +01:00
|
|
|
optIn("kotlinx.serialization.ExperimentalSerializationApi")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val commonMain by getting {
|
|
|
|
|
dependencies {
|
2022-07-06 17:16:09 +02:00
|
|
|
implementation(dependencies.platform(projects.modules.versionsPlatform))
|
2021-12-08 17:43:08 +01:00
|
|
|
|
2022-09-11 00:48:16 +02:00
|
|
|
implementation(libs.kotlinxSerialization.core)
|
|
|
|
|
implementation(libs.kotlinxSerialization.json)
|
|
|
|
|
api(libs.kotlinxSerialization.kxsTsGen)
|
2022-07-02 08:45:21 +02:00
|
|
|
|
|
|
|
|
implementation(libs.okio.core)
|
|
|
|
|
|
|
|
|
|
implementation(libs.kotlinx.coroutines.core)
|
2021-12-08 17:43:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val commonTest by getting {
|
|
|
|
|
dependencies {
|
2022-07-06 17:16:09 +02:00
|
|
|
implementation(dependencies.platform(projects.modules.versionsPlatform))
|
2021-12-08 17:43:08 +01:00
|
|
|
|
|
|
|
|
implementation(kotlin("test"))
|
|
|
|
|
|
2022-05-14 12:23:58 +02:00
|
|
|
implementation(libs.kotest.core)
|
|
|
|
|
implementation(libs.kotest.datatest)
|
2022-07-06 16:20:11 +02:00
|
|
|
implementation(libs.kotest.frameworkEngine)
|
2022-05-14 12:23:58 +02:00
|
|
|
implementation(libs.kotest.json)
|
2022-07-06 16:20:11 +02:00
|
|
|
implementation(libs.kotest.prop)
|
2021-12-08 17:43:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-11-10 17:34:01 +01:00
|
|
|
|
2021-12-08 17:43:08 +01:00
|
|
|
val jvmMain by getting {
|
|
|
|
|
dependencies {
|
2022-07-06 17:16:09 +02:00
|
|
|
implementation(dependencies.platform(projects.modules.versionsPlatform))
|
|
|
|
|
|
2022-04-19 23:25:10 +02:00
|
|
|
implementation(kotlin("reflect"))
|
2021-12-08 17:43:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-03 09:04:18 +01:00
|
|
|
|
2021-12-08 17:43:08 +01:00
|
|
|
val jvmTest by getting {
|
|
|
|
|
dependencies {
|
2022-07-06 17:16:09 +02:00
|
|
|
implementation(dependencies.platform(projects.modules.versionsPlatform))
|
|
|
|
|
|
2022-07-06 16:20:11 +02:00
|
|
|
implementation(libs.kotest.runnerJunit5)
|
2021-12-08 17:43:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-13 10:44:13 +01:00
|
|
|
|
|
|
|
|
val jsTest by getting {
|
2022-07-06 17:16:09 +02:00
|
|
|
dependencies { }
|
2022-02-13 10:44:13 +01:00
|
|
|
}
|
2021-12-08 17:43:08 +01:00
|
|
|
}
|
2021-10-31 09:13:41 +01:00
|
|
|
}
|
2021-11-10 17:34:01 +01:00
|
|
|
|
2022-07-02 10:21:13 +02:00
|
|
|
|
2022-07-05 23:44:23 +02:00
|
|
|
val kotlinJvmMainCompilation: NamedDomainObjectProvider<KotlinJvmCompilation> =
|
|
|
|
|
kotlin.jvm().compilations.named(KotlinCompilation.MAIN_COMPILATION_NAME)
|
|
|
|
|
|
|
|
|
|
|
2022-05-07 20:22:54 +02:00
|
|
|
val jvmJar: TaskProvider<Jar> = tasks.named<Jar>(kotlin.jvm().artifactsTaskName)
|
2022-07-05 23:44:23 +02:00
|
|
|
|
|
|
|
|
val kotlinMainRuntimeDependencies: Provider<FileCollection> =
|
|
|
|
|
kotlinJvmMainCompilation.map { it.runtimeDependencyFiles }
|
|
|
|
|
|
|
|
|
|
val kotlinMainCompileDependencies: Provider<FileCollection> =
|
|
|
|
|
kotlinJvmMainCompilation.map { it.compileDependencyFiles }
|
|
|
|
|
|
|
|
|
|
val kotlinMainCompileTask: Provider<KotlinCompile> =
|
|
|
|
|
kotlinJvmMainCompilation.map { it.compileKotlinTask }
|
2021-12-08 17:43:08 +01:00
|
|
|
|
2021-11-10 17:34:01 +01:00
|
|
|
|
2022-06-26 14:56:53 +02:00
|
|
|
val generateTypeScript by tasks.registering(GenerateTypeScriptTask::class) {
|
2022-04-23 17:59:37 +02:00
|
|
|
dependsOn(jvmJar)
|
2022-07-05 23:44:23 +02:00
|
|
|
// dependsOn(kotlinMainCompileTask)
|
|
|
|
|
|
|
|
|
|
// inputs.files(jvmJar.map { it.outputs.files })
|
|
|
|
|
// inputs.files(kotlinMainCompileTask.map { it.javaSources })
|
|
|
|
|
|
2021-12-08 17:43:08 +01:00
|
|
|
classpath(
|
|
|
|
|
jvmJar,
|
2022-07-05 23:44:23 +02:00
|
|
|
kotlinMainRuntimeDependencies,
|
|
|
|
|
// kotlinMainCompileTask.map { it.libraries }
|
|
|
|
|
// kotlinMainDependencies,
|
2021-12-08 17:43:08 +01:00
|
|
|
)
|
2022-05-07 20:22:54 +02:00
|
|
|
output.set(layout.buildDirectory.dir("generated/typescript"))
|
2022-07-16 23:10:32 +02:00
|
|
|
mainClass.set("dev.adamko.kafkatorio.schema.Kt2ts2Kt")
|
2022-05-07 20:22:54 +02:00
|
|
|
args(temporaryDir.canonicalPath)
|
|
|
|
|
}
|
2021-12-08 17:43:08 +01:00
|
|
|
|
2022-07-02 10:21:13 +02:00
|
|
|
|
2022-06-19 10:21:59 +02:00
|
|
|
val schemaTsDistributionName: Provider<String> = providers.provider {
|
2022-05-07 20:22:54 +02:00
|
|
|
"${rootProject.name}-${project.name}"
|
2021-12-02 00:54:15 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-02 10:21:13 +02:00
|
|
|
|
2022-06-26 14:56:53 +02:00
|
|
|
val generateTypeScriptOutputFiles: Provider<FileTree> =
|
|
|
|
|
generateTypeScript.map { it.outputs.files.asFileTree }
|
2022-05-14 12:23:58 +02:00
|
|
|
|
2022-07-02 10:21:13 +02:00
|
|
|
|
2022-07-05 23:44:23 +02:00
|
|
|
//val schemaTs by distributions.registering {
|
|
|
|
|
// distributionBaseName.set(schemaTsDistributionName)
|
|
|
|
|
// contents {
|
|
|
|
|
// from(generateTypeScriptOutputFiles)
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
2021-11-10 17:34:01 +01:00
|
|
|
|
2022-07-05 23:44:23 +02:00
|
|
|
//val schemaTsZipTask: TaskProvider<Zip> = tasks.named<Zip>("${schemaTs.name}DistZip")
|
|
|
|
|
//val schemaTsZipTaskArchiveFile: Provider<RegularFile> = schemaTsZipTask.flatMap { it.archiveFile }
|
2022-07-02 10:21:13 +02:00
|
|
|
|
2022-07-05 23:44:23 +02:00
|
|
|
|
|
|
|
|
val schemaTsZip by tasks.registering(Zip::class) {
|
|
|
|
|
group = "kt2ts"
|
|
|
|
|
|
|
|
|
|
archiveBaseName.set("schema-ts")
|
|
|
|
|
from(generateTypeScriptOutputFiles)
|
|
|
|
|
destinationDirectory.set(layout.buildDirectory.dir("distributions/kt2ts"))
|
|
|
|
|
}
|
|
|
|
|
val schemaTsZipTaskArchiveFile: Provider<RegularFile> = schemaTsZip.flatMap { it.archiveFile }
|
2022-05-07 20:22:54 +02:00
|
|
|
|
2022-07-02 10:21:13 +02:00
|
|
|
|
2022-09-11 00:25:58 +02:00
|
|
|
val typeScriptModelGenerated by configurations.creating<Configuration> {
|
2021-11-27 17:57:50 +01:00
|
|
|
asProvider()
|
|
|
|
|
typescriptAttributes(objects)
|
2021-12-08 17:43:08 +01:00
|
|
|
|
2022-05-14 12:23:58 +02:00
|
|
|
outgoing.artifact(schemaTsZipTaskArchiveFile)
|
2022-07-05 23:44:23 +02:00
|
|
|
// outgoing.artifact(schemaTsZipTaskArchiveFile)
|
2021-11-27 17:57:50 +01:00
|
|
|
}
|