properly generate and collect and create source sets for jvm+kt+ts (but kotlin multiplatform js doesn't work????)

todo: clean up this is really messy
This commit is contained in:
Adam 2021-11-02 23:22:30 +01:00
parent 00b3dc3554
commit ac8428f36d
6 changed files with 167 additions and 280 deletions

View file

@ -1,6 +1,6 @@
import dev.adamko.gradle.pbandg.task.ProtobufCompileTask
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask
//import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
//import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask
plugins {
id("dev.adamko.factoriowebmap.archetype.base")
@ -21,31 +21,25 @@ dependencies {
// api("com.google.protobuf:protobuf-kotlin-lite:3.19.1")
}
idea {
workspace {
}
}
kotlin {
sourceSets.all {
languageSettings.apply {
languageVersion = "1.5"
// enableLanguageFeature("InlineClasses") // language feature name
optIn("kotlin.OptIn")
optIn("kotlin.ExperimentalStdlibApi")
optIn("kotlin.time.ExperimentalTime")
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
optIn("kotlin.js.ExperimentalJsExport")
// progressiveMode = true // false by default
}
}
// sourceSets.all {
// languageSettings.apply {
// languageVersion = "1.5"
//// enableLanguageFeature("InlineClasses") // language feature name
// optIn("kotlin.OptIn")
// optIn("kotlin.ExperimentalStdlibApi")
// optIn("kotlin.time.ExperimentalTime")
// optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
// optIn("kotlin.js.ExperimentalJsExport")
//// progressiveMode = true // false by default
// }
// }
//<editor-fold desc="Protobuf">
sourceSets {
val proto by creating {
}
}
// sourceSets {
// val proto by creating {
// }
// }
//</editor-fold>
//<editor-fold desc="Java">
@ -57,6 +51,22 @@ kotlin {
}
}
//</editor-fold>
//<editor-fold desc="JS">
// js(IR) {
// binaries.executable()
//// browser {
////// commonWebpackConfig {
////// cssSupport.enabled = true
////// }
//// }
//
// useCommonJs()
// nodejs()
//
// }
sourceSets {
val jvmMain by getting {
dependencies {
@ -66,74 +76,18 @@ kotlin {
}
val jvmTest by getting {
}
}
//</editor-fold>
//<editor-fold desc="JS">
js(IR) {
binaries.executable()
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
useCommonJs()
nodejs()
compilations["main"].apply {
packageJson {
customField(
"scripts",
mapOf(
"build" to "tstl",
"dev" to "tstl --watch",
)
)
}
}
}
sourceSets {
val jsMain by getting {
kotlin.srcDir("externals02")
// kotlin.srcDir("externals")
dependencies {
val kotlinWrappersVersion = "0.0.1-pre.254-kotlin-1.5.31"
implementation(
project.dependencies.enforcedPlatform(
"org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${kotlinWrappersVersion}"
)
)
// implementation("org.jetbrains.kotlin-wrappers:kotlin-react")
// implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
// implementation(npm("react", "17.0.2"))
// implementation(npm("react-dom", "17.0.2"))
// implementation("org.jetbrains.kotlinx:kotlinx-nodejs:0.0.7") {
// because("https://github.com/Kotlin/kotlinx-nodejs")
// }
// implementation(npm("typescript-to-lua", "1.0.1"))
// implementation(npm("typed-factorio", "0.7.1"))
// implementation(npm("lua-types", "2.11.0"))
// implementation(npm("typescript", "4.4.3"))
implementation(npm("ts-proto", "1.83.3"))
}
}
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
// val jsMain by getting {
// dependencies {
// implementation(npm("ts-proto", "1.83.3"))
// }
// }
//
// val jsTest by getting {
// dependencies {
// implementation(kotlin("test-js"))
// }
// }
}
//</editor-fold>
@ -142,58 +96,56 @@ kotlin {
//rootProject.tasks.withType<RootPackageJsonTask>().configureEach {
//}
val rootPackageJson by rootProject.tasks.getting(RootPackageJsonTask::class)
val nodePath: Directory by extra {
val file = rootPackageJson.rootPackageJson.parentFile.normalize()
logger.lifecycle("Kotlin/JS NODE_PATH: $file")
project.layout.dir(provider { file }).get()
}
val nodeModulesDir: Directory by extra {
val file = nodePath.dir(NpmProject.NODE_MODULES)
logger.lifecycle("Kotlin/JS NODE_MODULES: $file")
file
}
//val rootPackageJson by rootProject.tasks.getting(RootPackageJsonTask::class)
//val nodePath: Directory by extra {
// val file = rootPackageJson.rootPackageJson.parentFile.normalize()
// logger.lifecycle("Kotlin/JS NODE_PATH: $file")
// project.layout.dir(provider { file }).get()
//}
//
//val nodeModulesDir: Directory by extra {
// val file = nodePath.dir(NpmProject.NODE_MODULES)
// logger.lifecycle("Kotlin/JS NODE_MODULES: $file")
// file
//}
// build/js/node_modules/ts-proto/node_modules/.bin
tasks.protobufCompile {
//
tasks.register<ProtobufCompileTask>("protobufJava") {
description = "proto2java"
protoFile.set(layout.projectDirectory.file("src/proto/FactorioServerLogRecord.proto"))
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
cliArgs.add("--java_out=lite:${project.mkdir("$temporaryDir/java").canonicalPath}")
}
tasks.create<ProtobufCompileTask>("protobufKotlin") {
description = "proto2kotlin"
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
cliArgs.add("--kotlin_out=lite:${project.mkdir("$temporaryDir/kotlin").canonicalPath}")
}
tasks.create<ProtobufCompileTask>("protobufTypescript") {
description = "proto2typescript"
// data class PluginTs(
// override val cliParam: String = "--plugin",
// override val protocOptions: String = "",
// override val outputDirectoryName: String =
// "${project.buildDir}/js/packages/factorio-web-map-factorio-events-data-model/node_modules/.bin/protoc-gen-ts_proto.cmd",
// ) : ProtocOutput
//
//
// data class OutputTs(
// override val cliParam: String = "--ts_proto_out",
// override val protocOptions: String = "",
// override val outputDirectoryName: String = "${project.buildDir}/pbAndG/generated-sources/typescript",
// ) : ProtocOutput
//
// protocOutputs.add(PluginTs())
// protocOutputs.add(OutputTs())
// linux:
// cliArgs.add("--plugin=${rootProject.buildDir}/js/packages/factorio-web-map-factorio-events-data-model/node_modules/.bin/protoc-gen-ts_proto.cmd")
// windows:
cliArgs.add("--plugin=protoc-gen-ts_proto=${rootProject.buildDir}/js/packages/factorio-web-map-factorio-events-data-model/node_modules/.bin/protoc-gen-ts_proto.cmd")
val outdir = temporaryDir.resolve("typescript")
val f: File = project.mkdir(outdir)
cliArgs.add("--ts_proto_out=${project.mkdir("$temporaryDir/typescript").canonicalPath}")
cliArgs.add("--ts_proto_out=${outdir.canonicalPath}")
cliArgs.add("--ts_proto_opt=useOptionals=true")
// cliArgs.add("--proto_path=${rootProject.rootDir}")
cliArgs.addAll(
"--ts_proto_opt=useOptionals=true",
"--ts_proto_opt=outputServices=false",
"--ts_proto_opt=outputJsonMethods=false",
"--ts_proto_opt=outputEncodeMethods=false",
"--ts_proto_opt=forceLong=string",
"--ts_proto_opt=forceLong=number",
"--ts_proto_opt=esModuleInterop=true",
"--ts_proto_opt=exportCommonSymbols=false",
// "--proto_path=${rootProject.rootDir}",
)
protoFile.set(layout.projectDirectory.file("src/proto/FactorioServerLogRecord.proto"))
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
}

View file

@ -5,8 +5,8 @@ option java_multiple_files = true;
package dev.adamko.factorioevents;
import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
//import "google/protobuf/any.proto";
//import "google/protobuf/timestamp.proto";
message FactorioServerLogRecord {
string mod_version = 1;
@ -54,7 +54,7 @@ message LuaPlayer {
// https://lua-api.factorio.com/next/LuaEntity.html
message LuaEntity {
uint32 unit_number = 1; // (optional) unique ID
optional uint32 unit_number = 1; // (optional) unique ID
string name = 2;
string type = 3;
string status = 4; // https://lua-api.factorio.com/next/defines.html#defines.entity_status
@ -62,8 +62,8 @@ message LuaEntity {
bool is_active = 8;
bool is_moving = 9;
uint32 player_index = 50; // (optional) The player connected to this character or nil if none.
uint32 last_user_index = 51; // (optional) The last player that changed any setting on this entity.
optional uint32 player_index = 50; // (optional) The player connected to this character or nil if none.
optional uint32 last_user_index = 51; // (optional) The last player that changed any setting on this entity.
Colour colour = 100; // (optional)
}