forked from 2fd/graphdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.ts
35 lines (30 loc) · 1.04 KB
/
README.ts
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
import Bluebird from "bluebird";
// tslint:disable-next-line:no-implicit-dependencies
import Handlebars from "handlebars";
import request from "request";
import { readFile, writeFile } from "./lib/utility/fs";
import { execSync } from "child_process";
Handlebars.registerHelper("bash", (command: string) => {
return execSync(command).toString("ascii");
});
async function fromGithub(endpoint: string) {
return Bluebird.promisify(request)({
method: "GET",
url: "https://api.github.com/" + endpoint,
json: true,
headers: { "User-Agent": "README generator" }
}).then((response: request.RequestResponse & { body: any }) => response.body);
}
Promise.all([
readFile("./README.handlebars", "utf8"),
fromGithub("repos/2fd/graphdoc"),
fromGithub("repos/2fd/graphdoc/contributors").then(
(contributors: Array<{ login: string }>) =>
contributors.filter(c => c.login !== "2fd")
)
]).then(([template, project, contributors]) => {
return writeFile(
"README.md",
Handlebars.compile(template)({ project, contributors })
);
});