-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathgenerate-authors.js
42 lines (39 loc) · 1.15 KB
/
generate-authors.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
'use strict';
/*
* Generate an AUTHOR file on the repo root and on each lerna package based on git log.
*
* Add / change aliases in .mailmap to avoid duplications and show the correct
* names / emails.
*/
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const packageRootPath = path.resolve(__dirname, '..');
function getAuthorsGitLog(packagePath) {
return execSync(
`git log --reverse --format='%aN <%aE>' --use-mailmap -- ${packagePath}`,
{ cwd: packageRootPath }
)
.toString()
.trim()
.split('\n');
}
function getAuthorsOrderedByFirstCommit(packagePath) {
const alreadyAdded = new Set();
const authors = [];
for (const authorName of getAuthorsGitLog(packagePath)) {
if (alreadyAdded.has(authorName)) {
continue;
}
alreadyAdded.add(authorName);
authors.push(authorName);
}
return authors.filter((authorName) => !authorName.includes('[bot]'));
}
function renderAuthorsFileContent(authors) {
return `${authors.join('\n')}\n`;
}
fs.writeFileSync(
path.resolve(packageRootPath, 'AUTHORS'),
renderAuthorsFileContent(getAuthorsOrderedByFirstCommit('.'))
);