-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (44 loc) · 1.18 KB
/
index.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
51
52
53
54
55
var fs = require('fs');
var path = require('path');
var base;
var getComponents = function(){
return fs.readdirSync(base).filter(function(file) {
return fs.statSync(path.join(base, file)).isDirectory();
}).map(function(dir){
return path.join(base, dir, 'trunk/bower.json');
});
};
var addToArray = function(array, thing){
if(!array) array = [];
if(typeof array === 'string') array = [array];
if(typeof thing === 'string'){
array.push(thing);
} else if(thing) {
array = array.concat(thing);
}
return array;
};
var getFiles = function(){
return getComponents(base).map(function(component){
var compFiles;
try {
compFiles = require(component).main;
} catch (err) {}
return compFiles;
}).reduce(function(previous, current){
return addToArray(previous, current);
});
};
var getByExtensions = function(extensions){
if(typeof extensions === 'string') extensions = [extensions];
return getFiles().filter(function(file){
return extensions.indexOf(path.extname(file).substring(1)) !== -1;
});
}
module.exports = function(userBase){
base = path.join(__dirname, userBase ? userBase : 'bower-components');
return {
files: getFiles(base),
ext: getByExtensions
}
};