tidying up after refactor, fix update-package-json task, try to fix factorio-client launcher
This commit is contained in:
parent
8c75b47a96
commit
afbfeda616
7 changed files with 37 additions and 31 deletions
|
|
@ -1,4 +1,4 @@
|
|||
package dev.adamko
|
||||
package dev.adamko.kafkatorio.gradle
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import org.gradle.api.Project
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ package dev.adamko.kafkatorio.lang
|
|||
|
||||
import com.github.gradle.node.NodePlugin
|
||||
import dev.adamko.kafkatorio.task.UpdatePackageJson
|
||||
import dev.adamko.kafkatorio.gradle.not
|
||||
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.registering
|
||||
import org.gradle.kotlin.dsl.support.useToRun
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
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")
|
||||
|
|
@ -37,38 +37,33 @@ val jsonMapper = Json {
|
|||
}
|
||||
|
||||
|
||||
val packageJsonFile: RegularFile = layout.projectDirectory.file("src/main/typescript/package.json")
|
||||
fun arePropertiesUpToDate(
|
||||
packageJsonFile: RegularFileProperty,
|
||||
properties: () -> Map<String, String>
|
||||
): Spec<Task> = Spec<Task> {
|
||||
val packageJsonContent = packageJsonFile.get().asFile.readText()
|
||||
val packageJson = jsonMapper.parseToJsonElement(packageJsonContent).jsonObject
|
||||
|
||||
fun arePropertiesUpToDate(properties: () -> Map<String, String>): Spec<Task> =
|
||||
Spec<Task> {
|
||||
val packageJsonContent = packageJsonFile.asFile.readText()
|
||||
val packageJson = jsonMapper.parseToJsonElement(packageJsonContent).jsonObject
|
||||
|
||||
properties().all { (key, expectedVal) ->
|
||||
val actualVal = packageJson[key]?.jsonPrimitive?.content
|
||||
val isUpToDate = expectedVal == actualVal
|
||||
if (!isUpToDate) {
|
||||
logger.lifecycle("package.json has outdated property $key=$actualVal (expected: $expectedVal)")
|
||||
}
|
||||
isUpToDate
|
||||
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
|
||||
|
||||
group = project.name
|
||||
description = "Read the package.json file and update the version and name, based on the project."
|
||||
|
||||
propertiesToCheck["version"] = "${project.version}"
|
||||
|
||||
outputs.file(packageJsonFile)
|
||||
|
||||
// check to see if the properties are already up-to-date
|
||||
onlyIf(arePropertiesUpToDate { propertiesToCheck })
|
||||
onlyIf(!arePropertiesUpToDate(packageJsonFile) { propertiesToCheck })
|
||||
|
||||
doLast {
|
||||
val packageJsonContent = packageJsonFile.asFile.readText()
|
||||
val packageJsonContent = packageJsonFile.get().asFile.readText()
|
||||
val packageJson = jsonMapper.parseToJsonElement(packageJsonContent).jsonObject
|
||||
|
||||
val newJsonProps = propertiesToCheck.mapValues { (_, newVal) -> JsonPrimitive(newVal) }
|
||||
|
|
@ -79,7 +74,9 @@ val updatePackageJson by tasks.registering(UpdatePackageJson::class) {
|
|||
.encodeToString(packageJsonUpdate)
|
||||
.suffixIfNot("\n")
|
||||
|
||||
packageJsonFile.asFile.writer().useToRun {
|
||||
logger.lifecycle(packageJsonContentUpdated)
|
||||
|
||||
packageJsonFile.get().asFile.writer().useToRun {
|
||||
write(packageJsonContentUpdated)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
package dev.adamko.kafkatorio.task
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
|
||||
abstract class UpdatePackageJson : DefaultTask() {
|
||||
@get:Input
|
||||
val propertiesToCheck: MutableMap<String, String> = mutableMapOf()
|
||||
@get:OutputFile
|
||||
abstract val packageJsonFile: RegularFileProperty
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ val factorioModProvider by configurations.registering {
|
|||
|
||||
tasks.updatePackageJson {
|
||||
propertiesToCheck["name"] = "${rootProject.name}-${project.name}"
|
||||
packageJsonFile.set(layout.projectDirectory.file("src/main/typescript/package.json"))
|
||||
}
|
||||
|
||||
tasks.assemble { dependsOn(fetchEventsSchema, tasks.updatePackageJson) }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "kafkatorio-events",
|
||||
"name": "kafkatorio-events-mod",
|
||||
"version": "0.0.7",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
|
@ -9,7 +9,8 @@
|
|||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"devDependencies": {
|
||||
},
|
||||
"dependencies": {
|
||||
"lua-types": "^2.11.0",
|
||||
"@types/node": "^12.0.8",
|
||||
|
|
@ -20,7 +21,10 @@
|
|||
"//": {
|
||||
"typed-factorio": "0.10.0"
|
||||
},
|
||||
"peerDependencies": {},
|
||||
"optionalDependencies": {},
|
||||
"bundledDependencies": []
|
||||
"peerDependencies": {
|
||||
},
|
||||
"optionalDependencies": {
|
||||
},
|
||||
"bundledDependencies": [
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import dev.adamko.kafkatorio.gradle.asConsumer
|
||||
import dev.adamko.kafkatorio.gradle.factorioModAttributes
|
||||
import dev.adamko.isProcessRunning
|
||||
import dev.adamko.not
|
||||
import dev.adamko.kafkatorio.gradle.isProcessRunning
|
||||
import dev.adamko.kafkatorio.gradle.not
|
||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||
|
||||
plugins {
|
||||
|
|
@ -52,7 +52,7 @@ val clientLaunch by tasks.registering(Exec::class) {
|
|||
commandLine = parseSpaceSeparatedArgs(
|
||||
// """explorer "steam://rungameid/$factorioGameId// --mp-connect localhost/" """ // not working
|
||||
// """explorer "steam://run/$factorioGameId//--mp-connect localhost/" """ // works! But has annoying pop-up
|
||||
""" $steamExe -applaunch $factorioGameId --mp-connect localhost """
|
||||
""" $steamExe -applaunch $factorioGameId --mp-connect localhost --mod-directory $clientModsDirectory """
|
||||
)
|
||||
doFirst { logger.lifecycle("Launching factorio.exe") }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue