-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsync-contributors.js
More file actions
28 lines (23 loc) · 911 Bytes
/
sync-contributors.js
File metadata and controls
28 lines (23 loc) · 911 Bytes
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
const fs = require('fs');
const SOURCE = '.all-contributorsrc';
const TARGET =
'./projects/elements-demo/src/app/features/contribute/contribute.component.html';
const TOKEN_START = '<!-- ALL-CONTRIBUTORS-LIST:START -->';
const TOKEN_END = '<!-- ALL-CONTRIBUTORS-LIST:END -->';
const PATTERN = new RegExp(`${TOKEN_START}[\\s\\S]*${TOKEN_END}`, 'gim');
const contributors = JSON.parse(fs.readFileSync(SOURCE, 'utf8')).contributors;
const content = fs.readFileSync(TARGET, 'utf8');
const data = contributors
.map(
(c) => `
<a class="contributor" href="${c.profile}" target="_blank">
<img src="${c.avatar_url}">
<span>${c.name}</span>
</a>
`
)
.join('\n');
const replacement = `${TOKEN_START}${data}${TOKEN_END}`;
const adjustedContent = content.replace(PATTERN, replacement);
fs.writeFileSync(TARGET, adjustedContent);
console.log(`${contributors.length} contributors added to HTML`);