diff options
author | 0neGal <mail@0negal.com> | 2023-07-24 19:14:41 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2023-07-24 19:28:11 +0200 |
commit | 67f12f53c24ee3b5742aa28a7e3da8a56ddacf2a (patch) | |
tree | e215726bdd0927139de6ec8e4e913830fcca1e40 /src/modules/packages.js | |
parent | c7a3316b1fe29b3b0a4ab053f0a1b6a9b4069f24 (diff) | |
download | Viper-67f12f53c24ee3b5742aa28a7e3da8a56ddacf2a.tar.gz Viper-67f12f53c24ee3b5742aa28a7e3da8a56ddacf2a.zip |
largely improve how we convert mods to packages
Convert is a strong word, in reality, when a user installs (and thereby
also updates) a package, we attempt to search for a mod that we can with
pretty high confidence, we could theoretically make this even better,
but at some point you'll accidentally delete mods that are manually
installed and weren't actually the right ones.
Diffstat (limited to 'src/modules/packages.js')
-rw-r--r-- | src/modules/packages.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/modules/packages.js b/src/modules/packages.js index cb0b800..8a5af76 100644 --- a/src/modules/packages.js +++ b/src/modules/packages.js @@ -237,6 +237,36 @@ packages.install = async (url, author, package_name, version) => { mods.remove(mod.name); continue; } + + // normalizes a string, i.e attempt to make two strings + // identical, that simply have slightly different formatting, as + // an example, these strings: + // + // "Mod_Name" and "Mod name" + // + // will just become: + // + // "modname" + let normalize = (string) => { + return string.toLowerCase() + .replaceAll("_", "") + .replaceAll(".", "") + .replaceAll(" ", ""); + } + + // check if the mod's name from it's `mod.json` file when + // normalized, is the same as the normalized name of the package + if (normalize(mod.name) == normalize(package_name)) { + mods.remove(mod.name); + continue; + } + + // check if the name of the mod's folder when normalized, is the + // same as the normalized name of the package + if (normalize(mod.folder_name) == normalize(package_name)) { + mods.remove(mod.name); + continue; + } } // removes older version of package inside the `packages` folder @@ -374,8 +404,7 @@ packages.verify = (package_path) => { let found_mod = false; let mods = fs.readdirSync(mods_path); for (let i = 0; i < mods.length; i++) { - let mod = mods[i]; - let mod_file = path.join(mod, "mod.json"); + let mod_file = path.join(mods_path, mods[i], "mod.json"); // make sure mod.json exists, and is a file, otherwise, this // is unlikely to be a mod folder |