build: add setupLocal task for local development config

This commit is contained in:
TapTap committed 2026-11-13 12:15:31 +00:00
1 parent af2a8bd35d
commit 656020f5c1
3 files changed
+56 -5

No files matched your search

+47
View File
@@ -67,6 +67,53 @@ tasks.test {
}
}
/**
* Prepares a local development checkout: creates the media directories and copies
* the example configs when they are missing. Existing files are never overwritten.
*/
val setupLocal by tasks.registering {
group = "application"
description = "Create local media folders and copy example configs if missing."
doLast {
project.mkdir("media/music")
project.mkdir("media/longform")
listOf("library", "users").forEach { name ->
val target = project.file("config/$name.yaml")
val example = project.file("config/$name.example.yaml")
if (!target.exists()) {
target.parentFile.mkdirs()
example.copyTo(target)
println("Created config/$name.yaml from config/$name.example.yaml")
} else {
println("Keeping existing config/$name.yaml")
}
}
val libraryConfig = project.file("config/library.yaml")
if (libraryConfig.exists()) {
val stale = libraryConfig.readText().lineSequence()
.map { it.trim() }
.filter { it.startsWith("path:") }
.map { it.removePrefix("path:").trim() }
.filter { it.startsWith("/mnt/media/") }
.toList()
if (stale.isNotEmpty()) {
logger.warn(
"config/library.yaml still points at /mnt/media paths that are not available " +
"locally: $stale. Replace it with the local example: " +
"cp config/library.example.yaml config/library.yaml",
)
}
}
}
}
tasks.named("run") {
dependsOn(setupLocal)
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}