forked from ngageoint/opensphere-build-resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.js
44 lines (37 loc) · 1.04 KB
/
plugins.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
'use strict';
const rglob = require('require-glob');
const path = require('path');
const filterEmpty = function(item) {
return Boolean(item);
};
const mapField = function(field) {
return function(item) {
return item[field];
};
};
const load = function() {
var resolverPackage = require(path.resolve(__dirname, 'package'));
var plugins = rglob.sync([
// built in plugins
path.join(__dirname, '/plugins/*/index.js'),
// installed sibling plugins
path.join('node_modules', resolverPackage.name + '-*', '/index.js')],
{
cwd: process.cwd(),
reducer: function(options, result, file, i, files) {
// don't actually reduce, because that's incredibly annoying
// for our case
return files;
}
}).map(function(item) {
return item.exports;
});
return {
resolvers: plugins.map(mapField('resolver')).filter(filterEmpty),
writers: plugins.map(mapField('writer')).filter(filterEmpty),
postResolvers: plugins.map(mapField('postResolver')).filter(filterEmpty)
};
};
module.exports = {
load: load
};