diff options
Diffstat (limited to 'scripts/add-crowdin-contributors.ts')
-rw-r--r-- | scripts/add-crowdin-contributors.ts | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/scripts/add-crowdin-contributors.ts b/scripts/add-crowdin-contributors.ts new file mode 100644 index 000000000..00d12eca1 --- /dev/null +++ b/scripts/add-crowdin-contributors.ts | |||
@@ -0,0 +1,81 @@ | |||
1 | import fs from 'fs-extra'; | ||
2 | import path from 'path'; | ||
3 | import allContributors from 'all-contributors-cli'; | ||
4 | |||
5 | /** | ||
6 | * Add CrowdIn Contributors to AllContributors list | ||
7 | * | ||
8 | * This script will add CrowdIn Contributors to the list of all contributors. | ||
9 | * As the CrowdIn API doesn't give good access to the data needed, this script | ||
10 | * requires you to manually execute a script on the members page of CrowdIn | ||
11 | * and paste its output into this script. | ||
12 | * | ||
13 | * Usage: | ||
14 | * 1. Open https://crowdin.com/project/getferdi/settings#members | ||
15 | * 2. Open the console and execute the script below: | ||
16 | |||
17 | const members = []; | ||
18 | // All elements containing members | ||
19 | const membersEl = [...document.querySelectorAll('.ps-members-name')]; | ||
20 | // Remove the first 4 contributors as they are already in the list | ||
21 | for (let i = 0; i < 4; i += 1) { | ||
22 | membersEl.shift(); | ||
23 | } | ||
24 | membersEl.forEach((el) => { | ||
25 | const text = el.innerText; | ||
26 | let picture = el.querySelector('img').getAttribute('src'); | ||
27 | picture = picture.replace(/\?.+/, ''); | ||
28 | |||
29 | // Check if the text includes a separate username | ||
30 | if (text.includes('(')) { | ||
31 | const username = /(?<=\()\w*(?=\))/.exec(text)[0]; | ||
32 | const name = /^.*(?= \()/.exec(text)[0]; | ||
33 | |||
34 | if (username) { | ||
35 | members.push({ | ||
36 | name: name || username, | ||
37 | login: username, | ||
38 | avatar_url: picture, | ||
39 | }); | ||
40 | return; | ||
41 | } | ||
42 | } | ||
43 | members.push({ | ||
44 | name: text, | ||
45 | login: text, | ||
46 | avatar_url: picture, | ||
47 | }); | ||
48 | }); | ||
49 | |||
50 | // Output data to console | ||
51 | console.clear(); | ||
52 | console.log(JSON.stringify(members)); | ||
53 | |||
54 | * 3. Paste the output of the script (JSON Array) below to set 'list' to that value | ||
55 | * 4. Execute this script using 'npm run add-crowdin-contributors' | ||
56 | * 5. Regenerate the README table using the CLI ('all-contributors generate') | ||
57 | * Please check if the generated data is ok and no data is lost. | ||
58 | */ | ||
59 | const list: any[] = []; | ||
60 | |||
61 | const infoPath = path.join(__dirname, '..', '.all-contributorsrc'); | ||
62 | |||
63 | (async () => { | ||
64 | const info = await fs.readJSON(infoPath); | ||
65 | |||
66 | for (const user of list) { | ||
67 | // eslint-disable-next-line no-await-in-loop | ||
68 | info.contributors = await allContributors.addContributorWithDetails({ | ||
69 | ...user, | ||
70 | contributions: ['translation'], | ||
71 | profile: `https://crowdin.com/profile/${user.login}`, | ||
72 | options: { | ||
73 | contributors: info.contributors, | ||
74 | }, | ||
75 | }); | ||
76 | } | ||
77 | |||
78 | fs.writeJSON(infoPath, info, { | ||
79 | spaces: 2, | ||
80 | }); | ||
81 | })(); | ||