1 | import mm from 'micromatch'
|
2 |
|
3 | export let PATTERNS = {
|
4 | filesView: {
|
5 | match: ['**/view.blocks'],
|
6 | },
|
7 | filesViewLogic: {
|
8 | match: ['**/logic.js'],
|
9 | },
|
10 | filesViewCustom: {
|
11 | match: ['**/react.js'],
|
12 | },
|
13 | filesFontCustom: {
|
14 | match: [
|
15 | '**/DesignSystem/Fonts/*.eot',
|
16 | '**/DesignSystem/Fonts/*.otf',
|
17 | '**/DesignSystem/Fonts/*.ttf',
|
18 | '**/DesignSystem/Fonts/*.svg',
|
19 | '**/DesignSystem/Fonts/*.woff',
|
20 | '**/DesignSystem/Fonts/*.woff2',
|
21 | ],
|
22 | },
|
23 | }
|
24 |
|
25 |
|
26 | export let isViewFile = async file => mm.isMatch(file, PATTERNS.filesView.match)
|
27 | export let isViewLogicFile = async file =>
|
28 |
|
29 | mm.isMatch(file, PATTERNS.filesViewLogic.match)
|
30 | export let isViewCustomFile = async file =>
|
31 |
|
32 | mm.isMatch(file, PATTERNS.filesViewCustom.match)
|
33 | export let isFontCustomFile = async file =>
|
34 |
|
35 | mm.isMatch(file, PATTERNS.filesFontCustom.match)
|
36 |
|
37 | export let MATCH = Object.values(PATTERNS)
|
38 | .map(item => item.match)
|
39 | .flat()
|
40 |
|
41 | export async function getMatchesPerPattern(files) {
|
42 |
|
43 | return Object.fromEntries(
|
44 | await Promise.all(
|
45 | Object.entries(PATTERNS).map(async ([key, { filter, match, ignore }]) => {
|
46 | let matches = mm(files, match, { ignore })
|
47 | if (typeof filter === 'function') {
|
48 | matches = await filter(matches)
|
49 | }
|
50 | return [key, new Set(matches)]
|
51 | })
|
52 | )
|
53 | )
|
54 | }
|