2
0
Fork 0
tcrud/lib/plugin/server/info/info-plugins.js

56 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2017-06-10 14:53:29 +00:00
var configRegistry = require('./../../../config-registry');
module.exports = (function () {
var createPluginInfo = function() {
var result = {};
for (var pluginIdx in configRegistry.getMasterConfig().plugins) {
var plugin = configRegistry.getMasterConfig().plugins[pluginIdx];
var pluginExtensions = Object.keys(plugin).slice(0,-1);
//TODO: pluginExtensions.remove('tmeta');
var pluginData = {
extensions: pluginExtensions,
tmeta: plugin.tmeta,
troutes: plugin.troutes
};
result[plugin.tmeta.key] = pluginData;
}
return result;
};
var createPluginKeyList = function() {
var result = [];
for (var pluginIdx in configRegistry.getMasterConfig().plugins) {
var plugin = configRegistry.getMasterConfig().plugins[pluginIdx];
result.push(plugin.tmeta.key);
}
return result;
};
return function ServerInfoPluginsPlugin() {
this.configPlugin = function (ctx) {
ctx.key='serverInfoPlugins';
ctx.description='Makes the server plugins info public as json';
ctx.localDir = __dirname;
ctx.localConfigTemplate = 'info-plugins.json';
};
this.configServer = function(ctx) {
ctx.server.get(ctx.createSlugApiServerBase(),ctx.renderFunctionJSON(function () {
return {
plugins: {
keys: {
registrated: createPluginKeyList(),
backends: Object.keys(configRegistry.getMasterConfig().backends),
validators: Object.keys(configRegistry.getMasterConfig().validators)
},
info: createPluginInfo()
}
}
}));
};
};
})();