From 1e526899ad60ad15175249a00306d6386168c445 Mon Sep 17 00:00:00 2001 From: MrGeorgen Date: Thu, 21 Jan 2021 16:22:00 +0100 Subject: [PATCH] fixed deleting mod twice --- package-lock.json | 82 ++++++----------------------------------------- package.json | 2 +- src/git.js | 41 ++++++++++++++++-------- 3 files changed, 37 insertions(+), 88 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0e12d93..b279b3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,25 +4,6 @@ "lockfileVersion": 1, "requires": true, "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": { "version": "1.0.0", "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", "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": { "version": "0.10.2", "resolved": "https://registry.npmjs.org/gift/-/gift-0.10.2.tgz", @@ -47,68 +23,28 @@ "underscore": "^1.8.3" } }, - "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "gradle-to-js": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/gradle-to-js/-/gradle-to-js-2.0.0.tgz", + "integrity": "sha512-eoYJiSoreHG0cS5aUmv7ISJhajuULlqdqG3QKVti6x1EFkBXE8rGH6ipGKWEesXpCkfNgzBrhzo5ztIH1JWZMw==", "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "lodash.merge": "4.6.2" } }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "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" - } + "lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" }, "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=" }, - "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": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.0.tgz", "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=" } } } diff --git a/package.json b/package.json index c19e621..8f3d7f1 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "dependencies": { "follow-redirects": "^1.13.0", "gift": "^0.10.2", - "glob": "^7.1.6", + "gradle-to-js": "^2.0.0", "node-json-minify": "^1.0.0" } } diff --git a/src/git.js b/src/git.js index 41fa525..8e32f51 100644 --- a/src/git.js +++ b/src/git.js @@ -2,6 +2,7 @@ const git = require("gift"); const glob = require("glob"); const childProcess = require("child_process"); const fs = require("fs"); +const g2js = require('gradle-to-js/lib/parser'); let modsLock; let globCallback; let loopCounter = 0; @@ -32,11 +33,13 @@ function main () { } }); }); - deleteMods.forEach((mod) => { - fs.unlink(mod.filename, (err) => { + deleteMods.forEach((mod, url) => { + modsLock.delete(url); + fs.unlink(modPath(mod.filename), (err) => { if(err) throw err; }); }); + mayCb(); } function build(repo, repoPath, gitRepo) { @@ -47,32 +50,42 @@ function build(repo, repoPath, gitRepo) { } repo.current_commit((err, commit) => { if(err) throw err; - if(commit.id === newLock.commitId) mayCb(); + if(commit.id === newLock.commitId) cbDecrease(); else { newLock.commitId = commit.id; childProcess.execFile("gradle", ["build"], {cwd: repoPath}, (err) => { if(err) throw err; 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(files.length !== 1) throw `mod glob matched multiple or no files. mod:\n${JSON.stringify(gitRepo)}`; - modFile = files[0]; - if(newLock.filename != null) fs.unlink(`mods/${newLock.filename}`, (err) => { - if(err) throw err; + g2js.parseText(data).then((gradleProp) => { + let modFile = `${gradleProp.archives_base_name}-${gradleProp.mod_version}.jar`; + if(newLock.filename != null) fs.unlink(`mods/${newLock.filename}`, (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() { - 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) => {