fixed deleting mod twice

This commit is contained in:
2021-01-21 16:22:00 +01:00
parent 7a0ae4eb99
commit 1e526899ad
3 changed files with 37 additions and 88 deletions

82
package-lock.json generated
View File

@ -4,25 +4,6 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"flex-exec": { "flex-exec": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/flex-exec/-/flex-exec-1.0.0.tgz", "resolved": "https://registry.npmjs.org/flex-exec/-/flex-exec-1.0.0.tgz",
@ -33,11 +14,6 @@
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
"integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==" "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
}, },
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"gift": { "gift": {
"version": "0.10.2", "version": "0.10.2",
"resolved": "https://registry.npmjs.org/gift/-/gift-0.10.2.tgz", "resolved": "https://registry.npmjs.org/gift/-/gift-0.10.2.tgz",
@ -47,68 +23,28 @@
"underscore": "^1.8.3" "underscore": "^1.8.3"
} }
}, },
"glob": { "gradle-to-js": {
"version": "7.1.6", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", "resolved": "https://registry.npmjs.org/gradle-to-js/-/gradle-to-js-2.0.0.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "integrity": "sha512-eoYJiSoreHG0cS5aUmv7ISJhajuULlqdqG3QKVti6x1EFkBXE8rGH6ipGKWEesXpCkfNgzBrhzo5ztIH1JWZMw==",
"requires": { "requires": {
"fs.realpath": "^1.0.0", "lodash.merge": "4.6.2"
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
} }
}, },
"inflight": { "lodash.merge": {
"version": "1.0.6", "version": "4.6.2",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "^1.1.7"
}
}, },
"node-json-minify": { "node-json-minify": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-json-minify/-/node-json-minify-1.0.0.tgz", "resolved": "https://registry.npmjs.org/node-json-minify/-/node-json-minify-1.0.0.tgz",
"integrity": "sha1-e7NDL5ZYtr6x2ZP9XVOzyinQ15w=" "integrity": "sha1-e7NDL5ZYtr6x2ZP9XVOzyinQ15w="
}, },
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"underscore": { "underscore": {
"version": "1.12.0", "version": "1.12.0",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.0.tgz", "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.0.tgz",
"integrity": "sha512-21rQzss/XPMjolTiIezSu3JAjgagXKROtNrYFEOWK109qY1Uv2tVjPTZ1ci2HgvQDA16gHYSthQIJfB+XId/rQ==" "integrity": "sha512-21rQzss/XPMjolTiIezSu3JAjgagXKROtNrYFEOWK109qY1Uv2tVjPTZ1ci2HgvQDA16gHYSthQIJfB+XId/rQ=="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
} }
} }
} }

View File

@ -15,7 +15,7 @@
"dependencies": { "dependencies": {
"follow-redirects": "^1.13.0", "follow-redirects": "^1.13.0",
"gift": "^0.10.2", "gift": "^0.10.2",
"glob": "^7.1.6", "gradle-to-js": "^2.0.0",
"node-json-minify": "^1.0.0" "node-json-minify": "^1.0.0"
} }
} }

View File

@ -2,6 +2,7 @@ const git = require("gift");
const glob = require("glob"); const glob = require("glob");
const childProcess = require("child_process"); const childProcess = require("child_process");
const fs = require("fs"); const fs = require("fs");
const g2js = require('gradle-to-js/lib/parser');
let modsLock; let modsLock;
let globCallback; let globCallback;
let loopCounter = 0; let loopCounter = 0;
@ -32,11 +33,13 @@ function main () {
} }
}); });
}); });
deleteMods.forEach((mod) => { deleteMods.forEach((mod, url) => {
fs.unlink(mod.filename, (err) => { modsLock.delete(url);
fs.unlink(modPath(mod.filename), (err) => {
if(err) throw err; if(err) throw err;
}); });
}); });
mayCb();
} }
function build(repo, repoPath, gitRepo) { function build(repo, repoPath, gitRepo) {
@ -47,32 +50,42 @@ function build(repo, repoPath, gitRepo) {
} }
repo.current_commit((err, commit) => { repo.current_commit((err, commit) => {
if(err) throw err; if(err) throw err;
if(commit.id === newLock.commitId) mayCb(); if(commit.id === newLock.commitId) cbDecrease();
else { else {
newLock.commitId = commit.id; newLock.commitId = commit.id;
childProcess.execFile("gradle", ["build"], {cwd: repoPath}, (err) => { childProcess.execFile("gradle", ["build"], {cwd: repoPath}, (err) => {
if(err) throw err; if(err) throw err;
let buildPath = `${repoPath}/build/libs`; let buildPath = `${repoPath}/build/libs`;
glob(gitRepo.fileMatch, {cwd: buildPath}, (err, files) => { fs.readFile(`${repoPath}/gradle.properties`, "utf-8", (err, data) => {
if(err) throw err; if(err) throw err;
if(files.length !== 1) throw `mod glob matched multiple or no files. mod:\n${JSON.stringify(gitRepo)}`; g2js.parseText(data).then((gradleProp) => {
modFile = files[0]; let modFile = `${gradleProp.archives_base_name}-${gradleProp.mod_version}.jar`;
if(newLock.filename != null) fs.unlink(`mods/${newLock.filename}`, (err) => { if(newLock.filename != null) fs.unlink(`mods/${newLock.filename}`, (err) => {
if(err) throw err; if(err) throw err;
});
fs.copyFile(`${buildPath}/${modFile}`, `mods/${modFile}`, (err) => {
if(err) throw err;
});
newLock.filename = modFile;
cbDecrease();
}); });
mayCb();
fs.copyFile(`${buildPath}/${modFile}`, `mods/${modFile}`, (err) => {
if(err) throw err;
});
newLock.filename = modFile;
}); });
}); });
} }
}); });
} }
function cbDecrease() {
--loopCounter;
mayCb();
}
function mayCb() { function mayCb() {
if(--loopCounter === 0) globCallback("git", Object.fromEntries(modsLock)); if(loopCounter <= 0) globCallback("git", Object.fromEntries(modsLock));
}
function modPath(filename) {
return `mods/${filename}`;
} }
module.exports = (mods_lock_p, cb) => { module.exports = (mods_lock_p, cb) => {