2021-12-01 18:12:34 +01:00
|
|
|
import dev.adamko.kafkatorio.gradle.asConsumer
|
|
|
|
|
import dev.adamko.kafkatorio.gradle.asProvider
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
description =
|
|
|
|
|
"Sends in-game information to a server over the internet (requires Kafkatorio Kafka-Pipe)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Factorio required format is:
|
|
|
|
|
// - filename: `mod-name_version.zip`
|
|
|
|
|
// - zip contains one directory, `mod-name`
|
2022-05-01 15:46:20 +02:00
|
|
|
val modName: String by extra { "${rootProject.name}-events" }
|
|
|
|
|
val distributionZipName: String by extra { "${modName}_${project.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-01 15:46:20 +02:00
|
|
|
val projectTokens: MapProperty<String, String> by rootProject.extra
|
|
|
|
|
projectTokens.apply {
|
|
|
|
|
put("mod.name", modName)
|
|
|
|
|
put("mod.title", "Kafkatorio Events")
|
|
|
|
|
put("mod.description", provider { project.description }.orElse(""))
|
|
|
|
|
put("factorio.version", modFactorioCompatibility)
|
|
|
|
|
}
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
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
|
|
|
|
|
eachFile {
|
|
|
|
|
relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray())
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
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-01 15:46:20 +02:00
|
|
|
inputs.property("zipNameProvider", zipNameProvider)
|
|
|
|
|
inputs.property("projectTokens", projectTokens)
|
|
|
|
|
|
|
|
|
|
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-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
|
|
|
|
2021-12-01 18:12:34 +01:00
|
|
|
tasks.updatePackageJson {
|
2022-04-23 17:59:37 +02:00
|
|
|
propertiesToCheck.put("name", providers.provider { "${rootProject.name}-${project.name}" })
|
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
|
|
|
//}
|