v1.18.x
barisusakli 10 years ago
parent f5b758245f
commit b51127bd9c

@ -34,8 +34,8 @@ var fs = require('fs'),
Plugins.initialized = false;
Plugins.requireLibrary = function(pluginData, libraryPath) {
Plugins.libraries[pluginData.id] = require(libraryPath);
Plugins.requireLibrary = function(pluginID, libraryPath) {
Plugins.libraries[pluginID] = require(libraryPath);
Plugins.libraryPaths.push(libraryPath);
};
@ -287,45 +287,32 @@ var fs = require('fs'),
async.waterfall([
function(next) {
async.parallel({
packageJSON: function(next) {
fs.readFile(path.join(file, 'package.json'), next);
},
pluginJSON: function(next) {
fs.readFile(path.join(file, 'plugin.json'), next);
}
}, next);
Plugins.loadPluginInfo(file, next);
},
function(results, next) {
var packageName = path.basename(file),
packageInfo, pluginInfo;
try {
packageInfo = JSON.parse(results.packageJSON);
pluginInfo = JSON.parse(results.pluginJSON);
} catch (err) {
function(pluginData, next) {
var packageName = path.basename(file);
if (!pluginData) {
winston.warn("Plugin `" + packageName + "` is corrupted or invalid. Please check either package.json or plugin.json for errors.");
return next(null, {
id: packageName,
installed: true,
error: true,
active: null
});
return next(null, {
id: packageName,
installed: true,
error: true,
active: null
});
}
Plugins.isActive(packageInfo.name, function(err, active) {
Plugins.isActive(pluginData.name, function(err, active) {
if (err) {
return next(new Error('no-active-state'));
}
delete pluginInfo.hooks;
delete pluginInfo.library;
pluginInfo.active = active;
pluginInfo.installed = true;
pluginInfo.error = false;
pluginInfo.version = packageInfo.version;
next(null, pluginInfo);
delete pluginData.hooks;
delete pluginData.library;
pluginData.active = active;
pluginData.installed = true;
pluginData.error = false;
next(null, pluginData);
});
}
], function(err, config) {

@ -31,7 +31,7 @@ module.exports = function(Plugins) {
if (typeof data.method === 'string' && data.method.length > 0) {
method = data.method.split('.').reduce(function(memo, prop) {
if (memo !== null && memo[prop]) {
if (memo && memo[prop]) {
return memo[prop];
} else {
// Couldn't find method by path, aborting

@ -12,20 +12,13 @@ var fs = require('fs'),
module.exports = function(Plugins) {
Plugins.loadPlugin = function(pluginPath, callback) {
fs.readFile(path.join(pluginPath, 'plugin.json'), function(err, data) {
Plugins.loadPluginInfo(pluginPath, function(err, pluginData) {
if (err) {
return callback(pluginPath.match('nodebb-theme') ? null : err);
}
var pluginData, staticDir;
try {
pluginData = JSON.parse(data);
} catch (err) {
var pluginDir = pluginPath.split(path.sep);
pluginDir = pluginDir[pluginDir.length -1];
winston.error('[plugins/' + pluginDir + '] Plugin not loaded - please check its plugin.json for errors');
var staticDir;
if (!pluginData) {
return callback();
}
@ -88,7 +81,7 @@ module.exports = function(Plugins) {
}
if (!Plugins.libraries[pluginData.id]) {
Plugins.requireLibrary(pluginData, libraryPath);
Plugins.requireLibrary(pluginData.id, libraryPath);
}
if (Array.isArray(pluginData.hooks) && pluginData.hooks.length > 0) {
@ -198,7 +191,35 @@ module.exports = function(Plugins) {
callback();
});
});
}
Plugins.loadPluginInfo = function(pluginPath, callback) {
async.parallel({
package: function(next) {
fs.readFile(path.join(pluginPath, 'package.json'), next);
},
plugin: function(next) {
fs.readFile(path.join(pluginPath, 'plugin.json'), next);
}
}, function(err, results) {
if (err) {
return callback(err);
}
try {
var pluginData = JSON.parse(results.plugin);
var packageData = JSON.parse(results.package);
var obj = utils.merge(pluginData, packageData);
obj.id = packageData.name;
callback(null, obj);
} catch(err) {
var pluginDir = pluginPath.split(path.sep);
pluginDir = pluginDir[pluginDir.length -1];
winston.error('[plugins/' + pluginDir + '] Error in plugin.json/package.json! ' + err.message);
callback();
}
});
};
};
Loading…
Cancel
Save