-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 1000 Bytes
/
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
const path = require('path');
const Flow = require('./flow');
const read = require('./plugins/read');
const matter = require('./plugins/matter');
const source = require('./plugins/source');
const output = require('./plugins/output');
const cwd = process.cwd();
const getPlugin = name => {
const filename = require.resolve(`./${name}`, {
paths: [cwd, path.join(__dirname, './plugins')]
});
return require(filename);
};
const normalize = a => a; // TODO:
function KelpGenerator(config) {
const flow = new Flow();
if (config.source) flow.use(source(config.source));
if (config.source) flow.use(read());
if (config.source) flow.use(matter());
if (config.plugins) {
for (const name in normalize(config.plugins)) {
const plugin = getPlugin(name);
const options = config.plugins[name];
flow.use(plugin(options));
}
}
if (config.output) flow.use(output(config.output));
return flow.run();
};
KelpGenerator.Flow = Flow;
module.exports = KelpGenerator;