UNPKG

1.4 kBJavaScriptView Raw
1import mm from 'micromatch'
2
3export 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// @ts-ignore
26export let isViewFile = async file => mm.isMatch(file, PATTERNS.filesView.match)
27export let isViewLogicFile = async file =>
28 // @ts-ignore
29 mm.isMatch(file, PATTERNS.filesViewLogic.match)
30export let isViewCustomFile = async file =>
31 // @ts-ignore
32 mm.isMatch(file, PATTERNS.filesViewCustom.match)
33export let isFontCustomFile = async file =>
34 // @ts-ignore
35 mm.isMatch(file, PATTERNS.filesFontCustom.match)
36
37export let MATCH = Object.values(PATTERNS)
38 .map(item => item.match)
39 .flat()
40
41export async function getMatchesPerPattern(files) {
42 // @ts-ignore
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}