From 656020f5c12d78c8d1903fdded0708b9408e328b Mon Sep 17 00:00:00 2001 From: TapTap Date: Fri, 13 Nov 2026 12:15:31 +0000 Subject: [PATCH] build: add setupLocal task for local development config --- README.md | 9 ++-- build.gradle.kts | 47 +++++++++++++++++++ .../musicmanager/config/LibraryConfig.kt | 5 +- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0f76e2..01eca03 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/build.gradle.kts b/build.gradle.kts index de54396..f4d09c6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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().configureEach { options.encoding = "UTF-8" } diff --git a/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt b/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt index f554655..51203e7 100644 --- a/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt +++ b/src/main/kotlin/win/taptap/musicmanager/config/LibraryConfig.kt @@ -37,8 +37,9 @@ data class LibraryConfig(val folders: List) { 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}. " +