analyze-css
Version:
CSS selectors complexity and performance analyzer
52 lines (39 loc) • 1.1 kB
JavaScript
/**
* A wrapper for preprocessors
*/
;
var debug = require("debug")("analyze-css:preprocessors"),
glob = require("glob");
var preprocessors = function () {};
preprocessors.prototype = {
get: function (name) {
return require(__dirname + "/preprocessors/" + name + ".js");
},
// return instances of all available preprocessors
getAll: function () {
var files,
res = [];
files = glob.sync(__dirname + "/preprocessors/*.js");
debug("Initializing...");
/* istanbul ignore next */
if (Array.isArray(files)) {
files.forEach(function (file) {
res.push(require(file));
});
}
return res;
},
// get name of matching preprocessor
findMatchingByFileName: function (fileName) {
var matching = false;
this.getAll().forEach(function (preprocessor) {
if (preprocessor.matchesFileName(fileName)) {
matching = preprocessor.name;
debug('%s matches "%s" preprocessor', fileName, matching);
return false;
}
});
return matching;
},
};
module.exports = preprocessors;