Merge branch 'master' into develop

This commit is contained in:
Julian Lam
2017-02-24 12:46:40 -05:00
449 changed files with 9202 additions and 6984 deletions

View File

@@ -1,7 +1,7 @@
'use strict';
var winston = require('winston'),
async = require('async');
var winston = require('winston');
var async = require('async');
module.exports = function (Plugins) {
Plugins.deprecatedHooks = {
@@ -10,7 +10,7 @@ module.exports = function (Plugins) {
'filter:user.profileLinks': 'filter:user.profileMenu',
'action:post.flag': 'action:flag.create',
'action:plugin.activate': null,
'action:plugin.install': null
'action:plugin.install': null,
};
/*
`data` is an object consisting of (* is required):
@@ -47,7 +47,7 @@ module.exports = function (Plugins) {
if (parts.length > 2) {
parts.pop();
}
var hook = parts.join(':');
parts.join(':');
}
if (data.hook && data.method) {
@@ -60,10 +60,9 @@ module.exports = function (Plugins) {
method = data.method.split('.').reduce(function (memo, prop) {
if (memo && memo[prop]) {
return memo[prop];
} else {
// Couldn't find method by path, aborting
return null;
}
// Couldn't find method by path, aborting
return null;
}, Plugins.libraries[data.id]);
// Write the actual method reference to the hookObj
@@ -86,18 +85,18 @@ module.exports = function (Plugins) {
var hookType = hook.split(':')[0];
switch (hookType) {
case 'filter':
fireFilterHook(hook, hookList, params, callback);
break;
case 'action':
fireActionHook(hook, hookList, params, callback);
break;
case 'static':
fireStaticHook(hook, hookList, params, callback);
break;
default:
winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook);
break;
case 'filter':
fireFilterHook(hook, hookList, params, callback);
break;
case 'action':
fireActionHook(hook, hookList, params, callback);
break;
case 'static':
fireStaticHook(hook, hookList, params, callback);
break;
default:
winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook);
break;
}
};
@@ -129,7 +128,6 @@ module.exports = function (Plugins) {
return callback();
}
async.each(hookList, function (hookObj, next) {
if (typeof hookObj.method !== 'function') {
if (global.env === 'development') {
winston.warn('[plugins] Expected method for hook \'' + hook + '\' in plugin \'' + hookObj.id + '\' not found, skipping.');
@@ -163,7 +161,7 @@ module.exports = function (Plugins) {
next.apply(null, arguments);
}
});
} catch(err) {
} catch (err) {
winston.error('[plugins] Error executing \'' + hook + '\' in plugin \'' + hookObj.id + '\'');
winston.error(err);
clearTimeout(timeoutId);

View File

@@ -13,7 +13,6 @@ var pubsub = require('../pubsub');
module.exports = function (Plugins) {
if (nconf.get('isPrimary') === 'true') {
pubsub.on('plugins:toggleInstall', function (data) {
if (data.hostname !== os.hostname()) {
@@ -51,22 +50,22 @@ module.exports = function (Plugins) {
function (next) {
meta.reloadRequired = true;
if (isActive) {
Plugins.fireHook('action:plugin.deactivate', {id: id});
Plugins.fireHook('action:plugin.deactivate', { id: id });
}
setImmediate(next);
}
},
], function (err) {
if (err) {
winston.warn('[plugins] Could not toggle active state on plugin \'' + id + '\'');
return callback(err);
}
callback(null, {id: id, active: !isActive});
callback(null, { id: id, active: !isActive });
});
};
Plugins.toggleInstall = function (id, version, callback) {
pubsub.publish('plugins:toggleInstall', {hostname: os.hostname(), id: id, version: version});
pubsub.publish('plugins:toggleInstall', { hostname: os.hostname(), id: id, version: version });
toggleInstall(id, version, callback);
};
@@ -82,7 +81,7 @@ module.exports = function (Plugins) {
},
function (active, next) {
if (active) {
Plugins.toggleActive(id, function (err, status) {
Plugins.toggleActive(id, function (err) {
next(err);
});
return;
@@ -97,11 +96,11 @@ module.exports = function (Plugins) {
},
function (pluginData, next) {
if (installed) {
Plugins.fireHook('action:plugin.uninstall', {id: id, version: version});
Plugins.fireHook('action:plugin.uninstall', { id: id, version: version });
}
setImmediate(next, null, pluginData);
}
},
], callback);
}
@@ -117,7 +116,7 @@ module.exports = function (Plugins) {
}
Plugins.upgrade = function (id, version, callback) {
pubsub.publish('plugins:upgrade', {hostname: os.hostname(), id: id, version: version});
pubsub.publish('plugins:upgrade', { hostname: os.hostname(), id: id, version: version });
upgrade(id, version, callback);
};
@@ -130,7 +129,7 @@ module.exports = function (Plugins) {
function (isActive, next) {
meta.reloadRequired = isActive;
next(null, isActive);
}
},
], callback);
}
@@ -149,4 +148,4 @@ module.exports = function (Plugins) {
Plugins.getActive = function (callback) {
db.getSortedSetRange('plugins:active', 0, -1, callback);
};
};
};

View File

@@ -59,7 +59,7 @@ module.exports = function (Plugins) {
async.apply(mapSoundpack, pluginData),
], next);
}, next);
}
},
], callback);
};
@@ -143,7 +143,7 @@ module.exports = function (Plugins) {
} else {
callback();
}
} catch(err) {
} catch (err) {
winston.error(err.stack);
winston.warn('[plugins] Unable to parse library for: ' + pluginData.id);
callback();
@@ -151,6 +151,8 @@ module.exports = function (Plugins) {
}
function mapStaticDirectories(pluginData, pluginPath, callback) {
var validMappedPath = /^[\w\-_]+$/;
function mapStaticDirs(mappedPath, callback) {
if (Plugins.staticDirs[mappedPath]) {
winston.warn('[plugins/' + pluginData.id + '] Mapped path (' + mappedPath + ') already specified!');
@@ -173,8 +175,6 @@ module.exports = function (Plugins) {
}
}
var validMappedPath = /^[\w\-_]+$/;
pluginData.staticDirs = pluginData.staticDirs || {};
var dirs = Object.keys(pluginData.staticDirs);
@@ -228,7 +228,7 @@ module.exports = function (Plugins) {
pluginData.modules.forEach(function (file) {
if (strip) {
modules[file.replace(new RegExp('\.?(\/[^\/]+){' + strip + '}\/'), '')] = path.join('./node_modules/', pluginData.id, file);
modules[file.replace(new RegExp('.?(/[^/]+){' + strip + '}/'), '')] = path.join('./node_modules/', pluginData.id, file);
} else {
modules[path.basename(file)] = path.join('./node_modules/', pluginData.id, file);
}
@@ -300,11 +300,10 @@ module.exports = function (Plugins) {
if (!atRootLevel && relPath) {
winston.verbose('[plugins/load] File not found: ' + fullPath + ' (Ascending)');
return resolveModulePath(path.join(__dirname, '../..', relPath));
} else {
// Already at root level, file was simply not found
winston.warn('[plugins/load] File not found: ' + fullPath + ' (Ignoring)');
return null;
}
// Already at root level, file was simply not found
winston.warn('[plugins/load] File not found: ' + fullPath + ' (Ignoring)');
return null;
}
}
@@ -315,7 +314,7 @@ module.exports = function (Plugins) {
},
plugin: function (next) {
fs.readFile(path.join(pluginPath, 'plugin.json'), next);
}
},
}, function (err, results) {
if (err) {
return callback(err);
@@ -333,7 +332,7 @@ module.exports = function (Plugins) {
pluginData.repository = packageData.repository;
pluginData.nbbpm = packageData.nbbpm;
pluginData.path = pluginPath;
} catch(err) {
} catch (err) {
var pluginDir = pluginPath.split(path.sep);
pluginDir = pluginDir[pluginDir.length - 1];