-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateStats.ts
50 lines (41 loc) · 1.16 KB
/
updateStats.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import path from "path";
import { readdirSync, readFileSync, writeFileSync } from "fs";
const YEAR_START = 2015;
const YEAR_END = 2023;
const getStats = () => {
const complete = {};
for (let year = YEAR_START; year <= YEAR_END; year++) {
complete[year] = [];
readdirSync(path.resolve(__dirname, `${year}`)).forEach((file) => {
if (/day\d+\.ts/.test(file)) {
complete[year].push(`${year}/${file}`);
}
});
}
return complete;
};
const main = () => {
const readme = readFileSync(path.resolve(__dirname, "README.md"), {
encoding: "utf8",
flag: "r",
});
const stats = getStats();
const statsText = [];
let starsTotal = 0;
for (const year in stats) {
const stars = stats[year].length * 2;
starsTotal += stars;
statsText.push(` [${year}]: ${`${stars}`.padStart(2, " ")}*`);
}
statsText.reverse();
statsText.push("");
statsText.push(` Total stars: ${starsTotal}*`);
const updatedReadme = readme.split("\n");
updatedReadme.splice(9, statsText.length, ...statsText);
writeFileSync(
path.resolve(__dirname, "README.md"),
updatedReadme.join("\n"),
{ encoding: "utf8" }
);
};
main();