forked from 2fd/graphdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.ts
More file actions
30 lines (25 loc) · 1 KB
/
README.ts
File metadata and controls
30 lines (25 loc) · 1 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
import * as Handlebars from "handlebars";
import * as request from 'request';
import * as util from 'util';
import { readFile, writeFile } from "./lib/utility/fs";
import { execSync } from "child_process";
Handlebars.registerHelper('bash', function (command: string) {
return execSync(command).toString().replace(/\[\d{1,2}m/gi, '')
})
async function fromGithub (endpoint: string) {
return util.promisify(request)({
method: 'GET',
url: 'https://api.github.com/' + endpoint,
json: true,
headers: { 'User-Agent': 'README generator' }
}).then(response => response.body)
}
Promise
.all([
readFile('./README.handlebars', 'utf8'),
fromGithub('repos/2fd/graphdoc'),
fromGithub('repos/2fd/graphdoc/contributors').then(contributors => contributors.filter(c => c.login !== '2fd') ),
])
.then(([template, project, contributors]) => {
return writeFile('README.md', Handlebars.compile(template)({project, contributors}))
})