|
| 1 | +const fs = require("fs"); |
| 2 | +const toml = require("@iarna/toml"); |
| 3 | + |
| 4 | +const errors = []; |
| 5 | + |
| 6 | +function checkMod(file) { |
| 7 | + const fileData = fs.readFileSync(file, "utf-8"); |
| 8 | + const parsed = toml.parse(fileData); |
| 9 | + |
| 10 | + if (!parsed.id) { |
| 11 | + errors.push(`${file} doesn't have an id?`); |
| 12 | + return null; |
| 13 | + } |
| 14 | + |
| 15 | + if (!parsed.filename || !parsed.filename.endsWith(".jar")) { |
| 16 | + errors.push(`${file} invalid mod name`); |
| 17 | + return null; |
| 18 | + } |
| 19 | + |
| 20 | + if (!parsed.download?.url) { |
| 21 | + errors.push(`${file} doesn't have a download url?`); |
| 22 | + return null; |
| 23 | + } |
| 24 | + |
| 25 | + if (!parsed.update && !parsed.overrides) { |
| 26 | + errors.push(`${file} doesn't have overrides...`); |
| 27 | + return parsed.id; |
| 28 | + } |
| 29 | + |
| 30 | + if (parsed.update?.modrinth?.version) { |
| 31 | + const modVersion = parsed.update.modrinth.version; |
| 32 | + const split = parsed.download.url.split("/"); |
| 33 | + if (split[split.length - 2] !== modVersion) { |
| 34 | + errors.push(`${file} has a bad download modrinth url. Please fix`); |
| 35 | + return parsed.id; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + return parsed.id; |
| 40 | +} |
| 41 | + |
| 42 | +function checkBundle(bundlePath, bundle) { |
| 43 | + const mods = fs.readdirSync(`${bundlePath}/mods`); |
| 44 | + const modIds = []; |
| 45 | + for (const mod of mods) { |
| 46 | + if (!mod.endsWith(".toml")) { |
| 47 | + errors.push( |
| 48 | + `${bundlePath} - Will not work because it contains a jar file` |
| 49 | + ); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + const path = `${bundlePath}/mods/${mod}`; |
| 54 | + const modId = checkMod(path); |
| 55 | + if (!modId) continue; |
| 56 | + if (modId.toLowerCase() === bundle.toLowerCase()) { |
| 57 | + errors.push( |
| 58 | + `${path} uses the defualt mod id. This is not recommended but not blocked` |
| 59 | + ); |
| 60 | + } |
| 61 | + if (modIds.includes(modId)) { |
| 62 | + errors.push(`${path} has a duplicate mod id`); |
| 63 | + } else { |
| 64 | + modIds.push(modId); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +const versions = fs.readdirSync("./oneclient/mrpacks/"); |
| 70 | +for (const version of versions) { |
| 71 | + const bundles = fs.readdirSync(`./oneclient/mrpacks/${version}`); |
| 72 | + for (const bundle of bundles) { |
| 73 | + checkBundle(`./oneclient/mrpacks/${version}/${bundle}`, bundle); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +if (errors.length > 0) { |
| 78 | + errors.forEach((error) => console.log(error)); |
| 79 | + throw new Error("Something wen't wrong"); |
| 80 | +} |
0 commit comments