forked from ZeusLN/zeus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-styles.test.ts
39 lines (37 loc) · 1.43 KB
/
check-styles.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as fs from 'fs';
import * as path from 'path';
describe('static style sheets', () => {
it('must not contain themeColor() calls', () => {
const dirs = fs
.readdirSync('.', { withFileTypes: true })
.filter((e) => e.isDirectory() && e.name !== 'node_modules')
.map((e) => e.name);
dirs.push('.');
const tsxFiles = dirs.flatMap((dir) =>
fs
.readdirSync(dir, { recursive: dir !== '.' })
// @ts-ignore:next-line
.filter(
(file: any) =>
typeof file === 'string' &&
!file.startsWith('node_modules/') &&
file.toLowerCase().endsWith('.tsx')
)
.map((file: any) => path.join(dir, file as string))
);
const regExp = new RegExp(
/\n[^\s][^\n]+StyleSheet\.create\(\{.*themeColor\(/,
's'
);
const invalidFiles = tsxFiles.filter((file) =>
fs.readFileSync(file).toString('utf8').match(regExp)
);
if (invalidFiles.length > 0) {
throw new Error(
'The following files contain static StyleSheets with themeColor() calls. ' +
'This is not allowed because the color then will not be updated when theme is changed.\n' +
invalidFiles.join('\n')
);
}
});
});