git support

builds mods with gradle from source
This commit is contained in:
2021-01-20 18:15:13 +01:00
parent 0b6fc9174e
commit fbf7551fc2
4 changed files with 178 additions and 4 deletions

96
package-lock.json generated
View File

@ -4,15 +4,111 @@
"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",
"integrity": "sha1-BpdLaFMoOdKhLDLevNsSN4IA/fA="
},
"follow-redirects": {
"version": "1.13.0",
"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",
"integrity": "sha512-wC9aKnQpjfOTWX+JG4DPJkS89ux6sl8EN4hXhv/2vBoXCDTEz1JiTeGTSeuKYlCqIgUFM1JwPVym34Sys3hvzw==",
"requires": {
"flex-exec": "^1.0.0",
"underscore": "^1.8.3"
}
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"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"
}
},
"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"
}
},
"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="
}
}
}

View File

@ -14,6 +14,8 @@
"license": "LGPL-3.0",
"dependencies": {
"follow-redirects": "^1.13.0",
"gift": "^0.10.2",
"glob": "^7.1.6",
"node-json-minify": "^1.0.0"
}
}

75
src/git.js Normal file
View File

@ -0,0 +1,75 @@
const git = require("gift");
const glob = require("glob");
const childProcess = require("child_process");
const fs = require("fs");
let modsLock;
let globCallback;
let loopCounter = 0;
function main () {
modsLock = new Map(Object.entries(modsLock));
let cacheDir = process.env.XDG_CACHE_HOME;
if(cacheDir == null) cacheDir = `${process.env.HOME}/.cache`;
let repoPathRoot = `${cacheDir}/minecraft-mod-packager`;
global.config.mods.git.forEach((gitRepo) => {
++loopCounter;
let repoPath = `${repoPathRoot}/${gitRepo.url.replace("://", "+")}/${gitRepo.branch}`;
fs.access(repoPath, (err) => {
if(err) {
if(err.code !== "ENOENT") throw err;
git.clone(gitRepo.url, repoPath, undefined, gitRepo.branch, (err, repo) => {
if(err) throw err;
build(repo, repoPath, gitRepo);
});
}
else {
let repo = git(repoPath);
repo.pull(["origin"], gitRepo.branch, (err) => {
if(err) throw err;
build(repo, repoPath, gitRepo);
});
}
});
});
}
function build(repo, repoPath, gitRepo) {
if(modsLock.has(gitRepo.url)) newLock = modsLock.get(gitRepo.url);
else {
newLock = {};
modsLock.set(gitRepo.url, newLock);
}
repo.current_commit((err, commit) => {
if(err) throw err;
if(commit.id === newLock.commitId) mayCb();
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) => {
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;
});
mayCb();
fs.copyFile(`${buildPath}/${modFile}`, `mods/${modFile}`, (err) => {
if(err) throw err;
});
newLock.filename = modFile;
});
});
}
});
}
function mayCb() {
if(--loopCounter === 0) globCallback("git", Object.fromEntries(modsLock));
}
module.exports = (mods_lock_p, cb) => {
globCallback = cb;
modsLock = mods_lock_p;
main()
}

View File

@ -17,14 +17,15 @@ try {
}
catch(err) {
if(err.errno !== -2) throw err;
modsLock = {curse: new Map()};
modsLock = {curse: {}, git: {}};
}
const numberCallback = 1;
const numberCallback = 2;
let callbackCounter = 0;
require("./curse.js")(modsLock.curse, finnish);
require("./git.js")(modsLock.git, finnish);
function finnish(curse) {
save_mods_lock.curse = curse;
function finnish(name, data) {
save_mods_lock[name] = data;
if(++callbackCounter == numberCallback) {
fs.writeFile(modLockPath, JSON.stringify(save_mods_lock), (err) => {
if(err) throw err;