fixed modloader versions match

This commit is contained in:
2021-01-06 00:17:53 +01:00
parent 70ef29ef2b
commit eb6a78d254
5 changed files with 147 additions and 100 deletions

4
.gitignore vendored
View File

@ -107,3 +107,7 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
/.eslintrc.js
/mods
/mods-lock.json
/mods.json

18
package-lock.json generated Normal file
View File

@ -0,0 +1,18 @@
{
"name": "minecraft-mod-packager",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"follow-redirects": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
"integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
},
"node-json-minify": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-json-minify/-/node-json-minify-1.0.0.tgz",
"integrity": "sha1-e7NDL5ZYtr6x2ZP9XVOzyinQ15w="
}
}
}

19
package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "minecraft-mod-packager",
"version": "1.0.0",
"description": "A minecraft mod package manager",
"main": "src/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.redstoneunion.de/MrGeorgen/minecraft-mod-packager.git"
},
"author": "MrGeorgen",
"license": "LGPL-3.0",
"dependencies": {
"follow-redirects": "^1.13.0",
"node-json-minify": "^1.0.0"
}
}

View File

@ -1,21 +1,18 @@
const { http, https } = require('follow-redirects');
const fs = require("fs");
let downloadStarted = false;
let mods_lock;
let dep = new Map();
try {
function main() {
const { http, https } = require('follow-redirects');
const fs = require("fs");
let downloadStarted = false;
let dep = new Map();
mods_lock = new Map(Object.entries(mods_lock));
} catch {
mods_lock = new Map;
}
global.config.mods.curse.forEach(mod => {
getData(`search?categoryId=0&gameId=432&gameVersion=${encodeURI(global.config.gameVersion)}&index=0&pageSize=15&searchFilter=${encodeURI(mod)}&sectionId=6&sort=2`, (result) => { // resolve projectID
global.config.mods.curse.forEach(mod => {
getData(`search?categoryId=0&gameId=432&gameVersion=${encodeURI(global.config.gameVersion)}&index=0&pageSize=1&searchFilter=${encodeURI(mod)}&sectionId=6&sort=2`, (result) => { // resolve projectID
resolveDep(result[0].id, downloadMods);
});
});
});
var resolveDepRecursionCount = [];
function resolveDep(modId, callback, index) {
var resolveDepRecursionCount = [];
function resolveDep(modId, callback, index) {
if(index === undefined) index = resolveDepRecursionCount.push(0) - 1;
++resolveDepRecursionCount[index];
getData(`${modId}/files`, (files) => {
@ -33,9 +30,9 @@ function resolveDep(modId, callback, index) {
--resolveDepRecursionCount[index];
if(resolveDepRecursionCount[index] == 0) callback();
});
}
}
function getData(url, callback) {
function getData(url, callback) {
https.get(`https://addons-ecs.forgesvc.net/api/v2/addon/${url}`, (resp) => {
let data = '';
resp.on('data', (chunk) => {
@ -45,28 +42,27 @@ function getData(url, callback) {
callback(JSON.parse(data));
});
});
}
}
function versionMatch(versionArray, gameVersion) {
function versionMatch(versionArray, gameVersion) {
let gameVersionMatch = false;
versionArray.forEach(version => {
gameVersionMatch = gameVersionMatch || version == gameVersion;
});
return gameVersionMatch;
}
}
function modloaderMatch(versionArray, modloaderVersion) {
versionArray.forEach(version => {
if(/^[a-zA-Z]+$/.test(version) && version != modloaderVersion) return false;
function modloaderMatch(versionArray, modloaderVersion) {
for(let i = 0; i < versionArray.length; ++i) {
if(/^[a-zA-Z]+$/.test(versionArray[i]) && versionArray[i] != modloaderVersion) return false;
}
return true;
});
}
}
function downloadMods() {
function downloadMods() {
if(!downloadStarted) {
downloadStarted = true;
save_mods_lock = Object.fromEntries(dep);
globCallback();
globCallback(Object.fromEntries(dep));
dep.forEach((mod, modId) => {
getData(modId, (data) => {
let path = `mods/${data.name}.jar`
@ -78,9 +74,9 @@ function downloadMods() {
});
});
}
}
}
function downloadFile(url, dest) {
function downloadFile(url, dest) {
let file = fs.createWriteStream(dest);
console.log(`downloading... ${url}`);
let request = https.get(url, (response) => {
@ -105,9 +101,11 @@ function downloadFile(url, dest) {
fs.unlink(dest);
throw err;
});
}
}
module.exports = function(saved_mods_lock, mods_lock_p, callback) {
var save_mods_lock = saved_mods_lock;
var mods_lock = mods_lock_p;
module.exports = function(mods_lock_p, callback) {
mods_lock = mods_lock_p;
console.log(mods_lock);
globCallback = callback;
main();
};

View File

@ -9,14 +9,22 @@ switch(process.argv.length) {
default:
throw "unexpected argument";
}
const modLockPath = "mods-lock.json";
let save_mods_lock = {};
let modsLock = JSON.parse(fs.readFileSync(modLockPath, "utf-8"));
const numberCallback = 2;
const modLockPath = "mods-lock.json";
let modsLock;
try {
modsLock = JSON.parse(fs.readFileSync(modLockPath, "utf-8"));
}
catch(err) {
if(err.errno !== -2) throw err;
modsLock = {curse: new Map()};
}
const numberCallback = 1;
let callbackCounter = 0;
require("./curse.js")(save_mods_lock.curse, modsLock.curse, finnish);
require("./curse.js")(modsLock.curse, finnish);
function finnish() {
function finnish(curse) {
save_mods_lock.curse = curse;
if(++callbackCounter == numberCallback) {
fs.writeFile(modLockPath, JSON.stringify(save_mods_lock), (err) => {
if(err) throw err;