Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support glob for overrides #43

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/teksturepako/pakku/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package teksturepako.pakku

const val VERSION = "0.18.2"
const val VERSION = "0.19.0"
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import teksturepako.pakku.api.data.Dirs.cacheDir
import teksturepako.pakku.api.data.LockFile
import teksturepako.pakku.api.data.workingPath
import teksturepako.pakku.api.overrides.OverrideType
import teksturepako.pakku.api.overrides.filterOverrides
import teksturepako.pakku.api.overrides.readProjectOverrides
import teksturepako.pakku.api.platforms.Platform
import teksturepako.pakku.debug
Expand Down Expand Up @@ -270,11 +271,11 @@ suspend fun List<ExportRule>.produceRuleResults(
val results = this.fold(listOf<Pair<ExportRule, RuleContext>>()) { acc, rule ->
acc + lockFile.getAllProjects().map {
rule to RuleContext.ExportingProject(it, lockFile, configFile, workingSubDir)
} + configFile.getAllOverrides().map {
} + filterOverrides(configFile.getAllOverrides().expandWithGlob()).map {
rule to RuleContext.ExportingOverride(it, OverrideType.OVERRIDE, lockFile, configFile, workingSubDir)
} + configFile.getAllServerOverrides().map {
} + filterOverrides(configFile.getAllServerOverrides().expandWithGlob()).map {
rule to RuleContext.ExportingOverride(it, OverrideType.SERVER_OVERRIDE, lockFile, configFile, workingSubDir)
} + configFile.getAllClientOverrides().map {
} + filterOverrides(configFile.getAllClientOverrides().expandWithGlob()).map {
SettingDust marked this conversation as resolved.
Show resolved Hide resolved
rule to RuleContext.ExportingOverride(it, OverrideType.CLIENT_OVERRIDE, lockFile, configFile, workingSubDir)
} + readProjectOverrides(configFile).map {
rule to RuleContext.ExportingProjectOverride(it, lockFile, configFile, workingSubDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ data class ConfigFile(
this.overrides.clear()
}

fun getAllOverrides(): List<String> = filterOverrides(this.overrides)
fun getAllServerOverrides(): List<String> = filterOverrides(this.serverOverrides)
fun getAllClientOverrides(): List<String> = filterOverrides(this.clientOverrides)
fun getAllOverrides(): List<String> = this.overrides
fun getAllServerOverrides(): List<String> = this.serverOverrides
fun getAllClientOverrides(): List<String> = this.clientOverrides

// -- PROJECTS --

Expand Down
19 changes: 19 additions & 0 deletions src/commonMain/kotlin/teksturepako/pakku/io/Glob.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package teksturepako.pakku.io

import java.nio.file.FileSystems
import java.nio.file.Path
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.Path
import kotlin.io.path.PathWalkOption
import kotlin.io.path.walk

@OptIn(ExperimentalPathApi::class)
fun Path.listDirectoryEntriesRecursive(glob: String): List<Path>
{
val matcher = FileSystems.getDefault().getPathMatcher("glob:${glob.removePrefix("./")}")
return walk(PathWalkOption.FOLLOW_LINKS, PathWalkOption.INCLUDE_DIRECTORIES).filter { matcher.matches(it) }.toList()
SettingDust marked this conversation as resolved.
Show resolved Hide resolved
}

fun List<String>.expandWithGlob() = flatMap { glob ->
Path("").listDirectoryEntriesRecursive(glob).map { it.toString() }
}