move schema to kotlin-multiplatform
This commit is contained in:
parent
6d60428ab9
commit
1f88d6f464
11 changed files with 118 additions and 46 deletions
|
|
@ -2,29 +2,83 @@ import dev.adamko.kafkatorio.gradle.asProvider
|
|||
import dev.adamko.kafkatorio.gradle.typescriptAttributes
|
||||
|
||||
plugins {
|
||||
id("dev.adamko.kafkatorio.lang.kotlin-jvm")
|
||||
kotlin("multiplatform")
|
||||
kotlin("plugin.serialization")
|
||||
distribution
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(libs.kotlinx.serialization.bom))
|
||||
implementation(libs.kotlinx.serialization.core)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
kotlin {
|
||||
js(IR) {
|
||||
binaries.executable()
|
||||
nodejs()
|
||||
}
|
||||
jvm()
|
||||
|
||||
implementation("com.github.ntrrgc:ts-generator:1.1.2")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
@Suppress("UnstableApiUsage") // enforcedPlatform is incubating
|
||||
sourceSets {
|
||||
|
||||
testImplementation(libs.kotest.datatest)
|
||||
all {
|
||||
languageSettings.apply {
|
||||
optIn("kotlin.RequiresOptIn")
|
||||
optIn("kotlin.ExperimentalStdlibApi")
|
||||
optIn("kotlin.time.ExperimentalTime")
|
||||
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
|
||||
optIn("kotlinx.serialization.ExperimentalSerializationApi")
|
||||
}
|
||||
}
|
||||
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(project.dependencies.enforcedPlatform(libs.kotlin.bom))
|
||||
|
||||
implementation(project.dependencies.enforcedPlatform(libs.kotlinx.serialization.bom))
|
||||
implementation(libs.kotlinx.serialization.core)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
|
||||
implementation(kotlin("test"))
|
||||
|
||||
implementation(project.dependencies.enforcedPlatform(libs.kotest.bom))
|
||||
implementation("io.kotest:kotest-assertions-core")
|
||||
implementation("io.kotest:kotest-property")
|
||||
implementation("io.kotest:kotest-assertions-json")
|
||||
}
|
||||
}
|
||||
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
implementation("com.github.ntrrgc:ts-generator:1.1.2")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
}
|
||||
}
|
||||
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation("io.kotest:kotest-runner-junit5")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val generateTypescript by tasks.registering(JavaExec::class) {
|
||||
group = project.name
|
||||
|
||||
val generatedFile = file("$temporaryDir/${project.name}.ts")
|
||||
val jvmJar by tasks.getting(Jar::class)
|
||||
val main by kotlin.jvm().compilations.getting
|
||||
classpath(
|
||||
jvmJar,
|
||||
main.runtimeDependencyFiles
|
||||
)
|
||||
|
||||
classpath(sourceSets.main.map { it.runtimeClasspath })
|
||||
mainClass.set("dev.adamko.kafkatorio.events.schema.Kt2tsKt")
|
||||
|
||||
val generatedFile = file("$temporaryDir/${project.name}.ts")
|
||||
args(generatedFile)
|
||||
|
||||
val buildOutput = layout.buildDirectory.dir("generated/typescript")
|
||||
|
|
@ -36,21 +90,25 @@ val generateTypescript by tasks.registering(JavaExec::class) {
|
|||
}
|
||||
|
||||
doLast {
|
||||
sync { from(temporaryDir); into(buildOutput) }
|
||||
}
|
||||
}
|
||||
|
||||
distributions {
|
||||
main {
|
||||
distributionBaseName.set("${rootProject.name}-${project.name}")
|
||||
contents {
|
||||
from(generateTypescript.map { it.outputs.files.asFileTree })
|
||||
sync {
|
||||
from(temporaryDir)
|
||||
into(buildOutput)
|
||||
include("**/*.ts")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val typescriptModelGenerated by configurations.registering {
|
||||
val schemaTs by distributions.registering {
|
||||
distributionBaseName.set("${rootProject.name}-${project.name}")
|
||||
contents {
|
||||
from(generateTypescript.map { it.outputs.files.asFileTree })
|
||||
}
|
||||
}
|
||||
|
||||
val typescriptModelGenerated : Configuration by configurations.creating {
|
||||
asProvider()
|
||||
typescriptAttributes(objects)
|
||||
outgoing.artifact(tasks.distZip.flatMap { it.archiveFile })
|
||||
|
||||
val schemaTsZipTask = tasks.named<Zip>("${schemaTs.name}DistZip")
|
||||
outgoing.artifact(schemaTsZipTask.flatMap { it.archiveFile })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
package dev.adamko.kafkatorio.events.schema
|
||||
|
||||
|
||||
import kotlin.jvm.JvmInline
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.adamko.kafkatorio.events.schema
|
||||
|
||||
|
||||
import kotlin.reflect.full.starProjectedType
|
||||
//import kotlin.reflect.full.starProjectedType
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonClassDiscriminator
|
||||
|
|
@ -35,8 +35,12 @@ const val FactorioObjectDataDiscriminatorKey: String = "object_name"
|
|||
sealed class FactorioObjectData {
|
||||
|
||||
// workaround - https://github.com/Kotlin/kotlinx.serialization/issues/1664
|
||||
// val objectName: String by lazy {
|
||||
// kotlinx.serialization.serializer(this::class.starProjectedType).descriptor.serialName
|
||||
// }
|
||||
val objectName: String by lazy {
|
||||
kotlinx.serialization.serializer(this::class.starProjectedType).descriptor.serialName
|
||||
serializer().descriptor.serialName
|
||||
// kotlinx.serialization.serializer(this::class.starProjectedType).descriptor.serialName
|
||||
}
|
||||
|
||||
// alternative: find the @SerialName annotation
|
||||
Loading…
Add table
Add a link
Reference in a new issue