-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·67 lines (62 loc) · 2.62 KB
/
Copy pathcli.js
File metadata and controls
executable file
·67 lines (62 loc) · 2.62 KB
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
#!/usr/bin/env node
var child = require('child_process')
var url = require('url')
var ghauth = require('ghauth')
var argv = require('minimist')(process.argv.splice(2), {boolean: true})
var collaborator = require('./')
var findNPM = require('find-npm-by-github')
var authOptions = {
// ~/.config/awesome.json will store the token
configName : 'collaborator',
// (optional) whatever GitHub auth scopes you require
scopes : [ 'repo' ],
// (optional) saved with the token on GitHub
note : 'This token is for the collaborator module from NPM'
}
auth()
function auth() {
var user = argv._[0]
ghauth(authOptions, function (err, authData) {
if (err) return console.error(err)
child.exec('git config --get remote.origin.url', function(err, stdo, stde) {
if (err || stdo.toString() === '') return console.error('Error: Could not read git remote origin from current directory')
var parts = stdo.toString().split('/')
var repo = parts[parts.length - 1].split('.git')[0].trim()
var action = 'add'
if (argv.del) action = 'del'
var collabs = []
collaborator(authData.token, action, user, repo, function(err, pagination, collaborators) {
if (err) return console.error('Error: ' + (err.message || err))
collabs = collabs.concat(collaborators)
if (pagination.isLastPage) {
collabs = collabs.map(function(c) { return {'username': c.login, 'avatar': c.avatar_url }})
var out = '## Collaborators\n\n'
+ repo + ' is only possible due to the excellent work of the following collaborators:\n\n'
+ makeTable(collabs)
console.log(out)
}
})
})
if(argv.npm) {
findNPM(authData.token, user, function (err, npmName) {
if (err) return console.error('Could not determine npm name (' +err.message+')')
if (!npmName) return console.error('Could not determine npm name')
child.exec('npm owner add ' + npmName + ' --quiet', function (err, stdo, stde) {
if(err || stde.toString() != '') return console.log('Error: Could not add ' + npmName + ' on npm')
child.exec('npm ls', function (err, stdo, stde) {
var moduleName = stdo.toString().split('@')[0]
console.error('Added ' + npmName + ' to module ' + moduleName)
})
})
})
}
})
}
function makeTable(rows) {
var table = '<table><tbody>'
rows.map(function(row) {
table += '<tr><th align="left">' + row.username + '</th><td><a href="https://github.com/' + row.username + '">GitHub/' + row.username + '</a></td></tr>\n'
})
table += '</tbody></table>'
return table
}