forked from SnapInteractive/mergeatron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mergeatron.js
62 lines (51 loc) · 1.37 KB
/
mergeatron.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
56
57
58
59
60
61
62
"use strict";
var config = require('./config').config,
db = require('./db').init(),
fs = require('fs'),
events = require('events'),
winston = require('winston');
/**
* The main Mergeatron class. This class contains a reference to the selected
* database.
*
* @class Mergeatron
* @module Mergeatron
* @param db {Object} Instance of the database accesor
* @constructor
*/
var Mergeatron = function(db, config) {
this.db = db;
this.log = new (winston.Logger)({
transports: [
new (winston.transports.Console)({ level: config.log_level })
]
});
this.log.cli();
};
Mergeatron.prototype = new events.EventEmitter();
var mergeatron = new Mergeatron(db, config);
config.plugin_dirs.forEach(function(dir) {
fs.readdir(dir, function(err, files) {
if (err) {
mergeatron.log.error(err);
process.exit(1);
}
for (var i = 0, l = files.length; i < l; i++) {
var filename = dir + files[i],
pluginName = files[i].split('.', 2)[0],
conf = { enabled: false };
if (!filename.match(/\.js$/)) {
continue;
}
mergeatron.log.info('Loading plugin: ' + pluginName);
if (config.plugins && config.plugins[pluginName]) {
conf = config.plugins[pluginName];
}
if (conf.enabled !== undefined && conf.enabled) {
require(filename).init(conf, mergeatron);
} else {
mergeatron.log.info('Not loading disabled plugin ' + pluginName);
}
}
});
});