aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
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
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')
-rw-r--r--scripts/add-crowdin-contributors.ts (renamed from scripts/add-crowdin-contributors.js)14
-rw-r--r--scripts/build-theme-info.js103
-rw-r--r--scripts/link-readme.ts (renamed from scripts/link-readme.js)6
-rw-r--r--scripts/postinstall.ts (renamed from scripts/postinstall.js)2
-rw-r--r--scripts/prepare.ts (renamed from scripts/prepare.js)0
5 files changed, 11 insertions, 114 deletions
diff --git a/scripts/add-crowdin-contributors.js b/scripts/add-crowdin-contributors.ts
index 05e377a94..00d12eca1 100644
--- a/scripts/add-crowdin-contributors.js
+++ b/scripts/add-crowdin-contributors.ts
@@ -1,3 +1,7 @@
1import fs from 'fs-extra';
2import path from 'path';
3import allContributors from 'all-contributors-cli';
4
1/** 5/**
2 * Add CrowdIn Contributors to AllContributors list 6 * Add CrowdIn Contributors to AllContributors list
3 * 7 *
@@ -48,17 +52,13 @@ console.clear();
48console.log(JSON.stringify(members)); 52console.log(JSON.stringify(members));
49 53
50 * 3. Paste the output of the script (JSON Array) below to set 'list' to that value 54 * 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' 55 * 4. Execute this script using 'npm run add-crowdin-contributors'
52 * 5. Regenerate the README table using the CLI ('all-contributors generate') 56 * 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. 57 * Please check if the generated data is ok and no data is lost.
54*/ 58*/
55const list = []; 59const list: any[] = [];
56
57const fs = require('fs-extra');
58const path = require('path');
59const allContributors = require('all-contributors-cli');
60 60
61const infoPath = path.join(__dirname, '..', '..', '.all-contributorsrc'); 61const infoPath = path.join(__dirname, '..', '.all-contributorsrc');
62 62
63(async () => { 63(async () => {
64 const info = await fs.readJSON(infoPath); 64 const info = await fs.readJSON(infoPath);
diff --git a/scripts/build-theme-info.js b/scripts/build-theme-info.js
deleted file mode 100644
index 8aee96ab7..000000000
--- a/scripts/build-theme-info.js
+++ /dev/null
@@ -1,103 +0,0 @@
1/**
2 * Script to get information on which selectors use the brand color.
3 * This is needed to provide the accent color feature - the feature will create CSS rules
4 * to overwrite the color of these selectors.
5 */
6const css = require('css');
7const fs = require('fs-extra');
8const path = require('path');
9const theme = require('@meetfranz/theme');
10
11// Colors that should be replaced with the accent color
12const accentColors = [
13 theme.DEFAULT_ACCENT_COLOR.toLowerCase(),
14 '#7367f0',
15 '#5e50ee',
16];
17
18const cssFile = path.join(__dirname, '..', '..', 'build', 'styles', 'main.css');
19const outputFile = path.join(__dirname, '..', 'assets', 'themeInfo.json');
20
21// Parse and extract the rules from a CSS stylesheet file
22async function getRulesFromCssFile(file) {
23 const cssSrc = (await fs.readFile(file)).toString();
24 const cssTree = css.parse(cssSrc);
25
26 return cssTree.stylesheet?.rules;
27}
28
29/**
30 * Get all selectors from a list of parsed CSS rules that set any property to one of the specified
31 * values.
32 *
33 * This function will output an object in this format:
34 * {
35 * 'property-name': [ array of selectors ]
36 * }
37 *
38 * e.g.
39 * {
40 * 'background-color': [
41 * '.background',
42 * '.input-dark'
43 * ]
44 * }
45 *
46 * @param {Array} rules Rules as outputted by the `css` module
47 * @param {Array} values Array of values that should be searched for
48 */
49function getSelectorsDeclaringValues(rules, values) {
50 const output = {};
51
52 for (const rule of rules) {
53 if (rule.declarations) {
54 for (const declaration of rule.declarations) {
55 if (
56 declaration.type === 'declaration' &&
57 values.includes(declaration.value.toLowerCase())
58 ) {
59 if (!output[declaration.property]) {
60 output[declaration.property] = [];
61 }
62 // eslint-disable-next-line unicorn/prefer-spread
63 output[declaration.property] = output[declaration.property].concat(
64 rule.selectors,
65 );
66 }
67 }
68 }
69 }
70
71 return output;
72}
73
74async function generateThemeInfo() {
75 if (!(await fs.pathExists(cssFile))) {
76 console.log('Please make sure to build the project first.');
77 return;
78 }
79
80 // Read and parse css bundle
81 const rules = await getRulesFromCssFile(cssFile);
82
83 console.log(`Found ${rules?.length} rules`);
84
85 // Get rules specifying the brand colors
86 const brandRules = getSelectorsDeclaringValues(rules, accentColors);
87
88 console.log(
89 `Found ${Object.keys(brandRules).join(
90 ', ',
91 )} properties that set color to brand color`,
92 );
93
94 // Join array of declarations into a single string
95 for (const rule of Object.keys(brandRules)) {
96 brandRules[rule] = brandRules[rule].join(', ');
97 }
98
99 // Write object with theme info to file
100 fs.writeFile(outputFile, JSON.stringify(brandRules));
101}
102
103generateThemeInfo();
diff --git a/scripts/link-readme.js b/scripts/link-readme.ts
index 2ab38912c..77b384ff4 100644
--- a/scripts/link-readme.js
+++ b/scripts/link-readme.ts
@@ -6,12 +6,12 @@
6 * and "@abc" => "[@abc](https://github.com/abc)" 6 * and "@abc" => "[@abc](https://github.com/abc)"
7 */ 7 */
8 8
9const fs = require('fs-extra'); 9import fs from 'fs-extra';
10const path = require('path'); 10import path from 'path';
11 11
12console.log('Linking issues and PRs in README.md'); 12console.log('Linking issues and PRs in README.md');
13 13
14const readmepath = path.join(__dirname, '..', '..', 'README.md'); 14const readmepath = path.join(__dirname, '..', 'README.md');
15 15
16// Read README.md 16// Read README.md
17let readme = fs.readFileSync(readmepath, 'utf-8'); 17let readme = fs.readFileSync(readmepath, 'utf-8');
diff --git a/scripts/postinstall.js b/scripts/postinstall.ts
index 84e7492ef..4fa71c35f 100644
--- a/scripts/postinstall.js
+++ b/scripts/postinstall.ts
@@ -1,4 +1,4 @@
1const { exec } = require('child_process'); 1import { exec } from 'child_process';
2 2
3// eslint-disable-next-line no-console 3// eslint-disable-next-line no-console
4const log = (err, stdout, stderr) => console.log(err || stdout || stderr); 4const log = (err, stdout, stderr) => console.log(err || stdout || stderr);
diff --git a/scripts/prepare.js b/scripts/prepare.ts
index 0b4daa82b..0b4daa82b 100644
--- a/scripts/prepare.js
+++ b/scripts/prepare.ts