mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Remove unused config parameter to pluginManager
Remove the unused library initialization parameter config to pluginManager and reorganize pluginManager to no longer be defined by a function.
This commit is contained in:
1 parent
35546b4b18
commit
a31778c7ff
4 files changed
+110
-102
No files matched your search
@@ -18,6 +18,7 @@ const objectOps = require("lib/objectOps.js");
|
|||||||
const fileOps = require("lib/fileOps");
|
const fileOps = require("lib/fileOps");
|
||||||
const stringUtils = require("lib/stringUtils.js");
|
const stringUtils = require("lib/stringUtils.js");
|
||||||
const configManager = require("lib/manager/configManager.js");
|
const configManager = require("lib/manager/configManager.js");
|
||||||
|
const pluginManager = require("lib/manager/pluginManager");
|
||||||
const hashFile = require('lib/hash').hashFile;
|
const hashFile = require('lib/hash').hashFile;
|
||||||
|
|
||||||
console.warn(`
|
console.warn(`
|
||||||
@@ -235,7 +236,6 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
}
|
}
|
||||||
} else if(tool == "plugins"){
|
} else if(tool == "plugins"){
|
||||||
(async function(){try{
|
(async function(){try{
|
||||||
const pluginManager = require("lib/manager/pluginManager.js")(config);
|
|
||||||
if(action == "list"){
|
if(action == "list"){
|
||||||
await pluginManager.listPlugins();
|
await pluginManager.listPlugins();
|
||||||
} else if(action == "add" || action == "install" || action == "download"){
|
} else if(action == "add" || action == "install" || action == "download"){
|
||||||
@@ -587,7 +587,6 @@ async function instanceManagement(instanceconfig) {
|
|||||||
setInterval(B=> socket.emit("heartbeat"), 10000);
|
setInterval(B=> socket.emit("heartbeat"), 10000);
|
||||||
|
|
||||||
// load plugins and execute onLoad event
|
// load plugins and execute onLoad event
|
||||||
const pluginManager = require("lib/manager/pluginManager.js")(config);
|
|
||||||
let pluginsToLoad = await pluginManager.getPlugins();
|
let pluginsToLoad = await pluginManager.getPlugins();
|
||||||
let plugins = [];
|
let plugins = [];
|
||||||
|
|
||||||
|
|||||||
+107
-98
@@ -3,114 +3,123 @@ const path = require("path");
|
|||||||
const git = require("simple-git")("./sharedPlugins");
|
const git = require("simple-git")("./sharedPlugins");
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(config){
|
async function listPlugins() {
|
||||||
if(!config) config = require("./../../config");
|
let plugins = await this.getPlugins();
|
||||||
|
plugins.forEach(plug => {
|
||||||
return {
|
console.log(`${plug.name}`.padEnd(22).substr(0,22)+` - ${plug.description}`.substr(0,80-22));
|
||||||
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));
|
async function getPlugins() {
|
||||||
});
|
let directories = await fs.readdir("./sharedPlugins");
|
||||||
},
|
let returnArray = [];
|
||||||
getPlugins: async function(){
|
for(let i in directories){
|
||||||
let directories = await fs.readdir("./sharedPlugins");
|
let dir = directories[i];
|
||||||
let returnArray = [];
|
let pluginContents = await fs.readdir(path.join("./sharedPlugins", dir));
|
||||||
for(let i in directories){
|
// console.log(pluginContents)
|
||||||
let dir = directories[i];
|
if(pluginContents.includes("config.js") || pluginContents.includes("config.json")){
|
||||||
let pluginContents = await fs.readdir(path.join("./sharedPlugins", dir));
|
try{
|
||||||
// console.log(pluginContents)
|
var pluginConfig = require(path.join("./../../sharedPlugins", dir, "config"));
|
||||||
if(pluginContents.includes("config.js") || pluginContents.includes("config.json")){
|
pluginConfig.pluginPath = path.join("./sharedPlugins", dir);
|
||||||
try{
|
}catch(e){
|
||||||
var pluginConfig = require(path.join("./../../sharedPlugins", dir, "config"));
|
console.log(e)
|
||||||
pluginConfig.pluginPath = path.join("./sharedPlugins", dir);
|
|
||||||
}catch(e){
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if plugin is enabled
|
|
||||||
try{
|
|
||||||
await fs.stat(path.join(pluginConfig.pluginPath, "DISABLED"))
|
|
||||||
pluginConfig.enabled = false;
|
|
||||||
}catch(e){
|
|
||||||
pluginConfig.enabled = true;
|
|
||||||
}
|
|
||||||
returnArray.push(pluginConfig);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return returnArray;
|
|
||||||
},
|
// check if plugin is enabled
|
||||||
addPlugin: function(path){
|
try{
|
||||||
return new Promise((resolve, reject) => {
|
await fs.stat(path.join(pluginConfig.pluginPath, "DISABLED"))
|
||||||
if(path.includes("git")){ // we are decently sure this is a git repo
|
pluginConfig.enabled = false;
|
||||||
git.clone(path, data => resolve(data))
|
}catch(e){
|
||||||
}
|
pluginConfig.enabled = true;
|
||||||
});
|
|
||||||
},
|
|
||||||
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}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
returnArray.push(pluginConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPlugin(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))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removePlugin(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 {
|
return {
|
||||||
ok:false,
|
ok:true,
|
||||||
msg:`Plugin matching "${name}" not found`,
|
msg:`Deleted plugin ${plug.name}`
|
||||||
}
|
|
||||||
},
|
|
||||||
enablePlugin: async function(name, instance){
|
|
||||||
let plugins = await this.getPlugins();
|
|
||||||
let plugin = plugins[findInArray("name", name, plugins)[0]];
|
|
||||||
if(plugin){
|
|
||||||
let files = await fs.readdir(plugin.pluginPath);
|
|
||||||
if(files.includes("DISABLED")){
|
|
||||||
await fs.unlink(path.join(plugin.pluginPath, "DISABLED"));
|
|
||||||
return {
|
|
||||||
ok:true,
|
|
||||||
msg:`Globally enabled plugin ${name}`,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
ok:true,
|
|
||||||
msg:`Plugin ${name} already enabled`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
ok:false,
|
|
||||||
msg:`Found no excact match for plugin ${name}`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
disablePlugin: async function(name, instance){
|
|
||||||
let plugins = await this.getPlugins();
|
|
||||||
let plugin = plugins[findInArray("name", name, plugins)[0]];
|
|
||||||
if(plugin){
|
|
||||||
await fs.writeFile(path.join(plugin.pluginPath, "DISABLED"), "");
|
|
||||||
return {
|
|
||||||
ok:true,
|
|
||||||
msg:`Plugin ${name} is now disabled on this host`,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
ok:false,
|
|
||||||
msg:`Found no excact match for plugin ${name}`,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
ok:false,
|
||||||
|
msg:`Plugin matching "${name}" not found`,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function findInArray(key, value, array){
|
|
||||||
|
async function enablePlugin(name, instance) {
|
||||||
|
let plugins = await this.getPlugins();
|
||||||
|
let plugin = plugins[findInArray("name", name, plugins)[0]];
|
||||||
|
if(plugin){
|
||||||
|
let files = await fs.readdir(plugin.pluginPath);
|
||||||
|
if(files.includes("DISABLED")){
|
||||||
|
await fs.unlink(path.join(plugin.pluginPath, "DISABLED"));
|
||||||
|
return {
|
||||||
|
ok:true,
|
||||||
|
msg:`Globally enabled plugin ${name}`,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
ok:true,
|
||||||
|
msg:`Plugin ${name} already enabled`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
ok:false,
|
||||||
|
msg:`Found no excact match for plugin ${name}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function disablePlugin(name, instance) {
|
||||||
|
let plugins = await this.getPlugins();
|
||||||
|
let plugin = plugins[findInArray("name", name, plugins)[0]];
|
||||||
|
if(plugin){
|
||||||
|
await fs.writeFile(path.join(plugin.pluginPath, "DISABLED"), "");
|
||||||
|
return {
|
||||||
|
ok:true,
|
||||||
|
msg:`Plugin ${name} is now disabled on this host`,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
ok:false,
|
||||||
|
msg:`Found no excact match for plugin ${name}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findInArray(key, value, array) {
|
||||||
let indexes = [];
|
let indexes = [];
|
||||||
for(let i in array){
|
for(let i in array){
|
||||||
if(array[i][key] && array[i][key] === value) indexes.push(i);
|
if(array[i][key] && array[i][key] === value) indexes.push(i);
|
||||||
}
|
}
|
||||||
return indexes;
|
return indexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
listPlugins,
|
||||||
|
getPlugins,
|
||||||
|
addPlugin,
|
||||||
|
removePlugin,
|
||||||
|
enablePlugin,
|
||||||
|
disablePlugin,
|
||||||
|
};
|
||||||
@@ -33,6 +33,7 @@ let config = {};
|
|||||||
// homebrew modules
|
// homebrew modules
|
||||||
const generateSSLcert = require("lib/generateSSLcert");
|
const generateSSLcert = require("lib/generateSSLcert");
|
||||||
const getFactorioLocale = require("lib/getFactorioLocale");
|
const getFactorioLocale = require("lib/getFactorioLocale");
|
||||||
|
const pluginManager = require("lib/manager/pluginManager.js");
|
||||||
const database = require("lib/database");
|
const database = require("lib/database");
|
||||||
|
|
||||||
// homemade express middleware for token auth
|
// homemade express middleware for token auth
|
||||||
@@ -800,7 +801,6 @@ async function pluginManagement(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getPlugins(){
|
async function getPlugins(){
|
||||||
const pluginManager = require("lib/manager/pluginManager.js")(config);
|
|
||||||
let plugins = [];
|
let plugins = [];
|
||||||
let pluginsToLoad = await pluginManager.getPlugins();
|
let pluginsToLoad = await pluginManager.getPlugins();
|
||||||
for(let i = 0; i < pluginsToLoad.length; i++){
|
for(let i = 0; i < pluginsToLoad.length; i++){
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ module.exports = class remoteCommands {
|
|||||||
this.messageInterface = messageInterface;
|
this.messageInterface = messageInterface;
|
||||||
this.config = mergedConfig;
|
this.config = mergedConfig;
|
||||||
this.socket = extras.socket;
|
this.socket = extras.socket;
|
||||||
const pluginManager = require("lib/manager/pluginManager.js")(this.config);
|
const pluginManager = require("lib/manager/pluginManager.js");
|
||||||
const configManager = require("lib/manager/configManager.js");
|
const configManager = require("lib/manager/configManager.js");
|
||||||
// const modManager = require("lib/manager/modManager.js")(this.config);
|
// const modManager = require("lib/manager/modManager.js")(this.config);
|
||||||
this.socket.on("hello", () => {
|
this.socket.on("hello", () => {
|
||||||
|
|||||||
Reference in new issue
Block a user