mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
configManager.js - more useful return values
This commit is contained in:
1 parent
5630f7f7f6
commit
1faa3671e4
2 files changed
+13
-3
No files matched your search
@@ -15,6 +15,9 @@ console.log()s each entry in the config
|
|||||||
@param {string} instance Either undefined, "shared" or the instance to show the config for.
|
@param {string} instance Either undefined, "shared" or the instance to show the config for.
|
||||||
*/
|
*/
|
||||||
module.exports.displayConfig = function(instance){
|
module.exports.displayConfig = function(instance){
|
||||||
|
console.log(asTable(this.getConfig(instance)));
|
||||||
|
}
|
||||||
|
module.exports.getConfig = async function(instance){
|
||||||
if(!instance || instance == "shared"){
|
if(!instance || instance == "shared"){
|
||||||
let configArray = [];
|
let configArray = [];
|
||||||
Object.keys(config).forEach(key=>{
|
Object.keys(config).forEach(key=>{
|
||||||
@@ -24,7 +27,7 @@ module.exports.displayConfig = function(instance){
|
|||||||
} else configArray.push({entry: key, value: config[key]});
|
} else configArray.push({entry: key, value: config[key]});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(asTable(configArray));
|
return configArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports.editConfig = function(instance, entry, newValue){
|
module.exports.editConfig = function(instance, entry, newValue){
|
||||||
@@ -36,12 +39,20 @@ module.exports.editConfig = function(instance, entry, newValue){
|
|||||||
console.log("new config file:");
|
console.log("new config file:");
|
||||||
console.log(JSON.stringify(config, null, " "))
|
console.log(JSON.stringify(config, null, " "))
|
||||||
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
||||||
|
return {
|
||||||
|
ok:true,
|
||||||
|
msg:`Changed config entry ${entry} from Object to ${JSON.stringify(newValue)}`,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
config[entry] = newValue;
|
config[entry] = newValue;
|
||||||
console.log("Changed config entry "+entry+" from "+config[entry]+" to '"+newValue+"'");
|
console.log("Changed config entry "+entry+" from "+config[entry]+" to '"+newValue+"'");
|
||||||
console.log("new config file:");
|
console.log("new config file:");
|
||||||
console.log(JSON.stringify(config, null, " "))
|
console.log(JSON.stringify(config, null, " "))
|
||||||
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
|
||||||
|
return {
|
||||||
|
ok:true,
|
||||||
|
msg:`Changed config entry ${entry} from ***** to '${newValue}'`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const rightpad = require("right-pad");
|
|||||||
const asTable = require("as-table").configure({delimiter: ' | '});
|
const asTable = require("as-table").configure({delimiter: ' | '});
|
||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
const syncRequest = require("sync-request");
|
const syncRequest = require("sync-request");
|
||||||
const fs = require("fs");
|
const fs = require("fs-extra");
|
||||||
const https = require('follow-redirects').https;
|
const https = require('follow-redirects').https;
|
||||||
const factorioAPI = require("node-factorio-api");
|
const factorioAPI = require("node-factorio-api");
|
||||||
const sLog = require("single-line-log").stdout;
|
const sLog = require("single-line-log").stdout;
|
||||||
@@ -27,7 +27,6 @@ function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","
|
|||||||
module.exports = function(config){
|
module.exports = function(config){
|
||||||
if(!config) config = require("./../../config");
|
if(!config) config = require("./../../config");
|
||||||
const instances = require("./../getInstances.js")(config).sync();
|
const instances = require("./../getInstances.js")(config).sync();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
Lists mods for an instance as a table. Warning, handles printing internally.
|
Lists mods for an instance as a table. Warning, handles printing internally.
|
||||||
|
|||||||
Reference in new issue
Block a user