|
1 | 1 | #!/usr/bin/env node
|
2 | 2 | // ./fetch_package_names <suffix> > output
|
3 | 3 | // ./fetch_package_names "-loader" > output.json
|
4 |
| -const GitHubApi = require("github"); |
| 4 | +const GitHubApi = require('github'); |
5 | 5 |
|
6 | 6 | if (require.main === module) {
|
7 |
| - main(); |
| 7 | + main(); |
8 | 8 | } else {
|
9 |
| - module.exports = fetchPackageNames; |
| 9 | + module.exports = fetchPackageNames; |
10 | 10 | }
|
11 | 11 |
|
12 | 12 | function main() {
|
13 | 13 | const organization = process.argv[2];
|
14 | 14 | const suffix = process.argv[3];
|
15 | 15 |
|
16 |
| - if(!organization) { |
| 16 | + if (!organization) { |
17 | 17 | return console.error('Missing organization!');
|
18 | 18 | }
|
19 |
| - if(!suffix) { |
| 19 | + if (!suffix) { |
20 | 20 | return console.error('Missing suffix!');
|
21 | 21 | }
|
22 | 22 |
|
23 |
| - fetchPackageNames({ |
24 |
| - organization: organization, |
25 |
| - suffix: suffix |
26 |
| - }, function(err, d) { |
27 |
| - if (err) { |
28 |
| - return console.error(err); |
29 |
| - } |
| 23 | + fetchPackageNames( |
| 24 | + { |
| 25 | + organization: organization, |
| 26 | + suffix: suffix |
| 27 | + }, |
| 28 | + function(err, d) { |
| 29 | + if (err) { |
| 30 | + return console.error(err); |
| 31 | + } |
30 | 32 |
|
31 |
| - console.log(JSON.stringify(d, null, 4)); |
32 |
| - }); |
| 33 | + console.log(JSON.stringify(d, null, 4)); |
| 34 | + } |
| 35 | + ); |
33 | 36 | }
|
34 | 37 |
|
35 | 38 | function fetchPackageNames(options, cb) {
|
36 | 39 | const github = new GitHubApi();
|
37 | 40 |
|
38 |
| - if(process.env.GITHUB_TOKEN) { |
| 41 | + if (process.env.GITHUB_TOKEN) { |
39 | 42 | github.authenticate({
|
40 | 43 | type: 'token',
|
41 | 44 | token: process.env.GITHUB_TOKEN
|
42 | 45 | });
|
43 | 46 | }
|
44 | 47 |
|
45 | 48 | // XXX: weak since this handles only one page
|
46 |
| - github.repos.getForOrg({ |
47 |
| - org: options.organization, |
48 |
| - per_page: 100 |
49 |
| - }, function (err, d) { |
50 |
| - if (err) { |
51 |
| - return cb(err); |
52 |
| - } |
| 49 | + github.repos.getForOrg( |
| 50 | + { |
| 51 | + org: options.organization, |
| 52 | + per_page: 100 |
| 53 | + }, |
| 54 | + function(err, d) { |
| 55 | + if (err) { |
| 56 | + return cb(err); |
| 57 | + } |
53 | 58 |
|
54 |
| - return cb(null, d.data.filter(function(o) { |
55 |
| - return o.name.endsWith(options.suffix); |
56 |
| - })); |
57 |
| - }); |
| 59 | + return cb( |
| 60 | + null, |
| 61 | + d.data.filter(function(o) { |
| 62 | + return o.name.endsWith(options.suffix); |
| 63 | + }) |
| 64 | + ); |
| 65 | + } |
| 66 | + ); |
58 | 67 | }
|
0 commit comments