This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
88 lines (73 loc) · 2.18 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
83
84
85
86
87
88
const GITHUB_CALLS_PER_HOUR = 4500
const fs = require('fs')
, async = require('async')
, rateLimit = require('function-rate-limit')
, loadNpmData = require('./load-npm-data')
, filterAussies = require('./filter-aussies')
, fetchGithubData = rateLimit(
GITHUB_CALLS_PER_HOUR
, 1000 * 60 * 60
, require('./fetch-github-data')
)
, config = require('./config')
/* ./config.json needs to look like this:
{
"allPackagesOutput" : "/path/to/allpackages.json"
, "repositoriesOutput" : "/path/to/repositories.json"
, "githubOutput" : "/path/to/githubusers.json"
, "githubAuthToken" : "yourgithubauthtoken"
}
where githubAuthToken can be obtained with something like:
curl -i -u <your_username> -d '{"scopes": ["repo"]}' https://api.github.com/authorizations
(not that it needs "repo" scope)
*/
function write (location, data) {
fs.writeFile(
location
, JSON.stringify(data, null, 2)
, function (err) {
if (err)
console.error(err)
console.log('Wrote', location)
}
)
}
function githubUsers (repositories) {
var users = []
repositories.forEach(function (repo) {
if (users.indexOf(repo.githubUser) == -1)
users.push(repo.githubUser)
})
return users
}
function fetchUsers (users, callback) {
async.map(
users
, function (user, callback) {
fetchGithubData(config.githubAuthToken, user, function (err, data) {
if (err || !user) {
console.error(err || 'No user data for ' + user)
return callback()
}
if (user.message) {
console.error('GitHub:', user.message)
return callback()
}
callback(null, data)
})
}
, callback
)
}
loadNpmData(function (err, data) {
if (err)
return console.error(err)
write(config.allPackagesOutput, data.allPackages)
write(config.repositoriesOutput, data.repositories)
fetchUsers(githubUsers(data.repositories), function (err, data) {
if (err)
return console.error(err)
write(config.githubOutput, data)
write(config.aussieOutput, filterAussies(data))
})
})