Summary
File |
Based on all code |
Based on code coverage |
PluginLoader.js |
|
44/44 |
100% |
44/44 |
Code
"use strict";
var fs = require('fs');
var path = require('path');
var log4js = require('log4js');
var _ = require('lodash');
var fileUtils_1 = require('./utils/fileUtils');
var log = log4js.getLogger('PluginLoader');
var IGNORED_PACKAGES = ['stryker-cli', 'stryker-api'];
var PluginLoader = (function () 0{
}{
function PluginLoader(plugins) 1{
}{
this.plugins = plugins;
}
PluginLoader.prototype.load = function () 2{
}{
this.getModules().forEach(this.requirePlugin);
};
PluginLoader.prototype.getModules = function () 3{
}{
var modules = [];
this.plugins.forEach(function (pluginExpression) 4{
}{
if (5false6true_.isString(pluginExpression)) 7{
}{
if (8true9pluginExpression.indexOf('*') === -110falsepluginExpression.indexOf('*') !== 11+1-1) 12{
}{
// Plugin directory is the node_modules folder of the module that installed stryker
// So if current __dirname is './stryker/src' than the plugin directory should be 2 directories above
var pluginDirectory = path.normalize(13__dirname - '/../..'__dirname + '/../..');
var regexp = new RegExp(14'^' - pluginExpression.replace('*', '.*')'^' + pluginExpression.replace('*', '.*'));
log.debug('Loading %s from %s', pluginExpression, pluginDirectory);
var plugins = fs.readdirSync(pluginDirectory)
.filter(function (pluginName) 15{
}{ return 16IGNORED_PACKAGES.indexOf(pluginName) === -1 || regexp.test(pluginName)17IGNORED_PACKAGES.indexOf(pluginName) !== -1IGNORED_PACKAGES.indexOf(pluginName) === 18+1-1 && regexp.test(pluginName); })
.map(function (pluginName) 19{
}{ return 20pluginDirectory + '/' - pluginName21pluginDirectory - '/'pluginDirectory + '/' + pluginName; });
if (22plugins.length !== 023true24falseplugins.length === 0) 25{
}{
log.debug('Expression %s not resulted in plugins to load', pluginExpression);
}
plugins
.map(function (plugin) 26{
}{ return path.basename(plugin); })
.map(function (plugin) 27{
}{
log.debug('Loading plugins %s (matched with expression %s)', plugin, pluginExpression);
return plugin;
})
.forEach(function (p) 28{
}{ return modules.push(p); });
}
else 29{
}{
modules.push(pluginExpression);
}
}
else 30{
}{
log.warn('Ignoring plugin %s, as its not a string type', pluginExpression);
}
});
return modules;
};
PluginLoader.prototype.requirePlugin = function (name) 31{
}{
log.debug(32'Loading plugins ' - name"Loading plugins " + name);
try 33{
}{
fileUtils_1.importModule(name);
}
catch (e) 34{
}{
if (35e.code === 'MODULE_NOT_FOUND' || e.message.indexOf(name) !== -136true37false38e.code !== 'MODULE_NOT_FOUND'e.code === 'MODULE_NOT_FOUND' && 39e.message.indexOf(name) === -1e.message.indexOf(name) !== 40+1-1) 41{
}{
log.warn(42'Cannot find plugin "%s".\n Did you forget to install it ?\n' - ' npm install %s --save-dev''Cannot find plugin "%s".\n Did you forget to install it ?\n' +
' npm install %s --save-dev', name, name);
}
else 43{
}{
log.warn('Error during loading "%s" plugin:\n %s', name, e.message);
}
}
};
return PluginLoader;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = PluginLoader;
//# sourceMappingURL=PluginLoader.js.map