UNPKG

1 kBJavaScriptView Raw
1/**
2 * A wrapper for preprocessors
3 */
4'use strict';
5
6var debug = require('debug')('analyze-css:preprocessors'),
7 glob = require('glob');
8
9var preprocessors = function() {
10
11};
12
13preprocessors.prototype = {
14
15 get: function(name) {
16 return require(__dirname + '/preprocessors/' + name + '.js');
17 },
18
19 // return instances of all available preprocessors
20 getAll: function() {
21 var files,
22 res = [];
23
24 files = glob.sync(__dirname + '/preprocessors/*.js');
25 debug('Initializing...');
26
27 if (Array.isArray(files)) {
28 files.forEach(function(file) {
29 res.push(require(file));
30 });
31 }
32
33 return res;
34 },
35
36 // get name of matching preprocessor
37 findMatchingByFileName: function(fileName) {
38 var matching = false;
39
40 this.getAll().forEach(function(preprocessor) {
41 if (preprocessor.matchesFileName(fileName)) {
42 matching = preprocessor.name;
43
44 debug('%s matches "%s" preprocessor', fileName, matching);
45 return false;
46 }
47 });
48
49 return matching;
50 }
51};
52
53module.exports = preprocessors;