Created
May 13, 2026 04:53
-
-
Save Lothrazar/54eb5dc8167c3152b4e7cb19560023cd to your computer and use it in GitHub Desktop.
automate copying an example config based on the mods generated config file(s) if any
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // I like to commit example versions of the generated config files in the root /examples/ folder of a mod src repo | |
| // this task automates that process | |
| // run it whenever you update the mods configs, or hook it up to trigger off some other task in the workflow | |
| tasks.register('syncExampleConfigs') { | |
| group = 'documentation' | |
| description = 'Copies generated example config files from run/config/ into examples/.' | |
| doLast { | |
| def modId = project.mod_id | |
| def srcDir = file('run/config') | |
| def destDir = file('examples') | |
| if (!srcDir.exists()) { | |
| logger.lifecycle("[${project.name}] run/config/ not found — nothing to sync.") | |
| return | |
| } | |
| def found = [ | |
| "${modId}.json", | |
| "${modId}.toml", | |
| "${modId}-common.toml", | |
| "${modId}-client.toml", | |
| "${modId}-server.toml" | |
| ].collect { new File(srcDir, it) }.findAll { it.exists() } | |
| if (found.isEmpty()) { | |
| logger.lifecycle("[${project.name}] No matching config files in run/config/ for '${modId}'.") | |
| return | |
| } | |
| destDir.mkdirs() | |
| found.each { src -> | |
| java.nio.file.Files.copy( | |
| src.toPath(), | |
| new File(destDir, src.name).toPath(), | |
| java.nio.file.StandardCopyOption.REPLACE_EXISTING | |
| ) | |
| logger.lifecycle("[${project.name}] Synced: ${src.name} → examples/") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment