Kafkatorio/modules/events-mod/build.gradle.kts

316 lines
9.2 KiB
Text
Raw Normal View History

import dev.adamko.gradle.factorio.mod_portal.FactorioModPublishTask
import dev.adamko.gradle.factorio.typescriptAttributes
import kafkatorio.tasks.TypeScriptToLuaTask
import kotlinx.serialization.json.put
import kotlinx.serialization.json.putJsonObject
2021-12-01 16:57:46 +01:00
plugins {
id("kafkatorio.conventions.lang.node")
id("dev.adamko.factorio-mod")
distribution
idea
2021-12-01 16:57:46 +01:00
}
2022-05-07 20:22:54 +02:00
description = "Sends in-game information to a server over the internet (requires additional setup)"
factorioMod {
modName.set("kafkatorio-events")
modTitle.set("Kafkatorio Events")
modAuthor.set("adam@adamko.dev")
factorioCompatibility.set(libs.versions.factorio.map { it.substringBeforeLast(".") })
}
// Factorio required format is:
// - filename: `mod-name_version.zip`
// - zip contains one directory, `mod-name`
//val modName: String by extra { "${rootProject.name}-events" }
//extra.set("modName", "kafkatorio-events")
//val modName = extra.get("modName") as String
//val modDescription: String by project.extra { project.description ?: "" }
// version of Factorio that the mod is compatible with (must only be "major.minor" - patch causes error)
//val modFactorioCompatibility: Provider<String> =
// libs.versions.factorio.map { SemVer.parse(it).run { "$major.$minor" } }
2021-12-01 16:57:46 +01:00
//rootProject.layout.projectDirectory.file("LICENSE")
val licenseFile: RegularFile by rootProject.extra
@Suppress("UNCHECKED_CAST")
val projectTokens: MapProperty<String, String> =
rootProject.extra.get("projectTokens") as? MapProperty<String, String>
?: error("error getting projectTokens")
//val projectTokens: MapProperty<String, String> by rootProject.extra
val projectTokensX1 = projectTokens.apply {
put("mod.name", factorioMod.modName)
put("mod.title", factorioMod.modTitle)
put("mod.description", factorioMod.modDescription)
put("factorio.version", factorioMod.factorioCompatibility)
}
//val tsSrcDir: Directory = layout.projectDirectory.dir("src/main/typescript")
2021-12-01 16:57:46 +01:00
2021-12-01 16:57:46 +01:00
node {
nodeProjectDir.set(layout.projectDirectory)
2021-12-01 16:57:46 +01:00
}
2022-05-07 20:22:54 +02:00
val typescriptEventsSchema: Configuration by configurations.creating {
description = "Fetch the TypeScript schema from the event-schema subproject"
2021-12-01 16:57:46 +01:00
asConsumer()
typescriptAttributes(objects)
}
dependencies {
typescriptEventsSchema(projects.modules.eventsLibrary)
2021-12-01 16:57:46 +01:00
}
val typescriptToLua by tasks.registering(TypeScriptToLuaTask::class) {
dependsOn(
tasks.npmInstall,
installEventsTsSchema,
tasks.updatePackageJson,
)
2021-12-01 16:57:46 +01:00
inputs.file(tasks.updatePackageJson.map { it.packageJsonFile })
sourceFiles.from(factorioMod.mainSources.typescript.sourceDirectories)
outputDirectory.set(factorioMod.mainSources.typescript.destinationDirectory)
2021-12-01 16:57:46 +01:00
}
2021-12-08 17:43:08 +01:00
val installEventsTsSchema by tasks.registering(Sync::class) {
description = "Fetch the latest shared TypeScript data-model"
group = project.name
2021-12-01 16:57:46 +01:00
2021-12-01 18:12:34 +01:00
dependsOn(typescriptEventsSchema)
2021-12-01 16:57:46 +01:00
from(
2021-12-08 17:43:08 +01:00
provider { typescriptEventsSchema }
.map { eventsSchema ->
eventsSchema.incoming
.artifactView { lenient(true) }
.artifacts
.artifactFiles
.filter { file -> file.exists() }
.map { zipTree(it) }
}
) {
// drop the first directory inside the zip
// eachFile { relativePath = dropDirectory() }
includeEmptyDirs = false
}
into(layout.projectDirectory.dir("src/main/typescript/generated"))
2021-12-01 16:57:46 +01:00
}
//val zipNameProvider = provider { distributionZipName }
2022-05-01 23:40:41 +02:00
tasks.distZip {
// val projectTokensXX22 = projectTokensX1
// inputs.property("zipNameProvider", zipNameProvider)
// inputs.property("projectTokens", projectTokensXX22)
val distributionZipName = factorioMod.distributionZipName
archiveFileName.set(distributionZipName)
}
2021-12-01 16:57:46 +01:00
2022-06-26 15:45:59 +02:00
val publishModToPortal by tasks.registering(FactorioModPublishTask::class) {
dependsOn(tasks.check)
distributionZip.set(tasks.distZip.flatMap { it.archiveFile })
// val projectModName = project.extra.get("modName") as String
modName.set(factorioMod.modName)
modVersion.set(factorioMod.modVersion)
// modVersion.set(project.version.toString())
}
tasks.assembleFactorioModContents {
modFiles.apply {
from(typescriptToLua.map { it.outputDirectory })
from(licenseFile)
2021-12-01 16:57:46 +01:00
}
}
2022-05-07 23:03:19 +02:00
//distributions {
// main {
//
//// distributionBaseName.set(factorioMod.modName)
// val tokens333: MutableMap<String, String> = projectTokensX1.get()
//
// contents {
//// from(factorioMod.mainSources.resources) {
//// include("**/**")
//// }
// from(licenseFile)
// from(typescriptToLua.map { it.outputDirectory })
// filesNotMatching("**/*.png") {
// // maybe make a bug report for projectTokensX1 causing null$null$null error?
// // val tokens333: MutableMap<String, String> = projectTokensX1.get()
// filter<ReplaceTokens>("tokens" to tokens333)
// }
//// includeEmptyDirs = false
//// exclude {
//// // exclude empty files
//// it.file.run {
//// isFile && useLines { lines -> lines.all { line -> line.isBlank() } }
//// }
//// }
// }
// }
//}
2022-05-07 23:03:19 +02:00
tasks.withType<Zip>().configureEach {
val projectTokensXX444 = projectTokensX1
inputs.property("projectTokens", projectTokensXX444)
2022-05-07 23:03:19 +02:00
}
//val factorioModProvider by configurations.registering {
// asProvider()
// factorioModAttributes(objects)
// outgoing.artifact(tasks.distZip.flatMap { it.archiveFile })
//}
2021-12-01 16:57:46 +01:00
val projectPackageJsonName: Provider<String> =
providers.provider { "${rootProject.name}-${project.name}" }
val projectPackageJsonFile: RegularFile = layout.projectDirectory.file("package.json")
val projectVersion: Provider<String> = providers.provider { "${project.version}" }
2022-05-07 20:22:54 +02:00
2021-12-01 18:12:34 +01:00
tasks.updatePackageJson {
// mustRunAfter(tasks.npmInstall)
updateExpectedJson {
put("name", projectPackageJsonName.get())
putJsonObject("dependencies") {
put("lua-types", libs.versions.npm.luaTypes.get())
put("typescript-to-lua", libs.versions.npm.typescriptToLua.get())
put("typed-factorio", libs.versions.npm.typedFactorio.get())
put("typescript", libs.versions.npm.typescript.get())
}
}
packageJsonFile.set(projectPackageJsonFile)
2021-12-01 18:12:34 +01:00
}
2021-12-01 16:57:46 +01:00
2021-12-08 17:43:08 +01:00
tasks.assemble { dependsOn(installEventsTsSchema, tasks.updatePackageJson) }
2021-12-01 16:57:46 +01:00
//val typescriptSrcDir: File = file("src/main/typescript")
//val luaSrcDir: File = file("src/generated/lua")
//val resourcesDir: File = file("src/main/resources")
//val typescriptTestSrcDir: File = file("src/test/typescript")
//val generatedSrcDir: File = file("src/generated")
//
//
//idea {
// module {
// sourceDirs.plusAssign(
// listOf(
// typescriptSrcDir,
// luaSrcDir,
// )
// )
//// sourceDirs = sourceDirs + file("src/main/lua")
// resourceDirs = resourceDirs + resourcesDir
// testSources.from(typescriptTestSrcDir)
//// testSourceDirs = testSourceDirs + typescriptTestSrcDir
//
// generatedSourceDirs = generatedSourceDirs + generatedSrcDir
//// excludeDirs = excludeDirs + generatedSrcDir
//
// iml {
// whenMerged {
// require(this is IdeaImlModule)
//
// sourceDirs.plusAssign(
// listOf(
// typescriptSrcDir,
// luaSrcDir,
// )
// )
//
// generatedSourceFolders.plusAssign(
// IdeaImlPath(luaSrcDir.toURI().toString())
// )
// resourceDirs = resourceDirs + resourcesDir
// testSources.from(typescriptTestSrcDir)
//// testSourceDirs = testSourceDirs + typescriptTestSrcDir
//// excludeDirs = excludeDirs + generatedSrcDir
// }
// }
// }
//}
// trying to get Gradle+idea to recognise the ts-src...
//val typescriptSrcSet = project.objects.sourceDirectorySet("typescript", "TypeScript").apply {
// srcDirs(tsSrcDir)
// compiledBy(typescriptToLua, TypescriptToLuaTask::outputDirectory)
//// destinationDirectory.set(layout.buildDirectory.dir("typescriptToLua"))
2021-12-01 16:57:46 +01:00
//}
//
//val tsSrcConfiguration by configurations.registering {
// asProvider()
// outgoing.artifact(tsSrcDir)
//}
2021-12-01 16:57:46 +01:00
//
//idea {
// module {
// // Not using += due to https://github.com/gradle/gradle/issues/8749
// sourceDirs = sourceDirs + typescriptSrcSet.sourceDirectories
// resourceDirs.add(file("src/main/resources"))
// excludeDirs.add(layout.projectDirectory.dir("src/main/typescript/node_modules").asFile)
// scopes.compute("MAIN") { _: String, scope: MutableMap<String, MutableCollection<Configuration>>? ->
// val s = (scope ?: mutableMapOf())
// s.compute("plus") { _, conf ->
// val c = conf ?: mutableListOf()
// c.add(tsSrcConfiguration.get())
// c
2021-12-01 16:57:46 +01:00
// }
// s
2021-12-01 16:57:46 +01:00
// }
// }
//}
//val downloadFactorioApiDocs by tasks.registering {
// group = project.name
//
// val target = uri("https://lua-api.factorio.com/latest/runtime-api.json")
// val apiFilename = File(target.path).name
// val downloadedFile = file("$temporaryDir/$apiFilename")
//
// val apiFile = layout.buildDirectory.file(apiFilename)
// outputs.file(apiFile)
//
// doLast {
//
// ant.invokeMethod(
// "get", mapOf(
// "src" to target,
// "dest" to downloadedFile,
// "verbose" to true,
// )
// )
//
// val json = downloadedFile.readText()
// val prettyJson = JsonOutput.prettyPrint(json)
//
// apiFile.get().asFile.writeText(prettyJson)
//
// logger.lifecycle("Downloaded Factorio API json: $apiFile")
// }
//}