build: add setupLocal task for local development config
This commit is contained in:
1 parent
af2a8bd35d
commit
656020f5c1
3 files changed
+56
-5
No files matched your search
@@ -12,13 +12,14 @@ This is the short version. The detailed design and endpoint reference follow in
|
|||||||
|
|
||||||
### 2. Configure the library
|
### 2. Configure the library
|
||||||
|
|
||||||
Copy the example config and edit the folder paths:
|
Create the local config and media directories:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp config/library.example.yaml config/library.yaml
|
./gradlew setupLocal
|
||||||
mkdir -p media/music media/longform
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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:
|
`config/library.yaml` defines every root the server indexes:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -42,6 +43,8 @@ The example file already uses these relative paths, so no edit is needed for loc
|
|||||||
|
|
||||||
### 3. Configure users
|
### 3. Configure users
|
||||||
|
|
||||||
|
`./gradlew setupLocal` already created it. To recreate it manually:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp config/users.example.yaml config/users.yaml
|
cp config/users.example.yaml config/users.yaml
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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 {
|
tasks.withType<JavaCompile>().configureEach {
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ data class LibraryConfig(val folders: List<MusicFolder>) {
|
|||||||
require(Files.isDirectory(folder.path)) {
|
require(Files.isDirectory(folder.path)) {
|
||||||
"Library folder ${folder.id} (${folder.name}) is not a directory: ${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). " +
|
"Create the directory or fix the path in the library config (LIBRARY_CONFIG). " +
|
||||||
"For local development, copy config/library.example.yaml and run " +
|
"For local development, run `./gradlew setupLocal` and copy " +
|
||||||
"`mkdir -p media/music media/longform`."
|
"config/library.example.yaml to config/library.yaml. That file is " +
|
||||||
|
"git-ignored, so `git pull` never updates it."
|
||||||
}
|
}
|
||||||
require(Files.isReadable(folder.path)) {
|
require(Files.isReadable(folder.path)) {
|
||||||
"Library folder ${folder.id} (${folder.name}) is not readable: ${folder.path}. " +
|
"Library folder ${folder.id} (${folder.name}) is not readable: ${folder.path}. " +
|
||||||
|
|||||||
Reference in new issue
Block a user