-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (44 loc) · 1.18 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
import toml from "@iarna/toml";
import fs from "fs";
import { Octokit } from "@octokit/core";
const token = process.env.TOKEN;
const github = new Octokit({
auth: token,
});
async function getStats(owner, repo) {
const { data } = await github.request(
"GET /repos/{owner}/{repo}/stats/code_frequency",
{
owner,
repo,
}
);
return data;
}
async function getRepoInfo(owner, repo) {
const { data } = await github.request("GET /repos/{owner}/{repo}", {
owner,
repo,
});
return data;
}
async function main() {
const file = "data/github.toml";
const outputFolder = "build";
const raw = fs.readFileSync(file, "utf8");
const { config, links } = toml.parse(raw);
const tags = Array.from(
Object.values(links).reduce(
(set, tags) => (tags.map((t) => set.add(t)), set),
new Set()
)
);
const goms = Object.entries(links).reduce(
(obj, [ident, tags]) => ({ ...obj, [config.prefix + ident]: tags }),
{}
);
if (!fs.existsSync(outputFolder)) fs.mkdirSync(outputFolder);
fs.writeFileSync(`${outputFolder}/goms.json`, JSON.stringify(goms));
fs.writeFileSync(`${outputFolder}/tags.json`, JSON.stringify(tags));
}
main();