diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 0b83ac0..47649fd 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -82,11 +82,11 @@ tasks.withType().configureEach { kotlinOptions.freeCompilerArgs += listOf( // "-Xcontext-receivers", - "-Xopt-in=kotlin.RequiresOptIn", - "-Xopt-in=kotlin.ExperimentalStdlibApi", - "-Xopt-in=kotlin.time.ExperimentalTime", + "-opt-in=kotlin.RequiresOptIn", + "-opt-in=kotlin.ExperimentalStdlibApi", + "-opt-in=kotlin.time.ExperimentalTime", // "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", - "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi", + "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", ) } diff --git a/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/JsonPropertiesUpToDateSpec.kt b/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/JsonPropertiesUpToDateSpec.kt index 0985fb0..c180df7 100644 --- a/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/JsonPropertiesUpToDateSpec.kt +++ b/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/JsonPropertiesUpToDateSpec.kt @@ -1,8 +1,5 @@ package dev.adamko.kafkatorio.task -import dev.adamko.kafkatorio.jsonMapper -import kotlinx.serialization.json.jsonObject -import kotlinx.serialization.json.jsonPrimitive import org.gradle.api.Task import org.gradle.api.internal.specs.ExplainingSpec @@ -13,34 +10,29 @@ object JsonPropertiesUpToDateSpec : ExplainingSpec { // Returns a description explaining why the task is outdated, // or null if the task is up to date - override fun whyUnsatisfied(element: Task?): String? = with(element) { - when (this) { - null -> "task is null" + override fun whyUnsatisfied(task: Task?): String? { + require(task is UpdatePackageJson) { "$task is not a UpdatePackageJson task" } - !is UpdatePackageJson -> - "task ${this::class.simpleName} is not instance of ${UpdatePackageJson::class.simpleName}" + val current = task.currentPackageJson() + val updated = task.updatedPackageJson(current) - else -> { + return if (current != updated) { + (current.keys + updated.keys) + .asSequence() + .distinct() + .sorted() + .mapNotNull { + val currentVal = current[it] + val updatedVal = updated[it] - val packageJsonContent = packageJsonFile2.get().asFile.readText() - val packageJson = jsonMapper.parseToJsonElement(packageJsonContent).jsonObject - - val outdatedProperties = propertiesToCheck.get().mapNotNull { (key, expectedVal) -> - val actualVal = packageJson[key]?.jsonPrimitive?.content - when { - expectedVal == actualVal -> null - else -> "'$key' (expected: $expectedVal, actual: $actualVal)" + if (currentVal == updatedVal) { + null + } else { + "'$it' - expected:$updatedVal, actual:$currentVal" } - } - - when { - outdatedProperties.isEmpty() -> null - outdatedProperties.size == 1 -> - "package.json has outdated property: ${outdatedProperties.single()}" - else -> - "package.json has outdated properties: ${outdatedProperties.joinToString(", ")}" - } - } + }.joinToString(prefix = "package.json is not up to date. ") + } else { + null } } } diff --git a/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/UpdatePackageJson.kt b/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/UpdatePackageJson.kt index 0c55c92..d4ce73f 100644 --- a/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/UpdatePackageJson.kt +++ b/buildSrc/src/main/kotlin/dev/adamko/kafkatorio/task/UpdatePackageJson.kt @@ -4,8 +4,8 @@ import com.github.gradle.node.NodePlugin import dev.adamko.kafkatorio.jsonMapper import javax.inject.Inject 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 org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty @@ -13,7 +13,6 @@ import org.gradle.api.provider.MapProperty import org.gradle.api.provider.ProviderFactory import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.gradle.kotlin.dsl.support.useToRun @@ -27,9 +26,9 @@ abstract class UpdatePackageJson @Inject constructor( @get:Input abstract val propertiesToCheck: MapProperty -// @get:OutputFile - @get:Internal - abstract val packageJsonFile2: RegularFileProperty + @get:OutputFile + abstract val packageJsonFile: RegularFileProperty + init { group = NodePlugin.NODE_GROUP @@ -37,34 +36,16 @@ abstract class UpdatePackageJson @Inject constructor( "Read the package.json file and update the version and name, based on the project." outputs.upToDateWhen(JsonPropertiesUpToDateSpec) - -// super.doFirst { -// propertiesToCheck.disallowChanges() -// packageJsonFile.disallowChanges() -// } } - init { - outputs.upToDateWhen { task -> - require(task is UpdatePackageJson) { "$task is not a UpdatePackageJson task" } - - val currentPackageJson = task.currentPackageJson() - val updatedPackageJson = task.updatedPackageJson(currentPackageJson) - - val status = currentPackageJson == updatedPackageJson - logger.lifecycle("package.json is ${if (status) "up to date" else "not up to date"}") - status - } - } @TaskAction fun exec() { - val packageJsonFile = packageJsonFile2.asFile.get() + val packageJsonFile = packageJsonFile.asFile.get() logger.lifecycle("updating package.json ${packageJsonFile.canonicalPath}") - val currentPackageJson = currentPackageJson() - val updatedPackageJson = updatedPackageJson(currentPackageJson) + val updatedPackageJson = updatedPackageJson() val packageJsonContentUpdated = jsonMapper @@ -78,14 +59,18 @@ abstract class UpdatePackageJson @Inject constructor( } } - private fun currentPackageJson(): JsonObject { - val packageJsonFile = packageJsonFile2.asFile.get() + internal fun currentPackageJson(): JsonObject { + val packageJsonFile = packageJsonFile.get().asFile return jsonMapper.parseToJsonElement(packageJsonFile.readText()).jsonObject } - private fun updatedPackageJson(currentPackageJson: JsonObject): JsonObject { - val propertiesToCheck = propertiesToCheck.get() - val newJsonProps = propertiesToCheck.mapValues { (_, newVal) -> JsonPrimitive(newVal) } + internal fun updatedPackageJson( + currentPackageJson: JsonObject = currentPackageJson(), + ): JsonObject { + val propertiesToCheck: Map = propertiesToCheck.get() + val newJsonProps = propertiesToCheck.mapValues { (_, newVal) -> + jsonMapper.parseToJsonElement(newVal) + } return JsonObject(currentPackageJson + newJsonProps) } } diff --git a/modules/events-mod/build.gradle.kts b/modules/events-mod/build.gradle.kts index ef92cbd..4277a63 100644 --- a/modules/events-mod/build.gradle.kts +++ b/modules/events-mod/build.gradle.kts @@ -119,6 +119,8 @@ tasks.distZip { val publishMod by tasks.registering(FactorioModPublishTask::class) { + dependsOn(tasks.check) + distributionZip.set(tasks.distZip.flatMap { it.archiveFile }) val projectModName = project.extra.get("modName") as String @@ -156,65 +158,8 @@ distributions { tasks.withType().configureEach { val projectTokensXX = projectTokensX inputs.property("projectTokens", projectTokensXX) -// if (name.startsWith("dist")) { -// notCompatibleWithConfigurationCache("NPE on projectTokens") -// } } -//tasks.npmInstall { -// nodeModulesOutputFilter { -// exclude("**/typed-factorio/generated/classes.d.ts") -// } -//} - -//interface ServiceProvider { -// @get:Inject -// val fs: FileSystemOperations -//} -// -//val fixLink by tasks.registering { -// dependsOn(tasks.npmInstall) -// -// -// val badLink = """{@link https://lua-api.factorio.com/latest/Data-Lifecycle.html Data Lifecycle}""" -// val goodLink = """https://lua-api.factorio.com/latest/Data-Lifecycle.html""" -// -// val typedFactorioDir = -// layout.projectDirectory.dir("src/main/typescript/node_modules/typed-factorio") -// val classesDTS = typedFactorioDir.file("generated/classes.d.ts") -// -// val services = project.objects.newInstance() -// -// inputs.file(classesDTS) -// outputs.file(classesDTS) -// -// inputs.property("badLink", badLink) -// inputs.property("goodLink", goodLink) -// -// doLast { -// logger.lifecycle("fixing link ${classesDTS.asFile.canonicalPath}") -// -// services.fs.sync { -// from(classesDTS) -// into(temporaryDir) -// filter { line -> -// when { -// line.contains(badLink) -> line.replace(badLink, goodLink) -// else -> line -// } -// } -// } -// -// services.fs.copy { -// from(temporaryDir.resolve("classes.d.ts").canonicalPath) -// into(classesDTS.asFile.parent) -// duplicatesStrategy = DuplicatesStrategy.WARN -// } -// } -//} -// -//tasks.assemble { dependsOn(fixLink) } - //val downloadFactorioApiDocs by tasks.registering { // group = project.name @@ -259,7 +204,7 @@ tasks.updatePackageJson { inputs.property("packageJsonName", packageJsonName) propertiesToCheck.put("name", packageJsonName) val pjProvider = layout.projectDirectory.file(provider { "package.json" }) - packageJsonFile2.set(pjProvider) + packageJsonFile.set(pjProvider) } @@ -296,3 +241,20 @@ tasks.assemble { dependsOn(installEventsTsSchema, tasks.updatePackageJson) } // } // } //} + +idea { + module { + sourceDirs = sourceDirs + file("src/main/typescript") + resourceDirs = resourceDirs + file("src/main/resources") + testSourceDirs = testSourceDirs + file("src/test/typescript") + iml { + whenMerged { + require(this is org.gradle.plugins.ide.idea.model.Module) + + sourceDirs = sourceDirs + file("src/main/typescript") + resourceDirs = resourceDirs + file("src/main/resources") + testSourceDirs = testSourceDirs + file("src/test/typescript") + } + } + } +}