forked from jsonwebtoken/jsonwebtoken.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libraries.js
52 lines (46 loc) · 1.69 KB
/
libraries.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
const fs = require("fs");
const { Octokit } = require("@octokit/rest");
const dotenv = require("dotenv").config();
const getLanguages = require("./views/website/libraries/support/get-languages.js");
const octokit = new Octokit({
auth: process.env.GITHUB || process.env.GITHUB_TOKEN,
});
function fetchGithubStars() {
const requests = [];
const languages = getLanguages();
console.log("----------------------");
console.log("Fetching GitHub Data");
console.log("----------------------");
languages.forEach((language) => {
language.libs.forEach((lib) => {
if (lib.gitHubRepoPath) {
const owner = lib.gitHubRepoPath.split("/")[0];
const repo = lib.gitHubRepoPath.split("/")[1];
requests.push(
octokit.repos
.get({
owner,
repo,
})
.then((repo) => {
console.log(
"Stars",
lib.gitHubRepoPath,
repo.data.stargazers_count
);
lib.stars = repo.data.stargazers_count;
return repo.data.stargazers_count;
})
.catch((error) => console.log(error))
);
}
});
});
Promise.all(requests).then(() => {
console.log("----------------------");
console.log("Writing libraries.json");
console.log("----------------------");
fs.writeFileSync(`${__dirname}/libraries.json`, JSON.stringify(languages));
});
}
fetchGithubStars();