modPath utils function

returns modPath from a mod object
This commit is contained in:
2021-01-21 21:38:41 +01:00
parent 54cfb222b9
commit 2d1de103d8
3 changed files with 15 additions and 11 deletions

View File

@ -1,6 +1,7 @@
let mods_lock;
const { http, https } = require('follow-redirects'); const { http, https } = require('follow-redirects');
const fs = require("fs"); const fs = require("fs");
const util = require("./util.js");
let mods_lock;
let downloadStarted = false; let downloadStarted = false;
let dep = new Map(); let dep = new Map();
function main() { function main() {
@ -104,7 +105,7 @@ function downloadFile(url, dest) {
}); });
file.on('error', (err) => { // Handle errors file.on('error', (err) => { // Handle errors
fs.unlink(dest); fs.unlink(dest, () => {});
throw err; throw err;
}); });
} }

View File

@ -2,6 +2,7 @@ const git = require("gift");
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'); const g2js = require('gradle-to-js/lib/parser');
const util = require("./util.js");
let modsLock; let modsLock;
let globCallback; let globCallback;
let loopCounter = 0; let loopCounter = 0;
@ -34,7 +35,7 @@ function main () {
}); });
deleteMods.forEach((mod, url) => { deleteMods.forEach((mod, url) => {
modsLock.delete(url); modsLock.delete(url);
fs.unlink(modPath(mod.filename), (err) => { fs.unlink(util.modPath(mod), (err) => {
if(err) throw err; if(err) throw err;
}); });
}); });
@ -58,14 +59,13 @@ function build(repo, repoPath, gitRepo) {
fs.readFile(`${repoPath}/gradle.properties`, "utf-8", (err, data) => { fs.readFile(`${repoPath}/gradle.properties`, "utf-8", (err, data) => {
if(err) throw err; if(err) throw err;
g2js.parseText(data).then((gradleProp) => { g2js.parseText(data).then((gradleProp) => {
let modFile = `${gradleProp.archives_base_name}-${gradleProp.mod_version}.jar`; if(newLock.filename != null) fs.unlink(util.modPath(newLock) (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) => { newLock.filename = `${gradleProp.archives_base_name}-${gradleProp.mod_version}.jar`;
fs.copyFile(`${buildPath}/${newLock.filename}`, util.modPath(newLock) (err) => {
if(err) throw err; if(err) throw err;
}); });
newLock.filename = modFile;
cbDecrease(); cbDecrease();
}); });
}); });
@ -83,10 +83,6 @@ 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) => {
globCallback = cb; globCallback = cb;
modsLock = mods_lock_p; modsLock = mods_lock_p;

7
src/util.js Normal file
View File

@ -0,0 +1,7 @@
function modPath(mod) {
return `mods${mod.filename}`;
}
module.exports = {
modPath: modPath
}