mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Commandline tools to install/uninstall plugins from github
This commit is contained in:
1 parent
958cdfa15a
commit
8abeb26dce
3 files changed
+91
-3
No files matched your search
@@ -118,6 +118,8 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
console.error("node client.js delete [instance]");
|
console.error("node client.js delete [instance]");
|
||||||
console.error("To download the latest version of the Clusterio lua mod, do");
|
console.error("To download the latest version of the Clusterio lua mod, do");
|
||||||
console.error("node client.js manage shared mods download clusterio");
|
console.error("node client.js manage shared mods download clusterio");
|
||||||
|
console.error("To download a clusterio plugin, do");
|
||||||
|
console.error("node client.js manage shared plugins install https://github.com/Danielv123/playerManager");
|
||||||
console.error("For more management options, do");
|
console.error("For more management options, do");
|
||||||
console.error("node client.js manage");
|
console.error("node client.js manage");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@@ -173,8 +175,10 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
console.log('node client.js manage '+instance+' '+tool+' ["list", "search", "add", "remove", "update"]');
|
console.log('node client.js manage '+instance+' '+tool+' ["list", "search", "add", "remove", "update"]');
|
||||||
} else if(tool && tool == "config") {
|
} else if(tool && tool == "config") {
|
||||||
console.log('node client.js manage '+instance+' '+tool+' ["list", "edit"]');
|
console.log('node client.js manage '+instance+' '+tool+' ["list", "edit"]');
|
||||||
|
} else if(tool && tool == "plugins") {
|
||||||
|
console.log(`node client.js manage ${instance} ${tool} ["list", "add", "remove"]`);
|
||||||
} else {
|
} else {
|
||||||
console.log('node client.js manage '+(instance || '[instance, "shared"]') +' '+ (tool || '["mods", "config"]') + ' ...');
|
console.log('node client.js manage '+(instance || '[instance, "shared"]') +' '+ (tool || '["mods", "config", "plugins"]') + ' ...');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const tool = process.argv[4] || "";
|
const tool = process.argv[4] || "";
|
||||||
@@ -221,6 +225,22 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
} else {
|
} else {
|
||||||
usage(instance, tool);
|
usage(instance, tool);
|
||||||
}
|
}
|
||||||
|
} else if(tool == "plugins"){
|
||||||
|
(async function(){try{
|
||||||
|
const pluginManager = require("./lib/manager/pluginManager.js")(config);
|
||||||
|
if(action == "list"){
|
||||||
|
console.log(await pluginManager.listPlugins())
|
||||||
|
} else if(action == "add" || action == "install" || action == "download"){
|
||||||
|
let status = await pluginManager.addPlugin(process.argv[6]);
|
||||||
|
} else if(action == "remove" || action == "uninstall" || action == "delete"){
|
||||||
|
let status = await pluginManager.removePlugin(process.argv[6]);
|
||||||
|
if(status && status.msg) console.log(status.msg);
|
||||||
|
}
|
||||||
|
process.exit(0);
|
||||||
|
}catch(e){
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
}})();
|
||||||
} else {
|
} else {
|
||||||
usage(instance);
|
usage(instance);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
const fs = require("fs-extra");
|
||||||
|
const path = require("path");
|
||||||
|
const git = require("simple-git")("./sharedPlugins");
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function(config){
|
||||||
|
if(!config) config = require("./../../config");
|
||||||
|
|
||||||
|
return {
|
||||||
|
listPlugins: async function(){
|
||||||
|
let plugins = await this.getPlugins();
|
||||||
|
plugins.forEach(plug => {
|
||||||
|
console.log(`${plug.name}`.padEnd(22).substr(0,22)+` - ${plug.description}`.substr(0,80-22));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getPlugins: async function(){
|
||||||
|
let directories = await fs.readdir("./sharedPlugins");
|
||||||
|
let returnArray = [];
|
||||||
|
for(let i in directories){
|
||||||
|
let dir = directories[i];
|
||||||
|
let pluginContents = await fs.readdir(path.join("./sharedPlugins", dir));
|
||||||
|
// console.log(pluginContents)
|
||||||
|
if(pluginContents.includes("config.js") || pluginContents.includes("config.json")){
|
||||||
|
try{
|
||||||
|
let pluginConfig = require(path.join("./../../sharedPlugins", dir, "config"));
|
||||||
|
pluginConfig.pluginPath = path.join("./sharedPlugins", dir);
|
||||||
|
returnArray.push(pluginConfig);
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
|
},
|
||||||
|
addPlugin: function(path){
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if(path.includes("git")){ // we are decently sure this is a git repo
|
||||||
|
git.clone(path, data => resolve(data))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
removePlugin: async function(name){
|
||||||
|
let plugins = await this.getPlugins();
|
||||||
|
for(let i in plugins){
|
||||||
|
let plug = plugins[i];
|
||||||
|
if(plug.name.includes(name)){
|
||||||
|
// console.log(`Removing plugin ${plug.name}`);
|
||||||
|
await fs.remove(plug.pluginPath);
|
||||||
|
return {
|
||||||
|
ok:true,
|
||||||
|
msg:`Deleted plugin ${plug.name}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ok:false,
|
||||||
|
msg:`Plugin matching "${name}" not found`,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enablePlugin: function(){
|
||||||
|
|
||||||
|
},
|
||||||
|
disablePlugin: function(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -61,12 +61,13 @@
|
|||||||
"right-pad": "^1.0.1",
|
"right-pad": "^1.0.1",
|
||||||
"rmdir-sync": "^1.0.1",
|
"rmdir-sync": "^1.0.1",
|
||||||
"sanitizer": "^0.1.3",
|
"sanitizer": "^0.1.3",
|
||||||
|
"simple-git": "^1.96.0",
|
||||||
"single-line-log": "^1.1.2",
|
"single-line-log": "^1.1.2",
|
||||||
|
"snyk": "^1.88.0",
|
||||||
"socket.io": "^2.0.4",
|
"socket.io": "^2.0.4",
|
||||||
"socket.io-client": "^2.0.4",
|
"socket.io-client": "^2.0.4",
|
||||||
"sync-request": "^4.0.1",
|
"sync-request": "^4.0.1",
|
||||||
"underscore": "^1.8.3",
|
"underscore": "^1.8.3"
|
||||||
"snyk": "^1.88.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"documentation": "^5.4.0",
|
"documentation": "^5.4.0",
|
||||||
|
|||||||
Reference in new issue
Block a user