-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugins.js
42 lines (39 loc) · 983 Bytes
/
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
var util = require('util');
var events = require('events');
var fs = require('fs');
function Plugins(plugins) {
events.EventEmitter.call(this);
this.plugins = plugins.slice(0);
var copy = this.plugins;
this.on('apply', function(plugin) {
var idx = copy.indexOf(plugin);
if (idx >= 0) {
copy.splice(idx, 1);
}
});
}
util.inherits(Plugins, events.EventEmitter);
Plugins.prototype.apply = function(event, data) {
var list = this;
this.plugins.forEach(function(plugin) {
plugin.emit(event, data, list);
});
}
function Plugin(name, comment, image) {
events.EventEmitter.call(this);
this.name = name;
this.comment = comment;
this.image = fs.readFileSync('./plugindata/' + image + '.png').toString('base64');
}
util.inherits(Plugin, events.EventEmitter);
Plugin.prototype.toJson = function() {
return {
name: this.name,
comment: this.comment,
image: this.image
};
}
module.exports = {
Plugins: Plugins,
Plugin: Plugin
};