More mod manager stuff, node client.js list is more informative

Now shows nice table with name and port to connect to
This commit is contained in:
Danielv123 committed 2017-11-03 22:54:52 +01:00
1 parent 1eeb289669
commit 8cf85f3ecc
3 files changed
+63 -4

No files matched your search

+45 -4
View File
@@ -16,7 +16,7 @@ const getMac = require('getmac').getMac;
const objectOps = require("./lib/objectOps.js");
const fileOps = require("./lib/fileOps.js");
const stringUtils = require("./lib/stringUtils.js");
const modManager = require("./lib/modManager/modManager.js");
const modManager = require("./lib/manager/modManager.js");
// require config.json
var config = require('./config');
@@ -79,9 +79,50 @@ if (!command || command == "help" || command == "--help") {
console.error("node client.js download");
process.exit(1);
} else if (command == "list") {
console.dir(fileOps.getDirectoriesSync("./instances/"));
let instanceNames = fileOps.getDirectoriesSync("./instances/");
instanceNames.unshift("Name:");
let longestInstanceName = 0;
// determine longest instance name
instanceNames.forEach(function(instance){
if(instance.length > longestInstanceName) longestInstanceName = instance.length;
});
let displayLines = [];
// push name coloumn to array
instanceNames.forEach(function(instance){
while(instance.length < longestInstanceName+1){
instance += " ";
}
displayLines.push("| "+ instance + "|");
});
// create port colloumn
let factorioPorts = [];
instanceNames.forEach(function(instance){
let factorioPort
if(instance.includes("Name:")){
factorioPort = "Port:"
} else {
factorioPort = require("./instances/"+instance+"/config").factorioPort;
}
factorioPorts.push(factorioPort);
});
factorioPorts.forEach((port, index) => {
let longestPort = 0;
factorioPorts.forEach((port, index) => {
if(port.toString().length > longestPort) longestPort = port.toString().length;
});
while(port.toString().length < longestPort){
port += " ";
}
factorioPorts[index] = port;
});
instanceNames.forEach(function(instance, index){
displayLines[index] += " " + factorioPorts[index] + " |";
});
displayLines.forEach(line => console.log(line));
process.exit(1);
} else if (command == "modManager") {
} else if (command == "manage"){
console.log("Launching mod manager");
modManager.listMods(instance);
@@ -108,7 +149,7 @@ if (!command || command == "help" || command == "--help") {
if(url) {
console.log(url);
var file = fs.createWriteStream("sharedMods/"+name);
var request = https.get(url, function(response) {
var req = https.get(url, function(response) {
response.pipe(file);
console.log("Downloaded "+name);
});
@@ -28,3 +28,21 @@ module.exports.listMods = function(instance){
console.log(JSON.parse(res.getBody()))
*/
}
// 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases'
module.exports.downloadFromGitURL = function(url){
console.log("Downloading mod from "+url);
// get JSON data about releases
let res = syncRequest('GET', url, {"headers":{"User-Agent":"Please don't require setting a user agent"}});
let downloadUrl = JSON.parse(res.getBody())[0].assets[0].browser_download_url;
let name = JSON.parse(res.getBody())[0].assets[0].name;
console.log(JSON.parse(res.getBody()))
if(downloadUrl) {
console.log(downloadUrl);
var file = fs.createWriteStream("sharedMods/"+name);
var request = https.get(downloadUrl, function(response) {
response.pipe(file);
console.log("Downloaded "+name);
});
}
}
File renamed without changes.