hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/cli/commands/check.js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/commands/check.js')
-rw-r--r--cli/commands/check.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/cli/commands/check.js b/cli/commands/check.js
new file mode 100644
index 0000000..f91b710
--- /dev/null
+++ b/cli/commands/check.js
@@ -0,0 +1,81 @@
+const { LoadConfig } = require("../../lib/config")
+const { GetModVersions, GetCompatibleVersion } = require("../../lib/modrinth")
+
+const config = LoadConfig()
+const { minecraft_version, modrinth_mods } = config
+
+const Check = async () =>
+{
+ console.log(`\n Checking mod compatibility for MC ${minecraft_version} (Fabric)...\n`)
+
+ const compatible = []
+ const incompatible = []
+ const failed = []
+
+ for (const slug of modrinth_mods)
+ {
+ try
+ {
+ const versions = await GetModVersions(slug)
+ if (!versions)
+ {
+ failed.push(slug)
+ continue
+ }
+
+ const match = GetCompatibleVersion(versions, minecraft_version, "fabric")
+ if (match)
+ {
+ const filename = match.files[0]?.filename || match.version_number
+ compatible.push({ slug, version: filename })
+ }
+ else
+ {
+ incompatible.push(slug)
+ }
+ }
+ catch (err)
+ {
+ failed.push(slug)
+ }
+ }
+
+ // Display results
+ if (compatible.length)
+ {
+ console.log(" [OK] Compatible:")
+ for (const { slug, version } of compatible)
+ console.log(` ${slug} -> ${version}`)
+ console.log("")
+ }
+
+ if (incompatible.length)
+ {
+ console.log(" [FAIL] No compatible version:")
+ for (const slug of incompatible)
+ console.log(` ${slug}`)
+ console.log("")
+ }
+
+ if (failed.length)
+ {
+ console.log(" [WARN] Failed to check:")
+ for (const slug of failed)
+ console.log(` ${slug}`)
+ console.log("")
+ }
+
+ // Summary
+ const total = modrinth_mods.length
+ const ok = compatible.length
+
+ console.log(` Summary: ${ok}/${total} mods compatible\n`)
+
+ if (incompatible.length === 0 && failed.length === 0)
+ console.log(" [OK] Safe to generate!\n")
+ else
+ console.log(" [FAIL] Not all mods are compatible. Generate may have issues.\n")
+}
+
+module.exports = { Check }
+