2022-10-02 12:11:06 +02:00
|
|
|
import dev.adamko.gradle.factorio.mod_portal.FactorioModPublishTask
|
|
|
|
|
import dev.adamko.gradle.factorio.typescriptAttributes
|
2022-12-18 01:40:40 +01:00
|
|
|
import kafkatorio.tasks.TypeScriptToLuaTask
|
2022-08-13 11:59:30 +02:00
|
|
|
import kotlinx.serialization.json.put
|
|
|
|
|
import kotlinx.serialization.json.putJsonObject
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
plugins {
|
2022-09-18 20:49:32 +02:00
|
|
|
id("kafkatorio.conventions.lang.node")
|
2022-10-02 12:11:06 +02:00
|
|
|
id("dev.adamko.factorio-mod")
|
2021-12-02 00:54:15 +01:00
|
|
|
distribution
|
2022-12-18 01:40:40 +01:00
|
|
|
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)"
|
2021-12-02 00:54:15 +01:00
|
|
|
|
|
|
|
|
|
2022-12-18 01:40:40 +01:00
|
|
|
factorioMod {
|
|
|
|
|
modName.set("kafkatorio-events")
|
|
|
|
|
modTitle.set("Kafkatorio Events")
|
|
|
|
|
modAuthor.set("adam@adamko.dev")
|
|
|
|
|
factorioCompatibility.set(libs.versions.factorio.map { it.substringBeforeLast(".") })
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 22:15:26 +01:00
|
|
|
val licenseFile: RegularFile by rootProject.extra
|
2022-05-15 13:08:36 +02:00
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
node {
|
2022-05-18 19:32:52 +02:00
|
|
|
nodeProjectDir.set(layout.projectDirectory)
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
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 {
|
2022-07-02 08:45:21 +02:00
|
|
|
typescriptEventsSchema(projects.modules.eventsLibrary)
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2022-12-18 01:40:40 +01:00
|
|
|
val typescriptToLua by tasks.registering(TypeScriptToLuaTask::class) {
|
2022-07-16 23:10:32 +02:00
|
|
|
dependsOn(
|
|
|
|
|
tasks.npmInstall,
|
|
|
|
|
installEventsTsSchema,
|
|
|
|
|
tasks.updatePackageJson,
|
|
|
|
|
)
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-07-02 10:24:02 +02:00
|
|
|
inputs.file(tasks.updatePackageJson.map { it.packageJsonFile })
|
|
|
|
|
|
2022-12-18 01:40:40 +01:00
|
|
|
sourceFiles.from(factorioMod.mainSources.typescript.sourceDirectories)
|
2022-07-02 09:50:11 +02:00
|
|
|
|
2022-12-18 01:40:40 +01:00
|
|
|
outputDirectory.set(factorioMod.mainSources.typescript.destinationDirectory)
|
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) {
|
2022-12-18 01:40:40 +01:00
|
|
|
description = "Fetch the latest shared TypeScript 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
|
|
|
|
|
|
|
|
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
|
|
|
) {
|
|
|
|
|
includeEmptyDirs = false
|
|
|
|
|
}
|
2022-12-18 01:40:40 +01:00
|
|
|
into(layout.projectDirectory.dir("src/main/typescript/generated"))
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 17:59:37 +02:00
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
tasks.distZip {
|
2022-12-18 01:40:40 +01:00
|
|
|
val distributionZipName = factorioMod.distributionZipName
|
|
|
|
|
archiveFileName.set(distributionZipName)
|
2021-12-02 00:54:15 +01:00
|
|
|
}
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-06-26 15:45:59 +02:00
|
|
|
val publishModToPortal by tasks.registering(FactorioModPublishTask::class) {
|
2022-05-19 23:12:44 +02:00
|
|
|
dependsOn(tasks.check)
|
|
|
|
|
|
2022-05-18 19:32:52 +02:00
|
|
|
distributionZip.set(tasks.distZip.flatMap { it.archiveFile })
|
|
|
|
|
|
2022-12-18 01:40:40 +01:00
|
|
|
modName.set(factorioMod.modName)
|
|
|
|
|
modVersion.set(factorioMod.modVersion)
|
2022-05-18 19:32:52 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-18 01:40:40 +01:00
|
|
|
tasks.assembleFactorioModContents {
|
|
|
|
|
modFiles.apply {
|
|
|
|
|
from(typescriptToLua.map { it.outputDirectory })
|
|
|
|
|
from(licenseFile)
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 11:59:30 +02: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 {
|
2022-05-18 19:36:40 +02:00
|
|
|
// mustRunAfter(tasks.npmInstall)
|
2022-08-13 11:59:30 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
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-06-19 10:54:37 +02: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")
|
|
|
|
|
// }
|
|
|
|
|
//}
|