From 5d7283240270277805f3733330f7287e9005a285 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Thu, 11 Jan 2018 21:44:23 +0100 Subject: [PATCH] #59 added node client.js manage mods shared/instance remove modname --- client.js | 2 ++ lib/manager/modManager.js | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/client.js b/client.js index 5a376305..07bb8d21 100644 --- a/client.js +++ b/client.js @@ -146,6 +146,8 @@ if (!command || command == "help" || command == "--help") { modManager.findMods(process.argv[6]); } else if(action == "add" || action == "download"){ modManager.addMod(process.argv[6], instance); + } else if(action == "remove" || action == "rm" || action == "delete"){ + modManager.removeMod(process.argv[6], instance); } else if(action == "update"){ modManager.updateAllMods(); } else { diff --git a/lib/manager/modManager.js b/lib/manager/modManager.js index 8d4a6025..02b14654 100644 --- a/lib/manager/modManager.js +++ b/lib/manager/modManager.js @@ -6,7 +6,8 @@ Provides tools to manage mods in a clusterio install const rightpad = require("right-pad"); const asTable = require("as-table").configure({delimiter: ' | '}); const moment = require("moment"); -const syncRequest = require("sync-request") +const syncRequest = require("sync-request"); +const fs = require("fs"); const factorioAPI = require("node-factorio-api"); const fileOps = require("./../fileOps.js"); @@ -138,6 +139,27 @@ module.exports.addMod = function(term, instance){ } } } +module.exports.removeMod = function removeMod(term, instance, force = false){ + if(instance == "shared"){ // modDirectory has to end in / + var modDirectory = "sharedMods/"; + } else { + var modDirectory = "instances/"+instance+"/instanceMods/"; + } + if(term && typeof term == "string" && term.length > 0){ + let mods = fs.readdirSync(modDirectory); + let modsMatchingFilter = mods.filter(mod => mod.includes(term)); + if(modsMatchingFilter.length < 1){ + console.log("No mods found matching search"); + } else if(modsMatchingFilter.length == 1){ + console.log("Deleting "+modsMatchingFilter[0]); + fs.unlinkSync(modDirectory+modsMatchingFilter[0]); + console.log("Deleted."); + } else if(modsMatchingFilter.length > 1){ + console.log("Found multiple mods, not doing anything"); + modsMatchingFilter.forEach(mod => console.log(mod)); + } + } +} /** Searches mods.factorio.com for mods matching a search term and prints the results to console as a neat looking table