-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-contributors-json.js
41 lines (31 loc) · 1.23 KB
/
generate-contributors-json.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
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
// Get __dirname equivalent in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
try {
if (!fs.existsSync(".all-contributorsrc")) {
throw new Error(".all-contributorsrc file does not exist.");
}
const rawData = fs.readFileSync(".all-contributorsrc", "utf-8");
const parsedData = JSON.parse(rawData);
if (!parsedData.contributors) {
throw new Error("contributors key is missing in .all-contributorsrc");
}
const contributors = parsedData.contributors;
const filteredContributors = contributors.map((contributor) => ({
login: contributor.login,
avatar_url: contributor.avatar_url,
contributions: contributor.contributions,
}));
const outputPath = path.join(__dirname, "src", "contributors.json");
if (!fs.existsSync(path.dirname(outputPath))) {
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
}
fs.writeFileSync(outputPath, JSON.stringify(filteredContributors, null, 2));
console.log("Contributors data has been updated successfully.");
} catch (error) {
console.error("Error while generating contributors data:", error.message);
process.exit(1);
}