This repository has been archived by the owner on Jul 16, 2018. It is now read-only.
forked from tmcw-up-for-adoption/ownership
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (74 loc) · 2.38 KB
/
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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var spawn = require('child_process').spawn;
module.exports.addUsersToPackage = addUsersToPackage;
module.exports.addUsersToPackages = addUsersToPackages;
module.exports.rmUserFromPackages = rmUserFromPackages;
function addUsersToPackages(users, packages, callback) {
var i = -1;
addPackage();
function addPackage() {
var p = packages[++i];
if (!p) { return callback(null); }
console.log('Adding users to:', p);
addUsersToPackage(users, p, function(err) {
if (!err) addPackage();
});
}
}
function addUsersToPackage(users, name, callback) {
var i = -1;
addUser();
function addUser() {
var user = users[++i];
if (!user) {
process.stdout.write('\n');
return callback(null);
}
spawn('npm', ['owner', 'add', user, name])
.on('exit', onexit.bind(undefined, user))
.on('error', onerror.bind(undefined, user));
}
function onexit(user, code) {
if (code === 0) {
process.stdout.write('✓ ' + user + ' ');
addUser();
} else {
process.stdout.write('err ' +
code + ': unable to add ' +
user + ' - are you sure the module ' + name + ' exists and is published?\n');
}
}
function onerror(user, err) {
process.stdout.write('err: unable to add ' +
user + '\n');
console.log(err.message);
}
}
function rmUserFromPackages(user, names, callback) {
var i = -1;
addUser();
function addUser() {
var name = names[++i];
if (!name) {
process.stdout.write('\n');
return callback();
}
spawn('npm', ['owner', 'rm', user, name])
.on('exit', onexit.bind(undefined, user, name))
.on('error', onerror.bind(undefined, user, name));
}
function onexit(user, name, code) {
if (code === 0) {
process.stdout.write('✓ ' + user + ' removed from ' + name + '\n');
addUser();
} else {
process.stdout.write('err ' +
code + ': unable to rm ' +
user + ' - are you sure the module ' + name + ' exists and is published?\n');
}
}
function onerror(user, err) {
process.stdout.write('err: unable to rm ' +
user + '\n');
console.log(err.message);
}
}