forked from skygragon/leetcode-cli
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathplugin.js
49 lines (39 loc) · 968 Bytes
/
plugin.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
var _ = require('underscore');
var h = require('./helper');
var log = require('./log');
function Plugin(id, name, ver, desc) {
this.id = id;
this.name = name;
this.ver = ver || 'default';
this.desc = desc;
this.next = null;
}
Plugin.prototype.init = function() {
};
Plugin.prototype.setNext = function(next) {
this.next = this.__proto__ = next;
};
Plugin.plugins = [];
Plugin.init = function(head) {
var plugins = [];
h.getDirData(['lib', 'plugins']).forEach(function(f) {
var p = f.data;
if (!p) return;
log.trace('found plugin: ' + p.name + '=' + p.ver);
p.init();
plugins.push(p);
log.trace('inited plugin: ' + p.name);
});
// chain the plugins together
// the one has bigger `id` comes first
plugins = _.sortBy(plugins, function(p) {
return -p.id;
});
var last = head;
plugins.forEach(function(p) {
last.setNext(p);
last = p;
});
Plugin.plugins = plugins;
};
module.exports = Plugin;