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

+6 -3
View File
@@ -12,13 +12,14 @@ This is the short version. The detailed design and endpoint reference follow in
### 2. Configure the library
Copy the example config and edit the folder paths:
Create the local config and media directories:
```bash
cp config/library.example.yaml config/library.yaml
mkdir -p media/music media/longform
./gradlew setupLocal
```
This copies `config/library.example.yaml` to `config/library.yaml` (only when it does not exist), copies `config/users.example.yaml` to `config/users.yaml` and creates `media/music` plus `media/longform`. Both local config files are git-ignored, so `git pull` never touches them.
`config/library.yaml` defines every root the server indexes:
```yaml
@@ -42,6 +43,8 @@ The example file already uses these relative paths, so no edit is needed for loc
### 3. Configure users
`./gradlew setupLocal` already created it. To recreate it manually:
```bash
cp config/users.example.yaml config/users.yaml
```
+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"
}
@@ -37,8 +37,9 @@ data class LibraryConfig(val folders: List<MusicFolder>) {
require(Files.isDirectory(folder.path)) {
"Library folder ${folder.id} (${folder.name}) is not a directory: ${folder.path}. " +
"Create the directory or fix the path in the library config (LIBRARY_CONFIG). " +
"For local development, copy config/library.example.yaml and run " +
"`mkdir -p media/music media/longform`."
"For local development, run `./gradlew setupLocal` and copy " +
"config/library.example.yaml to config/library.yaml. That file is " +
"git-ignored, so `git pull` never updates it."
}
require(Files.isReadable(folder.path)) {
"Library folder ${folder.id} (${folder.name}) is not readable: ${folder.path}. " +