forked from typescript-eslint/typescript-eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-sponsors.ts
96 lines (87 loc) · 2.03 KB
/
generate-sponsors.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import fetch from 'cross-fetch';
import * as fs from 'fs';
import * as path from 'path';
const graphqlEndpoint = 'https://api.opencollective.com/graphql/v2';
const graphqlQuery = `{
account(slug: "typescript-eslint") {
orders(status: ACTIVE, limit: 1000) {
totalCount
nodes {
tier {
slug
}
fromAccount {
id
name
slug
website
imageUrl
description
}
}
}
}
}`;
const excludedIds = new Set([
'53kzxy4v-07wlr6mr-o9epmj9n-o8agdbe5', // Josh Goldberg
]);
interface SponsorsData {
data: {
account: {
orders: {
nodes: SponsorNode[];
};
};
};
}
interface SponsorNode {
fromAccount: {
description: string;
id: string;
imageUrl: string;
name: string;
slug: string;
twitterHandle: string;
website: string;
};
tier?: {
slug: string;
};
}
async function main(): Promise<void> {
const response = await fetch(graphqlEndpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: graphqlQuery }),
});
const data = (await response.json()) as SponsorsData;
const uniqueIds = new Set<string>(excludedIds);
const allSponsorsConfig = data.data.account.orders.nodes
.filter(node => !!node.tier)
.map(node => ({
description: node.fromAccount.description,
id: node.fromAccount.id,
image: node.fromAccount.imageUrl,
name: node.fromAccount.name,
slug: node.fromAccount.slug,
tier: node.tier.slug,
twitterHandle: node.fromAccount.twitterHandle,
website: node.fromAccount.website,
}))
.filter(({ id }) => {
if (uniqueIds.has(id)) {
return false;
}
uniqueIds.add(id);
return true;
});
const rcPath = path.resolve(
__dirname,
'../packages/website/data/sponsors.json',
);
fs.writeFileSync(rcPath, JSON.stringify(allSponsorsConfig, null, 2));
}
main().catch(error => {
console.error(error);
process.exitCode = 1;
});