diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/errors/ErrorSeverity.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/errors/ErrorSeverity.kt index e2eea8e1..12480226 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/errors/ErrorSeverity.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/errors/ErrorSeverity.kt @@ -2,5 +2,5 @@ package teksturepako.pakku.api.actions.errors enum class ErrorSeverity { - ERROR, WARNING, NOTICE; + FATAL, ERROR, WARNING, NOTICE; } \ No newline at end of file diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/Export.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/Export.kt index bd2dc50b..81448900 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/Export.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/Export.kt @@ -7,8 +7,10 @@ import com.github.michaelbull.result.runCatching import kotlinx.coroutines.* import teksturepako.pakku.api.actions.errors.ActionError import teksturepako.pakku.api.actions.errors.CouldNotSave +import teksturepako.pakku.api.actions.errors.ErrorSeverity import teksturepako.pakku.api.actions.export.Packaging.* import teksturepako.pakku.api.actions.export.RuleContext.Finished +import teksturepako.pakku.api.actions.export.profiles.defaultProfiles import teksturepako.pakku.api.data.ConfigFile import teksturepako.pakku.api.data.Dirs.cacheDir import teksturepako.pakku.api.data.LockFile @@ -19,25 +21,28 @@ import teksturepako.pakku.api.platforms.Platform import teksturepako.pakku.debug import teksturepako.pakku.io.* import java.nio.file.Path -import kotlin.collections.List -import kotlin.collections.Map -import kotlin.collections.associate -import kotlin.collections.filter -import kotlin.collections.filterNot -import kotlin.collections.filterNotNull -import kotlin.collections.flatMap import kotlin.collections.fold -import kotlin.collections.isNotEmpty -import kotlin.collections.listOf import kotlin.collections.map -import kotlin.collections.mapNotNull -import kotlin.collections.plus -import kotlin.collections.toMap import kotlin.io.path.* import kotlin.time.Duration import kotlin.time.measureTimedValue import com.github.michaelbull.result.fold as resultFold +suspend fun exportDefaultProfiles( + onError: suspend (profile: ExportProfile, error: ActionError) -> Unit, + onSuccess: suspend (profile: ExportProfile, path: Path, duration: Duration) -> Unit, + lockFile: LockFile, + configFile: ConfigFile, + platforms: List +): List +{ + return export( + profiles = defaultProfiles.map { it.build(exportingScope(lockFile, configFile)) }, + onError = { profile, error -> onError(profile, error) }, + onSuccess = { profile, path, duration -> onSuccess(profile, path, duration) }, + lockFile, configFile, platforms + ) +} suspend fun export( profiles: List, @@ -81,7 +86,7 @@ suspend fun ExportProfile.export( clientOverrides: Deferred>>, ) { - if (this.dependsOn != null && this.dependsOn !in platforms) return + if (this.requiresPlatform != null && this.requiresPlatform !in platforms) return val timedValue = measureTimedValue { @@ -105,7 +110,7 @@ suspend fun ExportProfile.export( val inputDirectory = Path(cacheDir.pathString, this.name) val results: List = this.rules.filterNotNull().produceRuleResults( - onError = { onError(this, it) }, + onError = { error -> onError(this, error) }, lockFile, configFile, this.name, overrides, serverOverrides, clientOverrides ) @@ -194,6 +199,7 @@ suspend fun List.resolveResults( { onError(packagingAction.error) debug { println(ruleResult) } + if (packagingAction.error.severity == ErrorSeverity.FATAL) return@coroutineScope listOf() null } is Ignore -> null diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/ExportProfile.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/ExportProfile.kt index 2d830c7a..375f2c95 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/ExportProfile.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/ExportProfile.kt @@ -1,6 +1,9 @@ package teksturepako.pakku.api.actions.export +import teksturepako.pakku.api.data.ConfigFile +import teksturepako.pakku.api.data.LockFile import teksturepako.pakku.api.platforms.Platform +import teksturepako.pakku.debug /** * An export profile is used to contain a list of [export rules][ExportRule]. @@ -17,5 +20,101 @@ open class ExportProfile( val name: String, val fileExtension: String = "zip", val rules: List, - val dependsOn: Platform? = null + val requiresPlatform: Platform? = null ) + +/** + * Creates an export profile with customized settings and export rules. + * + * ``` + * val profile = exportProfile(name = "MyProfile") { + * rule { /* Add export rules */ } + * optionalRule { /* Add optional export rules */ } orElse rule { /* ... */ } + * } + * ``` + * + * @param name The unique name for the export profile. + * @param fileExtension The file extension for the exported profile (defaults to "zip"). + * @param requiresPlatform Optional platform constraint for the export profile. + * @param builder A lambda function to add export rules. + */ +fun exportProfile( + name: String, + fileExtension: String = "zip", + requiresPlatform: Platform? = null, + builder: ExportProfileBuilder.() -> Unit +): ExportProfileBuilder = ExportProfileBuilder(name, fileExtension, requiresPlatform, builder) + +class ExportProfileBuilder( + private val name: String, + private val fileExtension: String = "zip", + private val requiresPlatform: Platform? = null, + private val builder: (ExportProfileBuilder.() -> Unit), + private var rules: Sequence = sequenceOf(), +) : ExportingScope +{ + override lateinit var lockFile: LockFile + override lateinit var configFile: ConfigFile + + fun build(exportingScope: ExportingScope): ExportProfile + { + lockFile = exportingScope.lockFile + configFile = exportingScope.configFile + + builder.invoke(this) + + debug { println("Building $name profile") } + + return ExportProfile(name, fileExtension, rules.toList(), requiresPlatform) + } + + // -- AFTER BUILD -- + + /** Adds an export rule to the profile. */ + fun rule(exportRule: (ExportingScope) -> ExportRule): ExportRule + { + val rule = exportRule(this) + + rules += rule + return rule + } + + /** Adds an optional export rule to the profile. */ + fun optionalRule(exportRule: (ExportingScope) -> ExportRule?): ExportRule? + { + val rule = exportRule(this) + + if (rule != null) + { + rules += rule + return rule + } + else return null + } + + /** Provides a fallback mechanism when an optional rule is null. */ + infix fun ExportRule?.orElse(exportRule: ExportRule): ExportRule? + { + if (this == null) + { + rules += exportRule + return exportRule + } + else return null + } +} + +interface ExportingScope +{ + /** The lock file associated with the exporting scope. */ + val lockFile: LockFile + + /** The config file associated with the exporting scope. */ + val configFile: ConfigFile +} + +fun exportingScope(lockFile: LockFile, configFile: ConfigFile): ExportingScope = object : ExportingScope +{ + override val lockFile: LockFile = lockFile + override val configFile: ConfigFile = configFile +} diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/RuleContext.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/RuleContext.kt index be2978f2..2e9f6ae7 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/RuleContext.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/RuleContext.kt @@ -20,7 +20,11 @@ import kotlin.io.path.* /** * Rule Context keeps track of currently exporting content. */ -sealed class RuleContext(open val workingSubDir: String) +sealed class RuleContext( + open val workingSubDir: String, + open val lockFile: LockFile, + open val configFile: ConfigFile +) { fun getPath(path: String, vararg subpath: String) = Path(cacheDir.pathString, workingSubDir, path, *subpath) @@ -91,10 +95,10 @@ sealed class RuleContext(open val workingSubDir: String) /** Rule context representing a [project][Project]. */ data class ExportingProject( val project: Project, - val lockFile: LockFile, - val configFile: ConfigFile, + override val lockFile: LockFile, + override val configFile: ConfigFile, override val workingSubDir: String - ) : RuleContext(workingSubDir) + ) : RuleContext(workingSubDir, lockFile, configFile) { /** Sets the [project entry][RuleContext.ExportingProject] missing. */ fun setMissing(): RuleResult = MissingProject( @@ -130,10 +134,10 @@ sealed class RuleContext(open val workingSubDir: String) data class ExportingOverride( val path: String, val type: OverrideType, - val lockFile: LockFile, - val configFile: ConfigFile, + override val lockFile: LockFile, + override val configFile: ConfigFile, override val workingSubDir: String - ) : RuleContext(workingSubDir) + ) : RuleContext(workingSubDir, lockFile, configFile) { fun export(overridesDir: String? = type.folderName): RuleResult { @@ -173,10 +177,10 @@ sealed class RuleContext(open val workingSubDir: String) /** Rule context representing a [project override][ProjectOverride]. */ data class ExportingProjectOverride( val projectOverride: ProjectOverride, - val lockFile: LockFile, - val configFile: ConfigFile, + override val lockFile: LockFile, + override val configFile: ConfigFile, override val workingSubDir: String - ) : RuleContext(workingSubDir) + ) : RuleContext(workingSubDir, lockFile, configFile) { fun export(overridesDir: String? = projectOverride.type.folderName): RuleResult { @@ -203,10 +207,10 @@ sealed class RuleContext(open val workingSubDir: String) /** Rule context representing a [missing project][Project]. */ data class MissingProject( val project: Project, - val lockFile: LockFile, - val configFile: ConfigFile, + override val lockFile: LockFile, + override val configFile: ConfigFile, override val workingSubDir: String - ) : RuleContext(workingSubDir) + ) : RuleContext(workingSubDir, lockFile, configFile) { suspend fun exportAsOverrideFrom( provider: Provider, @@ -263,10 +267,10 @@ sealed class RuleContext(open val workingSubDir: String) /** Rule context indicating that all other actions have been finished. */ data class Finished( - val lockFile: LockFile, - val configFile: ConfigFile, + override val lockFile: LockFile, + override val configFile: ConfigFile, override val workingSubDir: String - ) : RuleContext(workingSubDir) + ) : RuleContext(workingSubDir, lockFile, configFile) { fun replaceText(vararg pairs: Pair): RuleResult { diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/CurseForgeProfile.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/CurseForgeProfile.kt index a212f8db..1b63563f 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/CurseForgeProfile.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/CurseForgeProfile.kt @@ -1,25 +1,14 @@ package teksturepako.pakku.api.actions.export.profiles -import teksturepako.pakku.api.actions.export.ExportProfile -import teksturepako.pakku.api.actions.export.rules.createCfModpackModel +import teksturepako.pakku.api.actions.export.exportProfile +import teksturepako.pakku.api.actions.export.rules.cfMissingProjectsRule +import teksturepako.pakku.api.actions.export.rules.cfModpackRule import teksturepako.pakku.api.actions.export.rules.replacementRule -import teksturepako.pakku.api.actions.export.rules.ruleOfCfMissingProjects -import teksturepako.pakku.api.actions.export.rules.ruleOfCfModpack -import teksturepako.pakku.api.data.ConfigFile -import teksturepako.pakku.api.data.LockFile import teksturepako.pakku.api.platforms.CurseForge -import teksturepako.pakku.compat.exportFileDirector +import teksturepako.pakku.compat.fileDirectorRule -class CurseForgeProfile(lockFile: LockFile, configFile: ConfigFile) : ExportProfile( - name = CurseForge.serialName, - rules = listOf( - lockFile.getFirstMcVersion()?.let { - val modpackModel = createCfModpackModel(it, lockFile, configFile) - ruleOfCfModpack(modpackModel) - }, - if (lockFile.getAllProjects().any { "filedirector" in it }) exportFileDirector(excludedProviders = setOf(CurseForge)) - else ruleOfCfMissingProjects(), - replacementRule() - ), - dependsOn = CurseForge -) +fun curseForgeProfile() = exportProfile(name = CurseForge.serialName, requiresPlatform = CurseForge) { + rule { cfModpackRule() } + optionalRule { fileDirectorRule(excludedProviders = setOf(CurseForge)) } orElse rule { cfMissingProjectsRule() } + rule { replacementRule() } +} diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/DefaultProfiles.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/DefaultProfiles.kt new file mode 100644 index 00000000..d06e72b6 --- /dev/null +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/DefaultProfiles.kt @@ -0,0 +1,7 @@ +package teksturepako.pakku.api.actions.export.profiles + +val defaultProfiles = listOf( + curseForgeProfile(), + modrinthProfile(), + serverPackProfile() +) diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ModrinthProfile.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ModrinthProfile.kt index 55a1ac3a..4a161cf5 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ModrinthProfile.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ModrinthProfile.kt @@ -1,26 +1,16 @@ package teksturepako.pakku.api.actions.export.profiles -import teksturepako.pakku.api.actions.export.ExportProfile -import teksturepako.pakku.api.actions.export.rules.createMrModpackModel +import teksturepako.pakku.api.actions.export.exportProfile +import teksturepako.pakku.api.actions.export.rules.mrMissingProjectsRule +import teksturepako.pakku.api.actions.export.rules.mrModpackRule import teksturepako.pakku.api.actions.export.rules.replacementRule -import teksturepako.pakku.api.actions.export.rules.ruleOfMrMissingProjects -import teksturepako.pakku.api.actions.export.rules.ruleOfMrModpack -import teksturepako.pakku.api.data.ConfigFile -import teksturepako.pakku.api.data.LockFile import teksturepako.pakku.api.platforms.Modrinth -import teksturepako.pakku.compat.exportFileDirector +import teksturepako.pakku.compat.fileDirectorRule -class ModrinthProfile(lockFile: LockFile, configFile: ConfigFile) : ExportProfile( - name = Modrinth.serialName, - fileExtension = "mrpack", - rules = listOf( - lockFile.getFirstMcVersion()?.let { - val modpackModel = createMrModpackModel(it, lockFile, configFile) - ruleOfMrModpack(modpackModel) - }, - if (lockFile.getAllProjects().any { "filedirector" in it }) exportFileDirector(excludedProviders = setOf(Modrinth)) - else ruleOfMrMissingProjects(), - replacementRule() - ), - dependsOn = Modrinth -) +fun modrinthProfile() = exportProfile( + name = Modrinth.serialName, fileExtension = "mrpack", requiresPlatform = Modrinth +) { + rule { mrModpackRule() } + optionalRule { fileDirectorRule(excludedProviders = setOf(Modrinth)) } orElse rule { mrMissingProjectsRule() } + rule { replacementRule() } +} diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ServerPackProfile.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ServerPackProfile.kt index 47b8e87d..82491827 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ServerPackProfile.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/profiles/ServerPackProfile.kt @@ -1,13 +1,10 @@ package teksturepako.pakku.api.actions.export.profiles -import teksturepako.pakku.api.actions.export.ExportProfile -import teksturepako.pakku.api.actions.export.rules.exportServerPack +import teksturepako.pakku.api.actions.export.exportProfile import teksturepako.pakku.api.actions.export.rules.replacementRule +import teksturepako.pakku.api.actions.export.rules.serverPackRule -class ServerPackProfile : ExportProfile( - name = "serverpack", - rules = listOf( - exportServerPack(), - replacementRule() - ) -) \ No newline at end of file +fun serverPackProfile() = exportProfile(name = "serverpack") { + rule { serverPackRule() } + rule { replacementRule() } +} diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/CurseForgeRules.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/CurseForgeRules.kt index 11181d9d..3b296f5b 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/CurseForgeRules.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/CurseForgeRules.kt @@ -1,5 +1,7 @@ package teksturepako.pakku.api.actions.export.rules +import teksturepako.pakku.api.actions.errors.ActionError +import teksturepako.pakku.api.actions.errors.ErrorSeverity import teksturepako.pakku.api.actions.export.ExportRule import teksturepako.pakku.api.actions.export.Packaging import teksturepako.pakku.api.actions.export.RuleContext.* @@ -14,7 +16,18 @@ import teksturepako.pakku.api.platforms.CurseForge import teksturepako.pakku.api.projects.Project import teksturepako.pakku.api.projects.ProjectFile -fun ruleOfCfModpack(modpackModel: CfModpackModel) = ExportRule { +data object RequiresMcVersion : ActionError() +{ + override val rawMessage = "Modpack requires a minimum of one version of Minecraft." + override val severity = ErrorSeverity.FATAL +} + +fun cfModpackRule() = ExportRule { + + val modpackModel = it.lockFile.getFirstMcVersion()?.let { mcVersion -> + createCfModpackModel(mcVersion, it.lockFile, it.configFile) + } ?: return@ExportRule it.error(RequiresMcVersion) + when (it) { is ExportingProject -> @@ -34,7 +47,7 @@ fun ruleOfCfModpack(modpackModel: CfModpackModel) = ExportRule { } } -fun ruleOfCfMissingProjects() = ExportRule { +fun cfMissingProjectsRule() = ExportRule { when (it) { is MissingProject -> diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ModrinthRules.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ModrinthRules.kt index e6ee3978..b8901576 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ModrinthRules.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ModrinthRules.kt @@ -16,7 +16,12 @@ import teksturepako.pakku.api.projects.ProjectSide import teksturepako.pakku.io.createHash import teksturepako.pakku.io.readPathBytesOrNull -fun ruleOfMrModpack(modpackModel: MrModpackModel) = ExportRule { +fun mrModpackRule() = ExportRule { + + val modpackModel = it.lockFile.getFirstMcVersion()?.let { mcVersion -> + createMrModpackModel(mcVersion, it.lockFile, it.configFile) + } ?: return@ExportRule it.error(RequiresMcVersion) + when (it) { is ExportingProject -> @@ -36,7 +41,7 @@ fun ruleOfMrModpack(modpackModel: MrModpackModel) = ExportRule { } } -fun ruleOfMrMissingProjects() = ExportRule { +fun mrMissingProjectsRule() = ExportRule { when (it) { is MissingProject -> diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ServerPackRules.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ServerPackRules.kt index f6aa1630..dc1ddb8c 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ServerPackRules.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/export/rules/ServerPackRules.kt @@ -4,7 +4,7 @@ import teksturepako.pakku.api.actions.export.ExportRule import teksturepako.pakku.api.actions.export.RuleContext.* import teksturepako.pakku.api.overrides.OverrideType -fun exportServerPack() = ExportRule { +fun serverPackRule() = ExportRule { when (it) { is ExportingProject -> diff --git a/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Export.kt b/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Export.kt index 5e7c9e41..e215f146 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Export.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Export.kt @@ -8,10 +8,7 @@ import com.github.michaelbull.result.getOrElse import kotlinx.coroutines.joinAll import kotlinx.coroutines.runBlocking import teksturepako.pakku.api.actions.errors.AlreadyExists -import teksturepako.pakku.api.actions.export.export -import teksturepako.pakku.api.actions.export.profiles.CurseForgeProfile -import teksturepako.pakku.api.actions.export.profiles.ModrinthProfile -import teksturepako.pakku.api.actions.export.profiles.ServerPackProfile +import teksturepako.pakku.api.actions.export.exportDefaultProfiles import teksturepako.pakku.api.data.ConfigFile import teksturepako.pakku.api.data.LockFile import teksturepako.pakku.api.platforms.Platform @@ -44,12 +41,7 @@ class Export : CliktCommand() return@runBlocking } - export( - profiles = listOf( - CurseForgeProfile(lockFile, configFile), - ModrinthProfile(lockFile, configFile), - ServerPackProfile() - ), + exportDefaultProfiles( onError = { profile, error -> if (error !is AlreadyExists) { diff --git a/src/commonMain/kotlin/teksturepako/pakku/cli/ui/ErrorMsg.kt b/src/commonMain/kotlin/teksturepako/pakku/cli/ui/ErrorMsg.kt index 96053694..6d8748c1 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/cli/ui/ErrorMsg.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/cli/ui/ErrorMsg.kt @@ -11,6 +11,10 @@ fun Terminal.processErrorMsg(error: ActionError, arg: String = "", prepend: Stri return when (error.severity) { + ErrorSeverity.FATAL -> + { + this.theme.danger(prefixed("$prep$msg", this.theme.string("pakku.prefix", ">>>"), offset)) + } ErrorSeverity.ERROR -> { this.theme.danger(prefixed("$prep$msg", this.theme.string("pakku.prefix", ">>>"), offset)) diff --git a/src/commonMain/kotlin/teksturepako/pakku/compat/FileDirector.kt b/src/commonMain/kotlin/teksturepako/pakku/compat/FileDirector.kt index 575784eb..e73b1a00 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/compat/FileDirector.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/compat/FileDirector.kt @@ -6,6 +6,7 @@ import net.thauvin.erik.urlencoder.UrlEncoderUtil import teksturepako.pakku.api.actions.errors.ActionError import teksturepako.pakku.api.actions.errors.NoFiles import teksturepako.pakku.api.actions.export.ExportRule +import teksturepako.pakku.api.actions.export.ExportingScope import teksturepako.pakku.api.actions.export.Packaging import teksturepako.pakku.api.actions.export.RuleContext.Finished import teksturepako.pakku.api.actions.export.RuleContext.MissingProject @@ -32,21 +33,26 @@ data class FileDirectorModel( ) } -fun exportFileDirector( +fun ExportingScope.fileDirectorRule( excludedProviders: Set = setOf(), fileDirectorModel: FileDirectorModel = FileDirectorModel() -) = ExportRule { - when (it) - { - is MissingProject -> - { - it.addToFileDirector(fileDirectorModel, excludedProviders) - } - is Finished -> +): ExportRule? +{ + if (lockFile.getProject("filedirector") == null) return null + + return ExportRule { + when (it) { - it.createJsonFile(fileDirectorModel, "overrides/config/mod-director/.bundle.json") + is MissingProject -> + { + it.addToFileDirector(fileDirectorModel, excludedProviders) + } + is Finished -> + { + it.createJsonFile(fileDirectorModel, "overrides/config/mod-director/.bundle.json") + } + else -> it.ignore() } - else -> it.ignore() } }