get a shared kotlin-typescript data model working
This commit is contained in:
parent
d6a9a58dc9
commit
0d85bfca60
10 changed files with 173 additions and 178 deletions
|
|
@ -1,120 +1,46 @@
|
|||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||
|
||||
import dev.adamko.factoriowebmap.configurations.asProvider
|
||||
import dev.adamko.factoriowebmap.configurations.typescriptAttributes
|
||||
|
||||
plugins {
|
||||
id("dev.adamko.factoriowebmap.archetype.kotlin-multiplatform")
|
||||
id("dev.adamko.factoriowebmap.archetype.kotlin-jvm")
|
||||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
||||
val projectId: String by project.extra
|
||||
val buildDir: Directory = layout.buildDirectory.dir(projectId).get()
|
||||
|
||||
kotlin {
|
||||
dependencies {
|
||||
val kotlinXSerializationVersion = "1.3.0"
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinXSerializationVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinXSerializationVersion")
|
||||
|
||||
//<editor-fold desc="Java">
|
||||
jvm {
|
||||
compilations.configureEach {
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
apiVersion = "1.6"
|
||||
languageVersion = "1.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
implementation("com.github.ntrrgc:ts-generator:1.1.2")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
implementation("com.github.ntrrgc:ts-generator:1.1.1")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
val generateTypescript by tasks.registering(JavaExec::class) {
|
||||
group = project.name
|
||||
|
||||
val kotlinXSerializationVersion = "1.3.0"
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinXSerializationVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinXSerializationVersion")
|
||||
}
|
||||
}
|
||||
val jvmTest by getting {
|
||||
}
|
||||
}
|
||||
val generatedFileName = "$temporaryDir/data-model.ts"
|
||||
inputs.property("generatedFileName", generatedFileName)
|
||||
outputs.file(generatedFileName)
|
||||
|
||||
//</editor-fold>
|
||||
classpath(sourceSets.main.map { it.runtimeClasspath })
|
||||
mainClass.set("dev.adamko.factorioevents.model.Kt2tsKt")
|
||||
args(generatedFileName)
|
||||
|
||||
//<editor-fold desc="JS">
|
||||
js(IR) {
|
||||
moduleName = "data-model"
|
||||
browser { }
|
||||
binaries.executable()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val jsMain: KotlinSourceSet by getting {
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation(npm("lua-types", "^2.11.0"))
|
||||
implementation(npm("@types/node", "^12.0.8"))
|
||||
implementation(npm("typescript-to-lua", "1.1.1"))
|
||||
implementation(npm("typescript", "4.4.4"))
|
||||
implementation(npm("typed-factorio", "0.11.0-packagetypes-1", false))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val jsTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
sourceSets.all {
|
||||
languageSettings.apply {
|
||||
languageVersion = "1.6"
|
||||
// enableLanguageFeature("InlineClasses") // language feature name
|
||||
optIn("kotlin.OptIn")
|
||||
optIn("kotlin.RequiresOptIn")
|
||||
optIn("kotlin.ExperimentalStdlibApi")
|
||||
optIn("kotlin.time.ExperimentalTime")
|
||||
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
|
||||
optIn("kotlin.js.ExperimentalJsExport")
|
||||
optIn("kotlinx.serialization.ExperimentalSerializationApi")
|
||||
// progressiveMode = true // false by default
|
||||
}
|
||||
doFirst {
|
||||
delete(temporaryDir)
|
||||
mkdir(temporaryDir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
afterEvaluate {
|
||||
|
||||
val kotlinJsCompilation: KotlinJsCompilation =
|
||||
kotlin.targets
|
||||
.flatMap { it.compilations }
|
||||
.filterIsInstance<KotlinJsCompilation>()
|
||||
.first { it.name == KotlinCompilation.MAIN_COMPILATION_NAME }
|
||||
val npmProject = kotlinJsCompilation.npmProject
|
||||
|
||||
tasks.create<Exec>("tstl") {
|
||||
group = project.name
|
||||
|
||||
standardOutput = System.out
|
||||
errorOutput = System.err
|
||||
|
||||
workingDir = npmProject.dir
|
||||
executable = when (npmProject.nodeJs.requireConfigured().isWindows) {
|
||||
true -> "npx.cmd"
|
||||
false -> "npx"
|
||||
}
|
||||
|
||||
args(parseSpaceSeparatedArgs("tstl --out $temporaryDir"))
|
||||
|
||||
}
|
||||
|
||||
val typescriptModelGenerated by configurations.registering {
|
||||
asProvider()
|
||||
typescriptAttributes(objects)
|
||||
outgoing.artifact(
|
||||
generateTypescript.map {
|
||||
it.outputs.files.singleFile
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue