factorio -> event -> mod -> console -> kafka pipe -> kafka -> event processor working!!!!!!!!!!!!!!!!!!
This commit is contained in:
parent
7091f7648d
commit
42b60ac0c3
19 changed files with 152 additions and 87 deletions
9
buildSrc/src/main/kotlin/dev/adamko/kafkatorio/common.kt
Normal file
9
buildSrc/src/main/kotlin/dev/adamko/kafkatorio/common.kt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package dev.adamko.kafkatorio
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
|
||||
val jsonMapper = Json {
|
||||
prettyPrint = true
|
||||
prettyPrintIndent = " "
|
||||
}
|
||||
|
|
@ -1,8 +1,13 @@
|
|||
package dev.adamko.kafkatorio.gradle
|
||||
|
||||
import dev.adamko.kafkatorio.jsonMapper
|
||||
import java.io.ByteArrayOutputStream
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.specs.Spec
|
||||
import org.gradle.kotlin.dsl.invoke
|
||||
|
||||
|
|
@ -12,10 +17,28 @@ fun Project.isProcessRunning(process: String, ignoreCase: Boolean = true): Spec<
|
|||
Spec<Task> {
|
||||
ByteArrayOutputStream().use { outputStream ->
|
||||
project.exec {
|
||||
commandLine("tasklist")
|
||||
commandLine("tasklist") // Windows only for now...
|
||||
standardOutput = outputStream
|
||||
}
|
||||
outputStream.toString()
|
||||
.contains(process, ignoreCase)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.areJsonPropertiesUpToDate(
|
||||
packageJsonFile: RegularFileProperty,
|
||||
properties: () -> Map<String, String>
|
||||
): Spec<Task> = Spec<Task> {
|
||||
val packageJsonContent = packageJsonFile.get().asFile.readText()
|
||||
val packageJson = jsonMapper.parseToJsonElement(packageJsonContent).jsonObject
|
||||
|
||||
properties().all { (key, expectedVal) ->
|
||||
val actualVal = packageJson[key]?.jsonPrimitive?.content
|
||||
(expectedVal == actualVal).also {
|
||||
logger.log(
|
||||
if (it) LogLevel.LIFECYCLE else LogLevel.INFO,
|
||||
"package.json has outdated property '$key' (expected: $expectedVal, actual: $actualVal)"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
package dev.adamko.kafkatorio.lang
|
||||
|
||||
import com.github.gradle.node.NodePlugin
|
||||
import dev.adamko.kafkatorio.task.UpdatePackageJson
|
||||
import dev.adamko.kafkatorio.gradle.areJsonPropertiesUpToDate
|
||||
import dev.adamko.kafkatorio.gradle.not
|
||||
import dev.adamko.kafkatorio.jsonMapper
|
||||
import dev.adamko.kafkatorio.task.UpdatePackageJson
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import org.gradle.kotlin.dsl.support.useToRun
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlugin
|
||||
import org.jetbrains.kotlin.util.suffixIfNot
|
||||
|
||||
|
||||
plugins {
|
||||
id("com.github.node-gradle.node")
|
||||
id("dev.adamko.kafkatorio.base")
|
||||
|
|
@ -27,32 +24,6 @@ node {
|
|||
distBaseUrl.set(null as String?) // set by dependencyResolutionManagement
|
||||
}
|
||||
|
||||
project.plugins.withType<KotlinJsPlugin>()
|
||||
project.plugins.withType<KotlinMultiplatformPlugin>()
|
||||
|
||||
|
||||
val jsonMapper = Json {
|
||||
prettyPrint = true
|
||||
prettyPrintIndent = " "
|
||||
}
|
||||
|
||||
|
||||
fun arePropertiesUpToDate(
|
||||
packageJsonFile: RegularFileProperty,
|
||||
properties: () -> Map<String, String>
|
||||
): Spec<Task> = Spec<Task> {
|
||||
val packageJsonContent = packageJsonFile.get().asFile.readText()
|
||||
val packageJson = jsonMapper.parseToJsonElement(packageJsonContent).jsonObject
|
||||
|
||||
properties().all { (key, expectedVal) ->
|
||||
val actualVal = packageJson[key]?.jsonPrimitive?.content
|
||||
(expectedVal == actualVal).also {
|
||||
if (!it)
|
||||
logger.lifecycle("package.json has outdated property '$key' (expected: $expectedVal, actual: $actualVal)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val updatePackageJson by tasks.registering(UpdatePackageJson::class) {
|
||||
group = NodePlugin.NODE_GROUP
|
||||
description = "Read the package.json file and update the version and name, based on the project."
|
||||
|
|
@ -60,7 +31,7 @@ val updatePackageJson by tasks.registering(UpdatePackageJson::class) {
|
|||
propertiesToCheck["version"] = "${project.version}"
|
||||
|
||||
// check to see if the properties are already up-to-date
|
||||
onlyIf(!arePropertiesUpToDate(packageJsonFile) { propertiesToCheck })
|
||||
onlyIf(!areJsonPropertiesUpToDate(packageJsonFile) { propertiesToCheck })
|
||||
|
||||
doLast {
|
||||
val packageJsonContent = packageJsonFile.get().asFile.readText()
|
||||
|
|
@ -74,7 +45,7 @@ val updatePackageJson by tasks.registering(UpdatePackageJson::class) {
|
|||
.encodeToString(packageJsonUpdate)
|
||||
.suffixIfNot("\n")
|
||||
|
||||
logger.lifecycle(packageJsonContentUpdated)
|
||||
logger.debug(packageJsonContentUpdated)
|
||||
|
||||
packageJsonFile.get().asFile.writer().useToRun {
|
||||
write(packageJsonContentUpdated)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue