summaryrefslogtreecommitdiffstats
path: root/scripts/add-crowdin-contributors.ts
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-09-18 11:15:25 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-18 11:15:25 +0200
commitd4101a48b3eee8b1fb177831aa02a4b4fbec2588 (patch)
treec92f2fbe91197fde8589207463d0d6526b4ff76b /scripts/add-crowdin-contributors.ts
parent5.6.3-nightly.6 [skip ci] (diff)
downloadferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.gz
ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.zst
ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.zip
chore: convert various files from JS to TS (#1959)
Diffstat (limited to 'scripts/add-crowdin-contributors.ts')
-rw-r--r--scripts/add-crowdin-contributors.ts81
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 @@
1import fs from 'fs-extra';
2import path from 'path';
3import 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
17const members = [];
18// All elements containing members
19const membersEl = [...document.querySelectorAll('.ps-members-name')];
20// Remove the first 4 contributors as they are already in the list
21for (let i = 0; i < 4; i += 1) {
22 membersEl.shift();
23}
24membersEl.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
51console.clear();
52console.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*/
59const list: any[] = [];
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})();