-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
72 lines (62 loc) · 2.09 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require("dotenv").config();
const fs = require("fs");
const request = require("undici").request;
const { format, parseISO } = require("date-fns");
const DATE_FORMAT = "LLLL dd, yyyy";
const now = new Date().toLocaleString("en", { timeZone: "UTC" });
const head = `# Node.js Web Frameworks
A list of popular GitHub projects related to Node.js web framework (ranked by stars)\n
| Framework | Stars | Forks | Open Issues | Description | Last Update | License |
| --------- | ----- | ----- | ----------- | ----------- | ----------- | ------- |
`;
const tail = "*Last Update*: ";
const warning = "⚠️ No longer maintained ⚠️";
const accessToken = process.env.TOKEN;
const repos = [];
const options = {
maxRedirections: 15,
headers: {
Authorization: `token ${accessToken}`,
"User-Agent":
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36",
accept: "application/vnd.github.v3+json",
},
};
const getJSON = async (url) => {
return (await request(url, options)).body.json();
};
Promise.all(
require("./list.json").map(async (framework) => {
try {
const repoURL = `https://api.github.com/repos/${framework}`;
const repo = await getJSON(repoURL);
const commit = await getJSON(`${repoURL}/commits/${repo.default_branch}`);
repo.lastCommitDate = commit.commit.committer.date;
repos.push(repo);
} catch (error) {
console.error(error);
}
}),
).then(() => {
if (repos.length === 0) {
return;
}
let readme = head;
repos
.sort((a, b) => a.stargazers_count - b.stargazers_count)
.reverse()
.map((repo) => {
readme += `| [${repo.full_name}](${repo.html_url}) | ${
repo.stargazers_count
} | ${repo.forks} | ${repo.open_issues} | ${
(repo.archived ? warning + " " : "") + repo.description
} | ${format(parseISO(repo.lastCommitDate), DATE_FORMAT)} | ${
repo.license?.name || ""
} |\n`;
});
readme += `\n${tail}${format(
new Date(now),
"'UTC' HH:mm" + ", " + DATE_FORMAT,
)}`;
fs.writeFileSync("README.MD", readme);
});