aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/add-crowdin-contributors.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/add-crowdin-contributors.js')
-rw-r--r--scripts/add-crowdin-contributors.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/scripts/add-crowdin-contributors.js b/scripts/add-crowdin-contributors.js
new file mode 100644
index 000000000..05e377a94
--- /dev/null
+++ b/scripts/add-crowdin-contributors.js
@@ -0,0 +1,81 @@
1/**
2 * Add CrowdIn Contributors to AllContributors list
3 *
4 * This script will add CrowdIn Contributors to the list of all contributors.
5 * As the CrowdIn API doesn't give good access to the data needed, this script
6 * requires you to manually execute a script on the members page of CrowdIn
7 * and paste its output into this script.
8 *
9 * Usage:
10 * 1. Open https://crowdin.com/project/getferdi/settings#members
11 * 2. Open the console and execute the script below:
12
13const members = [];
14// All elements containing members
15const membersEl = [...document.querySelectorAll('.ps-members-name')];
16// Remove the first 4 contributors as they are already in the list
17for (let i = 0; i < 4; i += 1) {
18 membersEl.shift();
19}
20membersEl.forEach((el) => {
21 const text = el.innerText;
22 let picture = el.querySelector('img').getAttribute('src');
23 picture = picture.replace(/\?.+/, '');
24
25 // Check if the text includes a separate username
26 if (text.includes('(')) {
27 const username = /(?<=\()\w*(?=\))/.exec(text)[0];
28 const name = /^.*(?= \()/.exec(text)[0];
29
30 if (username) {
31 members.push({
32 name: name || username,
33 login: username,
34 avatar_url: picture,
35 });
36 return;
37 }
38 }
39 members.push({
40 name: text,
41 login: text,
42 avatar_url: picture,
43 });
44});
45
46// Output data to console
47console.clear();
48console.log(JSON.stringify(members));
49
50 * 3. Paste the output of the script (JSON Array) below to set 'list' to that value
51 * 4. Execute this script using 'node scripts/add-crowdin-contributors.js'
52 * 5. Regenerate the README table using the CLI ('all-contributors generate')
53 * Please check if the generated data is ok and no data is lost.
54*/
55const list = [];
56
57const fs = require('fs-extra');
58const path = require('path');
59const allContributors = require('all-contributors-cli');
60
61const 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})();