tidy up after refactoring Gradle Factorio plugin

This commit is contained in:
Adam 2022-12-19 16:53:18 +01:00
parent a99ed5bb85
commit 76c47d9756
7 changed files with 14 additions and 273 deletions

View file

@ -21,38 +21,8 @@ factorioMod {
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" } }
//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")
node {
nodeProjectDir.set(layout.projectDirectory)
}
@ -102,21 +72,13 @@ val installEventsTsSchema by tasks.registering(Sync::class) {
.map { zipTree(it) }
}
) {
// drop the first directory inside the zip
// eachFile { relativePath = dropDirectory() }
includeEmptyDirs = false
}
into(layout.projectDirectory.dir("src/main/typescript/generated"))
}
//val zipNameProvider = provider { distributionZipName }
tasks.distZip {
// val projectTokensXX22 = projectTokensX1
// inputs.property("zipNameProvider", zipNameProvider)
// inputs.property("projectTokens", projectTokensXX22)
val distributionZipName = factorioMod.distributionZipName
archiveFileName.set(distributionZipName)
}
@ -126,10 +88,8 @@ val publishModToPortal by tasks.registering(FactorioModPublishTask::class) {
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 {
@ -139,49 +99,6 @@ tasks.assembleFactorioModContents {
}
}
//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() } }
//// }
//// }
// }
// }
//}
tasks.withType<Zip>().configureEach {
val projectTokensXX444 = projectTokensX1
inputs.property("projectTokens", projectTokensXX444)
}
//val factorioModProvider by configurations.registering {
// asProvider()
// factorioModAttributes(objects)
// outgoing.artifact(tasks.distZip.flatMap { it.archiveFile })
//}
val projectPackageJsonName: Provider<String> =
providers.provider { "${rootProject.name}-${project.name}" }
val projectPackageJsonFile: RegularFile = layout.projectDirectory.file("package.json")
@ -207,84 +124,6 @@ tasks.updatePackageJson {
tasks.assemble { dependsOn(installEventsTsSchema, tasks.updatePackageJson) }
//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"))
//}
//
//val tsSrcConfiguration by configurations.registering {
// asProvider()
// outgoing.artifact(tsSrcDir)
//}
//
//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
// }
// s
// }
// }
//}
//val downloadFactorioApiDocs by tasks.registering {
// group = project.name
//

View file

@ -1,9 +0,0 @@
{
"name": "@mod.name@",
"version": "@project.version@",
"title": "@mod.title@",
"description": "@mod.description@",
"author": "@author.email@",
"factorio_version": "@factorio.version@",
"dependencies": []
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

View file

@ -1,6 +1,4 @@
import dev.adamko.gradle.factorio.FactorioModPlugin
import dev.adamko.gradle.factorio.factorioModAttributes
import kafkatorio.extensions.not
import kafkatorio.tasks.ProcessRunningSpec
import org.gradle.kotlin.dsl.support.serviceOf
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
@ -10,7 +8,7 @@ plugins {
id("dev.adamko.factorio-mod")
}
description = "Start the Factorio game client"
description = "Manage the Factorio game client"
val clientModsDirectory: DirectoryProperty = objects.directoryProperty().apply {
val modDir = File("""D:\Users\Adam\AppData\Roaming\Factorio\mods""")
@ -18,69 +16,15 @@ val clientModsDirectory: DirectoryProperty = objects.directoryProperty().apply {
set(modDir)
}
}
//val factorioGameId = "427520"
//val steamExe: RegularFileProperty = objects.fileProperty().apply {
// val steam = File("""C:\Program Files (x86)\Steam\steam.exe""")
// if (steam.exists()) {
// set(steam)
// }
//}
//val factorioMod: Configuration by configurations.creating {
// asConsumer()
// factorioModAttributes(objects)
//}
dependencies {
factorioMod(projects.modules.eventsMod)
}
//<editor-fold desc="Mod deployment tasks">
//val deployModToLocalClient by tasks.registering(Copy::class) {
// description = "Copy the mod to the Factorio client"
// group = FactorioModPlugin.TASK_GROUP
//
// val clientModsDirectory123 = clientModsDirectory
//
// onlyIf { clientModsDirectory123.orNull?.asFile?.exists() == true }
//
// from(configurations.factorioMod.map { it.incoming.artifactView { lenient(true) }.files })
// into(clientModsDirectory)
//
// doLast {
// logger.lifecycle("Copying mod from ${source.files} to $destinationDir")
// }
//}
//</editor-fold>
//<editor-fold desc="Factorio client lifecycle tasks">
fun ExecOperations.isFactorioRunning(): Spec<Task> = ProcessRunningSpec(this, "factorio.exe")
//val clientLaunch by tasks.registering(Exec::class) {
// description = "Run local Factorio Steam game client"
// group = FactorioModPlugin.TASK_GROUP
//
// val steamExe123 = steamExe
// val clientModsDirectory444 = clientModsDirectory
//
// onlyIf(!serviceOf<ExecOperations>().isFactorioRunning())
// onlyIf { steamExe123.orNull?.asFile?.exists() == true }
// onlyIf { clientModsDirectory444.orNull?.asFile?.exists() == true }
//
// dependsOn(deployModToLocalClient)
// mustRunAfter(clientKill, ":modules:infra-factorio-server:processRun")
//
// commandLine = parseSpaceSeparatedArgs(
//// """explorer "steam://rungameid/$factorioGameId// --mp-connect localhost/" """ // not working
//// """explorer "steam://run/$factorioGameId//--mp-connect localhost/" """ // works! But has annoying pop-up
// """ ${steamExe.asFile.orNull?.canonicalPath} -applaunch $factorioGameId --mp-connect localhost --mod-directory ${clientModsDirectory.asFile.orNull?.canonicalPath} """
// )
// doFirst { logger.lifecycle("Launching factorio.exe") }
//}
val clientKill by tasks.registering(Exec::class) {
description = "Stop the local Factorio Steam game client"
group = FactorioModPlugin.TASK_GROUP
@ -90,7 +34,6 @@ val clientKill by tasks.registering(Exec::class) {
commandLine = parseSpaceSeparatedArgs(""" taskkill /im factorio.exe """)
doFirst { logger.lifecycle("Killing factorio.exe") }
}
//</editor-fold>
tasks.register(FactorioModPlugin.PUBLISH_MOD_LOCAL_TASK_NAME) {

View file

@ -12,19 +12,9 @@ geedeecee {
srcDir.set(layout.projectDirectory.dir("src"))
}
//val dockerSrcDir: Directory by extra
//val factorioServerDataDir: Directory = dockerSrcDir.dir("factorio-server")
val factorioServerDataDir: DirectoryProperty = objects.directoryProperty()
.convention(geedeecee.srcDir.dir("factorio-server"))
//val factorioMod: Configuration by configurations.creating {
// asConsumer()
// factorioModAttributes(objects)
//}
dependencies {
factorioMod(projects.modules.eventsMod)
}