2021-12-01 18:12:34 +01:00
|
|
|
import dev.adamko.kafkatorio.gradle.asConsumer
|
|
|
|
|
import dev.adamko.kafkatorio.gradle.asProvider
|
2022-05-07 20:22:54 +02:00
|
|
|
import dev.adamko.kafkatorio.gradle.dropDirectories
|
2021-12-01 18:12:34 +01:00
|
|
|
import dev.adamko.kafkatorio.gradle.factorioModAttributes
|
|
|
|
|
import dev.adamko.kafkatorio.gradle.typescriptAttributes
|
2022-02-20 12:23:29 +01:00
|
|
|
import dev.adamko.kafkatorio.task.TypescriptToLuaTask
|
2021-12-08 21:15:16 +01:00
|
|
|
import net.swiftzer.semver.SemVer
|
2021-12-08 21:51:52 +01:00
|
|
|
import org.apache.tools.ant.filters.ReplaceTokens
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
plugins {
|
2022-01-08 13:11:51 +01:00
|
|
|
dev.adamko.kafkatorio.lang.node
|
2021-12-02 00:54:15 +01:00
|
|
|
distribution
|
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)"
|
2021-12-02 00:54:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Factorio required format is:
|
|
|
|
|
// - filename: `mod-name_version.zip`
|
|
|
|
|
// - zip contains one directory, `mod-name`
|
2022-05-07 20:22:54 +02:00
|
|
|
|
2022-05-15 13:08:36 +02:00
|
|
|
|
|
|
|
|
//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 ?: "" }
|
|
|
|
|
|
2022-05-07 20:22:54 +02:00
|
|
|
val distributionZipName: String by extra { "${modName}_${rootProject.version}.zip" }
|
2021-12-02 00:54:15 +01:00
|
|
|
|
2021-12-06 22:15:26 +01:00
|
|
|
// version of Factorio that the mod is compatible with (must only be "major.minor" - patch causes error)
|
2022-05-01 15:46:20 +02:00
|
|
|
val modFactorioCompatibility: Provider<String> =
|
|
|
|
|
libs.versions.factorio.map { SemVer.parse(it).run { "$major.$minor" } }
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2021-12-06 22:15:26 +01:00
|
|
|
val licenseFile: RegularFile by rootProject.extra
|
2022-05-15 13:08:36 +02:00
|
|
|
|
|
|
|
|
@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 projectTokensX = projectTokens.apply {
|
2022-05-01 15:46:20 +02:00
|
|
|
put("mod.name", modName)
|
|
|
|
|
put("mod.title", "Kafkatorio Events")
|
2022-05-07 20:22:54 +02:00
|
|
|
put("mod.description", modDescription)
|
2022-05-15 13:08:36 +02:00
|
|
|
put("factorio.version", modFactorioCompatibility.get())
|
2022-05-01 15:46:20 +02:00
|
|
|
}
|
2021-12-02 00:54:15 +01:00
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
val tsSrcDir: Directory = layout.projectDirectory.dir("src/main/typescript")
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
node {
|
|
|
|
|
nodeProjectDir.set(tsSrcDir)
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-07 20:22:54 +02:00
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
val typescriptEventsSchema: Configuration by configurations.creating {
|
2022-02-20 12:23:29 +01:00
|
|
|
description = "Fetch the TypeScript schema from the event-schema subproject"
|
2021-12-01 16:57:46 +01:00
|
|
|
asConsumer()
|
|
|
|
|
typescriptAttributes(objects)
|
2021-12-02 00:54:15 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
dependencies {
|
|
|
|
|
typescriptEventsSchema(projects.modules.eventsSchema)
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2022-02-20 12:23:29 +01:00
|
|
|
val typescriptToLua by tasks.registering(TypescriptToLuaTask::class) {
|
2022-01-08 13:11:51 +01:00
|
|
|
dependsOn(tasks.npmInstall, installEventsTsSchema, tasks.updatePackageJson)
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-02-20 12:23:29 +01:00
|
|
|
sourceFiles.set(tsSrcDir)
|
|
|
|
|
outputDirectory.set(layout.buildDirectory.dir("typescriptToLua"))
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2021-12-08 17:43:08 +01:00
|
|
|
val installEventsTsSchema by tasks.registering(Sync::class) {
|
2021-12-01 16:57:46 +01:00
|
|
|
description = "Fetch the latest shared data-model"
|
2021-12-02 00:54:15 +01:00
|
|
|
group = project.name
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2021-12-01 18:12:34 +01:00
|
|
|
dependsOn(typescriptEventsSchema)
|
2022-05-14 17:59:50 +02:00
|
|
|
dependsOn(fixLink)
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-01-08 13:14:32 +01:00
|
|
|
val outputDir = layout.projectDirectory.dir("src/main/typescript/generated/kafkatorio-schema")
|
2021-12-08 17:43:08 +01:00
|
|
|
outputs.dir(outputDir)
|
|
|
|
|
|
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) }
|
|
|
|
|
}
|
2021-12-02 00:54:15 +01:00
|
|
|
) {
|
|
|
|
|
// drop the first directory inside the zip
|
2022-05-07 20:22:54 +02:00
|
|
|
eachFile { relativePath = dropDirectories() }
|
2021-12-02 00:54:15 +01:00
|
|
|
includeEmptyDirs = false
|
|
|
|
|
}
|
2021-12-08 17:43:08 +01:00
|
|
|
into(outputDir)
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2022-05-01 23:40:41 +02:00
|
|
|
val zipNameProvider = provider { distributionZipName }
|
|
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
tasks.distZip {
|
2022-05-15 13:08:36 +02:00
|
|
|
val projectTokensXX = projectTokensX
|
|
|
|
|
|
2022-05-01 15:46:20 +02:00
|
|
|
inputs.property("zipNameProvider", zipNameProvider)
|
2022-05-15 13:08:36 +02:00
|
|
|
inputs.property("projectTokens", projectTokensXX)
|
2022-05-01 15:46:20 +02:00
|
|
|
|
|
|
|
|
archiveFileName.set(zipNameProvider)
|
2021-12-02 00:54:15 +01:00
|
|
|
}
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
distributions {
|
|
|
|
|
main {
|
|
|
|
|
|
|
|
|
|
distributionBaseName.set(modName)
|
|
|
|
|
|
|
|
|
|
contents {
|
|
|
|
|
from(layout.projectDirectory.dir("src/main/resources/mod-data")) {
|
|
|
|
|
include("**/**")
|
|
|
|
|
}
|
|
|
|
|
from(licenseFile)
|
2022-02-20 12:23:29 +01:00
|
|
|
from(typescriptToLua.map { it.outputDirectory })
|
2022-02-13 10:44:13 +01:00
|
|
|
filesNotMatching("**/*.png") {
|
2022-05-01 15:46:20 +02:00
|
|
|
filter<ReplaceTokens>("tokens" to projectTokens.get())
|
2022-02-13 10:44:13 +01:00
|
|
|
}
|
2021-12-02 00:54:15 +01:00
|
|
|
includeEmptyDirs = false
|
|
|
|
|
exclude {
|
2021-12-28 17:05:52 +01:00
|
|
|
// exclude empty files
|
2021-12-02 00:54:15 +01:00
|
|
|
it.file.run {
|
|
|
|
|
isFile && useLines { lines -> lines.all { line -> line.isBlank() } }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-07 23:03:19 +02:00
|
|
|
|
|
|
|
|
tasks.withType<Zip>().configureEach {
|
2022-05-15 13:08:36 +02:00
|
|
|
val projectTokensXX = projectTokensX
|
|
|
|
|
inputs.property("projectTokens", projectTokensXX)
|
2022-05-07 23:03:19 +02:00
|
|
|
// if (name.startsWith("dist")) {
|
|
|
|
|
// notCompatibleWithConfigurationCache("NPE on projectTokens")
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 17:59:50 +02:00
|
|
|
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<ServiceProvider>()
|
|
|
|
|
|
|
|
|
|
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) }
|
|
|
|
|
|
2022-05-07 23:03:19 +02:00
|
|
|
|
2022-02-20 12:23:29 +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")
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
val factorioModProvider by configurations.registering {
|
|
|
|
|
asProvider()
|
|
|
|
|
factorioModAttributes(objects)
|
2021-12-02 00:54:15 +01:00
|
|
|
outgoing.artifact(tasks.distZip.flatMap { it.archiveFile })
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2022-05-07 20:22:54 +02:00
|
|
|
val packageJsonName = providers.provider { "${rootProject.name}-${project.name}" }
|
|
|
|
|
|
2021-12-01 18:12:34 +01:00
|
|
|
tasks.updatePackageJson {
|
2022-05-07 20:22:54 +02:00
|
|
|
inputs.property("packageJsonName", packageJsonName)
|
|
|
|
|
propertiesToCheck.put("name", packageJsonName)
|
2021-12-01 18:31:18 +01:00
|
|
|
packageJsonFile.set(layout.projectDirectory.file("src/main/typescript/package.json"))
|
2021-12-01 18:12:34 +01:00
|
|
|
}
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2021-12-08 17:43:08 +01:00
|
|
|
tasks.assemble { dependsOn(installEventsTsSchema, tasks.updatePackageJson) }
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-02-20 12:23:29 +01:00
|
|
|
|
|
|
|
|
// 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
|
|
|
//}
|
|
|
|
|
//
|
2022-02-20 12:23:29 +01:00
|
|
|
//val tsSrcConfiguration by configurations.registering {
|
|
|
|
|
// asProvider()
|
|
|
|
|
// outgoing.artifact(tsSrcDir)
|
|
|
|
|
//}
|
2021-12-01 16:57:46 +01:00
|
|
|
//
|
2022-02-20 12:23:29 +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
|
|
|
// }
|
2022-02-20 12:23:29 +01:00
|
|
|
// s
|
2021-12-01 16:57:46 +01:00
|
|
|
// }
|
|
|
|
|
// }
|
2022-02-20 12:23:29 +01:00
|
|
|
//}
|