-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
update.js
49 lines (40 loc) · 1.02 KB
/
update.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 EventEmitter = require('events').EventEmitter;
var users = require('./users');
var modules = require('./modules');
var updating;
var update = function(callback) {
if (callback) return update().on('end', callback);
if (updating) return updating;
updating = new EventEmitter();
updating.setMaxListeners(0);
updating.on('end', function() {
updating = null;
});
var emit = function(name) {
return function(data) {
updating.emit(name, data);
};
};
modules.update()
.on('module', emit('module'))
.on('end', function(err) {
if (err) return updating.emit('end', err);
users.update()
.on('user', emit('user'))
.on('end', emit('end'));
});
return updating;
};
module.exports = update;
if (require.main !== module) return;
var log = require('single-line-log');
update()
.on('module', function(mod) {
log('updating module '+mod._id+' (v'+mod.version+')');
})
.on('user', function(user) {
log('updating user '+user._id+' ('+user.updates+' updates)');
})
.on('end', function() {
process.exit(0);
})