-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
50 lines (44 loc) · 1.47 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var fs = require('fs');
var pathLib = require('path');
var async = require('async');
var internals = {};
internals.mapEntry = function (type) {
return function (entry) {
if (typeof entry === 'object') {
// maybe validate???
return entry;
}
if (typeof entry === 'string') {
return {
'name': entry,
'path': pathLib.join(__dirname, '.', 'rule', type, entry + '.js')
};
} else {
throw new Error('Wrong configuration of includes');
}
};
};
internals.collect = function (type) {
return function (specList) {
if (!Array.isArray(specList)){
console.log('specList'.red, specList);
throw new TypeError('Should send in a list');
}
return specList.map(internals.mapEntry(type));
};
};
internals.statFiles = function (list, done) {
return async.map(list, fs.stat, done);
};
module.exports = {
'mapEntry': internals.mapEntry,
'collect': function (parent) {
parent.instrument = internals.collect('instrument')(parent.instrument);
parent.preprocess = internals.collect('preprocess')(parent.preprocess);
parent.validate = internals.collect('validate')(parent.validate);
},
'collectSpec': internals.collect('instrument'),
'collectValidator': internals.collect('validate'),
'collectPreprocessor': internals.collect('preprocess'),
'statFiles': internals.statFiles
};