diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-14 19:58:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 19:58:52 +0200 |
commit | 95df3522a15631abc51a4295cae0ea401a8d4e1e (patch) | |
tree | e5eb0f368c947683f01458e912f21756fb0d99cb /scripts | |
parent | docs: add sad270 as a contributor for bug, userTesting [skip ci] (#1941) (diff) | |
download | ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.gz ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.zst ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.zip |
feat: add eslint-plugin-unicorn (#1936)
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/build-theme-info.js | 40 | ||||
-rw-r--r-- | scripts/link-readme.js | 8 |
2 files changed, 27 insertions, 21 deletions
diff --git a/scripts/build-theme-info.js b/scripts/build-theme-info.js index 4058be942..8aee96ab7 100644 --- a/scripts/build-theme-info.js +++ b/scripts/build-theme-info.js | |||
@@ -23,7 +23,7 @@ async function getRulesFromCssFile(file) { | |||
23 | const cssSrc = (await fs.readFile(file)).toString(); | 23 | const cssSrc = (await fs.readFile(file)).toString(); |
24 | const cssTree = css.parse(cssSrc); | 24 | const cssTree = css.parse(cssSrc); |
25 | 25 | ||
26 | return cssTree.stylesheet.rules; | 26 | return cssTree.stylesheet?.rules; |
27 | } | 27 | } |
28 | 28 | ||
29 | /** | 29 | /** |
@@ -49,25 +49,30 @@ async function getRulesFromCssFile(file) { | |||
49 | function getSelectorsDeclaringValues(rules, values) { | 49 | function getSelectorsDeclaringValues(rules, values) { |
50 | const output = {}; | 50 | const output = {}; |
51 | 51 | ||
52 | rules.forEach((rule) => { | 52 | for (const rule of rules) { |
53 | if (rule.declarations) { | 53 | if (rule.declarations) { |
54 | rule.declarations.forEach((declaration) => { | 54 | for (const declaration of rule.declarations) { |
55 | if (declaration.type === 'declaration' | 55 | if ( |
56 | && values.includes(declaration.value.toLowerCase())) { | 56 | declaration.type === 'declaration' && |
57 | values.includes(declaration.value.toLowerCase()) | ||
58 | ) { | ||
57 | if (!output[declaration.property]) { | 59 | if (!output[declaration.property]) { |
58 | output[declaration.property] = []; | 60 | output[declaration.property] = []; |
59 | } | 61 | } |
60 | output[declaration.property] = output[declaration.property].concat(rule.selectors); | 62 | // eslint-disable-next-line unicorn/prefer-spread |
63 | output[declaration.property] = output[declaration.property].concat( | ||
64 | rule.selectors, | ||
65 | ); | ||
61 | } | 66 | } |
62 | }); | 67 | } |
63 | } | 68 | } |
64 | }); | 69 | } |
65 | 70 | ||
66 | return output; | 71 | return output; |
67 | } | 72 | } |
68 | 73 | ||
69 | async function generateThemeInfo() { | 74 | async function generateThemeInfo() { |
70 | if (!await fs.pathExists(cssFile)) { | 75 | if (!(await fs.pathExists(cssFile))) { |
71 | console.log('Please make sure to build the project first.'); | 76 | console.log('Please make sure to build the project first.'); |
72 | return; | 77 | return; |
73 | } | 78 | } |
@@ -75,23 +80,24 @@ async function generateThemeInfo() { | |||
75 | // Read and parse css bundle | 80 | // Read and parse css bundle |
76 | const rules = await getRulesFromCssFile(cssFile); | 81 | const rules = await getRulesFromCssFile(cssFile); |
77 | 82 | ||
78 | console.log(`Found ${rules.length} rules`); | 83 | console.log(`Found ${rules?.length} rules`); |
79 | 84 | ||
80 | // Get rules specifying the brand colors | 85 | // Get rules specifying the brand colors |
81 | const brandRules = getSelectorsDeclaringValues(rules, accentColors); | 86 | const brandRules = getSelectorsDeclaringValues(rules, accentColors); |
82 | 87 | ||
83 | console.log(`Found ${Object.keys(brandRules).join(', ')} properties that set color to brand color`); | 88 | console.log( |
89 | `Found ${Object.keys(brandRules).join( | ||
90 | ', ', | ||
91 | )} properties that set color to brand color`, | ||
92 | ); | ||
84 | 93 | ||
85 | // Join array of declarations into a single string | 94 | // Join array of declarations into a single string |
86 | Object.keys(brandRules).forEach((rule) => { | 95 | for (const rule of Object.keys(brandRules)) { |
87 | brandRules[rule] = brandRules[rule].join(', '); | 96 | brandRules[rule] = brandRules[rule].join(', '); |
88 | }); | 97 | } |
89 | 98 | ||
90 | // Write object with theme info to file | 99 | // Write object with theme info to file |
91 | fs.writeFile( | 100 | fs.writeFile(outputFile, JSON.stringify(brandRules)); |
92 | outputFile, | ||
93 | JSON.stringify(brandRules), | ||
94 | ); | ||
95 | } | 101 | } |
96 | 102 | ||
97 | generateThemeInfo(); | 103 | generateThemeInfo(); |
diff --git a/scripts/link-readme.js b/scripts/link-readme.js index 1e47cddf8..2ab38912c 100644 --- a/scripts/link-readme.js +++ b/scripts/link-readme.js | |||
@@ -22,7 +22,7 @@ let replacements = 0; | |||
22 | // Regex matches strings that don't begin with a "[", i.e. are not already linked | 22 | // Regex matches strings that don't begin with a "[", i.e. are not already linked |
23 | // followed by a "franz#" and digits to indicate | 23 | // followed by a "franz#" and digits to indicate |
24 | // a GitHub issue, and not ending with a "]" | 24 | // a GitHub issue, and not ending with a "]" |
25 | readme = readme.replace(/(?<!\[)franz#\d{1,}(?![\]\d])/gi, (match) => { | 25 | readme = readme.replace(/(?<!\[)franz#\d+(?![\d\]])/gi, match => { |
26 | const issueNr = match.replace('franz#', ''); | 26 | const issueNr = match.replace('franz#', ''); |
27 | replacements += 1; | 27 | replacements += 1; |
28 | return `[franz#${issueNr}](https://github.com/meetfranz/franz/issues/${issueNr})`; | 28 | return `[franz#${issueNr}](https://github.com/meetfranz/franz/issues/${issueNr})`; |
@@ -31,7 +31,7 @@ readme = readme.replace(/(?<!\[)franz#\d{1,}(?![\]\d])/gi, (match) => { | |||
31 | // Replace external issues | 31 | // Replace external issues |
32 | // Regex matches strings that don't begin with a "[", followed a repo name in the format "user/repo" | 32 | // Regex matches strings that don't begin with a "[", followed a repo name in the format "user/repo" |
33 | // followed by a "#" and digits to indicate a GitHub issue, and not ending with a "]" | 33 | // followed by a "#" and digits to indicate a GitHub issue, and not ending with a "]" |
34 | readme = readme.replace(/(?<!\[)\w+\/\w+#\d{1,}(?![\]\d])/gi, (match) => { | 34 | readme = readme.replace(/(?<!\[)\w+\/\w+#\d+(?![\d\]])/gi, match => { |
35 | const issueNr = match.replace(/\D/g, ''); | 35 | const issueNr = match.replace(/\D/g, ''); |
36 | const repo = match.replace(/#\d+/g, ''); | 36 | const repo = match.replace(/#\d+/g, ''); |
37 | replacements += 1; | 37 | replacements += 1; |
@@ -42,7 +42,7 @@ readme = readme.replace(/(?<!\[)\w+\/\w+#\d{1,}(?![\]\d])/gi, (match) => { | |||
42 | // Regex matches strings that don't begin with a "[", i.e. are not already linked and | 42 | // Regex matches strings that don't begin with a "[", i.e. are not already linked and |
43 | // don't begin with "franz", i.e. are not Franz issues, followed by a "#" and digits to indicate | 43 | // don't begin with "franz", i.e. are not Franz issues, followed by a "#" and digits to indicate |
44 | // a GitHub issue, and not ending with a "]" | 44 | // a GitHub issue, and not ending with a "]" |
45 | readme = readme.replace(/(?<!\[|franz)#\d{1,}(?![\]\d])/gi, (match) => { | 45 | readme = readme.replace(/(?<!\[|franz)#\d+(?![\d\]])/gi, match => { |
46 | const issueNr = match.replace('#', ''); | 46 | const issueNr = match.replace('#', ''); |
47 | replacements += 1; | 47 | replacements += 1; |
48 | return `[#${issueNr}](https://github.com/getferdi/ferdi/issues/${issueNr})`; | 48 | return `[#${issueNr}](https://github.com/getferdi/ferdi/issues/${issueNr})`; |
@@ -51,7 +51,7 @@ readme = readme.replace(/(?<!\[|franz)#\d{1,}(?![\]\d])/gi, (match) => { | |||
51 | // Link GitHub users | 51 | // Link GitHub users |
52 | // Regex matches strings that don't begin with a "[", i.e. are not already linked | 52 | // Regex matches strings that don't begin with a "[", i.e. are not already linked |
53 | // followed by a "@" and at least one word character and not ending with a "]" | 53 | // followed by a "@" and at least one word character and not ending with a "]" |
54 | readme = readme.replace(/(?<!\[)@\w+(?!\])/gi, (match) => { | 54 | readme = readme.replace(/(?<!\[)@\w+(?!])/gi, match => { |
55 | const username = match.replace('@', ''); | 55 | const username = match.replace('@', ''); |
56 | replacements += 1; | 56 | replacements += 1; |
57 | return `[@${username}](https://github.com/${username})`; | 57 | return `[@${username}](https://github.com/${username})`; |