1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const github_contributors_1 = require("@bevry/github-contributors");
|
4 | const json_1 = require("@bevry/json");
|
5 | const util_js_1 = require("./util.js");
|
6 | async function updateContributors(path) {
|
7 | let localCount = 0, remoteCount = 0;
|
8 |
|
9 | const pkg = await json_1.readJSON(path);
|
10 |
|
11 | const githubRepoSlug = util_js_1.getGitHubRepoSlug(pkg);
|
12 | const slug = githubRepoSlug || pkg.name;
|
13 | if (!slug) {
|
14 | console.error(path, pkg);
|
15 | throw new Error('package needs at least a name to identify it uniquely');
|
16 | }
|
17 |
|
18 | github_contributors_1.Fellow.add(pkg.author, pkg.authors).forEach((person) => {
|
19 | person.authoredRepositories.add(slug);
|
20 | });
|
21 | github_contributors_1.Fellow.add(pkg.contributors).forEach((person) => {
|
22 | person.contributedRepositories.add(slug);
|
23 | });
|
24 | github_contributors_1.Fellow.add(pkg.maintainers).forEach((person) => {
|
25 | person.maintainedRepositories.add(slug);
|
26 | });
|
27 | localCount = github_contributors_1.Fellow.fellows.length;
|
28 |
|
29 | if (githubRepoSlug) {
|
30 | try {
|
31 | const added = await github_contributors_1.getContributorsFromRepoContributorData(githubRepoSlug);
|
32 | remoteCount = added.size;
|
33 | }
|
34 | catch (err) {
|
35 | console.warn(err);
|
36 | console.warn(`FAILED to fetch the remote contributors for the repository: ${githubRepoSlug}`);
|
37 | }
|
38 | }
|
39 |
|
40 | delete pkg.authors;
|
41 | pkg.author = github_contributors_1.Fellow.authorsRepository(slug)
|
42 | .map((fellow) => fellow.toString({ displayYears: true, displayEmail: true }))
|
43 | .join(', ');
|
44 | pkg.contributors = github_contributors_1.Fellow.contributesRepository(slug)
|
45 | .map((fellow) => fellow.toString({ displayEmail: true, urlFields: ['githubUrl', 'url'] }))
|
46 | .filter((entry) => entry.includes('[bot]') === false)
|
47 | .sort();
|
48 | pkg.maintainers = github_contributors_1.Fellow.maintainsRepository(slug)
|
49 | .map((fellow) => fellow.toString({ displayEmail: true, urlFields: ['githubUrl', 'url'] }))
|
50 | .sort();
|
51 |
|
52 | if (!pkg.author)
|
53 | delete pkg.author;
|
54 | if (pkg.contributors.length === 0)
|
55 | delete pkg.contributors;
|
56 | if (pkg.maintainers.length === 0)
|
57 | delete pkg.maintainers;
|
58 |
|
59 | await json_1.writeJSON(path, pkg);
|
60 |
|
61 | console.log(`Updated contributors (${localCount} local, ${remoteCount} remote) on [${path}]`);
|
62 | }
|
63 | exports.default = updateContributors;
|