-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerateReadme.js
More file actions
executable file
·67 lines (58 loc) · 2.15 KB
/
generateReadme.js
File metadata and controls
executable file
·67 lines (58 loc) · 2.15 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
const fs = require('fs');
const repositories = require('./repositories.json');
const readme = fs.readFileSync('./README.md', 'utf8');
const HEADER = '<!-- Repositories -->\n';
const repositoryIndex = readme.indexOf(HEADER);
const repoToTableRow = (repo) => {
const url = repo.url;
// Only supports github repositories right now
const [_, ghOrg, ghRepoName] = url.match(
/https:\/\/github.com\/(\w+)\/([\w_-]+)/
);
const slug = `${ghOrg}/${ghRepoName}`;
const supportsReleases =
typeof repo.supportsReleases === "boolean" ? repo.supportsReleases : true;
const repository = `[${slug}](https://github.com/${slug})`;
const type = repo.packages.map(getTypeBadge).join("<br>");
const packages = repo.packages.map(getPackageBadge).join("<br>");
const released =
!repo.private && supportsReleases
? ``
: "";
const tableSegments = [repository, type, packages, released];
return `| ${tableSegments.join(" | ")} |`;
};
const colorMap = new Map([
['issues', 'white'],
['library', 'yellowgreen'],
['plugin', 'blue'],
['GHA', 'orange'],
['config', 'lightblue'],
['template', 'purple'],
['Extension', 'red'],
])
/**
* Get the img.shield badge as <type>.
* @param {name: string, type: 'package' | 'library' } package
*/
function getTypeBadge(package) {
const color = colorMap.get(package.type) ?? 'lightgrey';
return ``;
}
/**
* Get the img.shield badge as <name><version>.
* @param {name: string, type: 'package' | 'library' } package
*/
function getPackageBadge(package) {
if(package.type !== 'GHA' && package.name) {
return `[](https://www.npmjs.com/package/${package.name})`;
}
}
const contents = [
HEADER,
"| Repository | Type | Package | Released |",
"|------------|:----:|---------|----------|",
...repositories.map(repoToTableRow),
];
const newContents = readme.substring(0, repositoryIndex) + contents.join('\n') + '\n';
fs.writeFileSync('README.md', newContents, '')