2021-12-01 16:57:46 +01:00
|
|
|
import com.github.gradle.node.npm.task.NpmTask
|
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
|
2021-12-01 16:57:46 +01:00
|
|
|
import groovy.json.JsonOutput
|
|
|
|
|
import org.apache.tools.ant.filters.ReplaceTokens
|
|
|
|
|
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
|
|
|
|
|
|
|
|
|
plugins {
|
|
|
|
|
idea
|
2021-12-01 18:12:34 +01:00
|
|
|
id("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`
|
|
|
|
|
val modName: String by extra("${rootProject.name}-events")
|
|
|
|
|
val distributionZipName: String by extra("${modName}_${project.version}.zip")
|
|
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
val tokens: MutableMap<String, String> by project.extra
|
|
|
|
|
tokens += mapOf(
|
|
|
|
|
"mod.name" to modName,
|
|
|
|
|
"mod.title" to "Kafkatorio Events",
|
|
|
|
|
"mod.description" to (project.description ?: ""),
|
|
|
|
|
"factorio.version" to libs.versions.factorio.get().substringBeforeLast("."),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val licenseFile: RegularFile by project.extra
|
2021-12-01 16:57:46 +01:00
|
|
|
val tsSrcDir: Directory = layout.projectDirectory.dir("src/main/typescript")
|
|
|
|
|
|
|
|
|
|
node {
|
|
|
|
|
nodeProjectDir.set(tsSrcDir)
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
val typescriptEventsSchema: Configuration by configurations.creating {
|
2021-12-01 16:57:46 +01:00
|
|
|
asConsumer()
|
|
|
|
|
typescriptAttributes(objects)
|
2021-12-02 00:54:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
|
typescriptEventsSchema(projects.modules.eventsSchema)
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val typescriptToLua by tasks.registering(NpmTask::class) {
|
|
|
|
|
description = "Convert Typescript To Lua"
|
|
|
|
|
group = project.name
|
|
|
|
|
|
2021-12-03 09:04:18 +01:00
|
|
|
dependsOn(tasks.npmInstall, fetchEventsSchema)
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
execOverrides { standardOutput = System.out }
|
|
|
|
|
|
|
|
|
|
npmCommand.set(listOf("run", "build"))
|
|
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
inputs.dir(tsSrcDir)
|
2021-12-01 16:57:46 +01:00
|
|
|
.skipWhenEmpty()
|
|
|
|
|
.withPropertyName("sourceFiles")
|
|
|
|
|
.withPathSensitivity(PathSensitivity.RELATIVE)
|
|
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
args.set(parseSpaceSeparatedArgs("-- --outDir $temporaryDir"))
|
2021-12-01 16:57:46 +01:00
|
|
|
val outputDir = layout.buildDirectory.dir("typescriptToLua")
|
|
|
|
|
outputs.dir(outputDir)
|
|
|
|
|
.withPropertyName("outputDir")
|
|
|
|
|
|
|
|
|
|
ignoreExitValue.set(false)
|
|
|
|
|
|
|
|
|
|
doFirst("clean") {
|
2021-12-02 00:54:15 +01:00
|
|
|
delete(temporaryDir)
|
|
|
|
|
mkdir(temporaryDir)
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doLast("syncTstlOutput") {
|
|
|
|
|
sync {
|
2021-12-02 00:54:15 +01:00
|
|
|
from(temporaryDir)
|
2021-12-01 16:57:46 +01:00
|
|
|
into(outputDir)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 18:12:34 +01:00
|
|
|
val fetchEventsSchema 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
|
|
|
|
|
|
|
|
from(
|
2021-12-02 00:54:15 +01:00
|
|
|
typescriptEventsSchema.incoming
|
|
|
|
|
.artifactView { lenient(true) }
|
|
|
|
|
.artifacts
|
|
|
|
|
.artifactFiles
|
|
|
|
|
.filter { file -> file.exists() }
|
|
|
|
|
.files
|
|
|
|
|
.map { zipTree(it) }
|
|
|
|
|
) {
|
|
|
|
|
// 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-01 16:57:46 +01:00
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
into(layout.projectDirectory.dir("src/main/typescript/schema"))
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
tasks.distZip {
|
|
|
|
|
archiveFileName.set(distributionZipName)
|
|
|
|
|
}
|
2021-12-01 16:57:46 +01: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)
|
|
|
|
|
from(typescriptToLua.map { it.outputs })
|
2021-12-03 09:04:18 +01:00
|
|
|
filter<ReplaceTokens>("tokens" to tokens)
|
2021-12-02 00:54:15 +01:00
|
|
|
includeEmptyDirs = false
|
|
|
|
|
exclude {
|
2021-12-03 09:04:18 +01:00
|
|
|
// exclude empty lines
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-02 00:54:15 +01:00
|
|
|
//val packageMod by tasks.registering(Zip::class) {
|
|
|
|
|
// description = "Package mod files into ZIP"
|
|
|
|
|
// group = project.name
|
|
|
|
|
//
|
|
|
|
|
// dependsOn(typescriptToLua)
|
|
|
|
|
//
|
|
|
|
|
// inputs.properties(tokens)
|
|
|
|
|
//
|
|
|
|
|
// from(layout.projectDirectory.dir("src/main/resources/mod-data")) {
|
|
|
|
|
// include("**/**")
|
|
|
|
|
// filter<ReplaceTokens>("tokens" to tokens)
|
|
|
|
|
// }
|
|
|
|
|
// from(licenseFile)
|
|
|
|
|
//
|
|
|
|
|
// into(rootProject.name)
|
|
|
|
|
//
|
|
|
|
|
// // Factorio required format is:
|
|
|
|
|
// // - filename: `mod-name_version.zip`
|
|
|
|
|
// // - zip contains one directory, `mod-name`
|
|
|
|
|
// archiveFileName.set("${rootProject.name}_${project.version}.zip")
|
|
|
|
|
// destinationDirectory.set(layout.buildDirectory.dir("dist"))
|
|
|
|
|
//
|
|
|
|
|
// doLast {
|
|
|
|
|
// val outDir = destinationDirectory.asFile.get().toRelativeString(layout.projectDirectory.asFile)
|
|
|
|
|
// val outZip = "${archiveFileName.orNull}"
|
|
|
|
|
// logger.lifecycle("Packaged mod into $outDir/$outZip")
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-12-01 18:12:34 +01:00
|
|
|
tasks.updatePackageJson {
|
|
|
|
|
propertiesToCheck["name"] = "${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
|
|
|
|
2021-12-01 18:12:34 +01:00
|
|
|
tasks.assemble { dependsOn(fetchEventsSchema, tasks.updatePackageJson) }
|
2021-12-02 00:54:15 +01:00
|
|
|
//tasks.build { dependsOn(packageMod) }
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//idea {
|
|
|
|
|
// // this doesn't work - no source sets?
|
|
|
|
|
// module {
|
|
|
|
|
// sourceDirs.add(mkdir(layout.projectDirectory.dir("src/main/typescript").asFile))
|
|
|
|
|
// excludeDirs.add(mkdir(layout.projectDirectory.dir("src/main/typescript/node_modules").asFile))
|
|
|
|
|
// resourceDirs.add(mkdir(layout.projectDirectory.dir("src/main/resources").asFile))
|
|
|
|
|
// resourceDirs.add(mkdir(layout.projectDirectory.dir("infra").asFile))
|
|
|
|
|
// excludeDirs.add(mkdir(layout.projectDirectory.dir("infra/factorio-server").asFile))
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//val typescriptSrcSet =
|
|
|
|
|
// project.objects.sourceDirectorySet("typescript", "typescript").apply {
|
|
|
|
|
// srcDir(layout.projectDirectory.dir("src/main/typescript"))
|
|
|
|
|
//
|
|
|
|
|
// destinationDirectory.set(modBuildDir.dir("typescriptToLua").asFile)
|
|
|
|
|
// compiledBy(tstlTask) {
|
|
|
|
|
//
|
|
|
|
|
// project.objects.directoryProperty().apply {
|
|
|
|
|
// set(modBuildDir.dir("typescriptToLua"))
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|