-
-
Notifications
You must be signed in to change notification settings - Fork 290
Expand file tree
/
Copy pathfilter-files.js
More file actions
45 lines (38 loc) · 1003 Bytes
/
filter-files.js
File metadata and controls
45 lines (38 loc) · 1003 Bytes
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
40
41
42
43
44
45
// filters a list of changed file paths to only those relevant for design review
const ALLOWED_EXTENSIONS = [
".css",
".scss",
".sass",
".mdx",
".md",
".tsx",
".jsx",
".js",
".ts",
];
const IGNORED_PATHS = [
"node_modules/",
"build/",
".docusaurus/",
".github/",
"package-lock.json",
"yarn.lock",
"pnpm-lock.yaml",
"DESIGN_GUIDELINES.md",
];
// Only review actual site source directories
const ALLOWED_PATHS = ["src/", "docs/", "versioned_docs/", "blog/", "static/"];
/**
* @param {string[]} files array of file paths from the diff
* @returns {string[]} filtered file paths
*/
function filterFiles(files) {
return files.filter((file) => {
const isIgnored = IGNORED_PATHS.some((p) => file.includes(p));
if (isIgnored) return false;
const hasAllowedExt = ALLOWED_EXTENSIONS.some((ext) => file.endsWith(ext));
if (!hasAllowedExt) return false;
return ALLOWED_PATHS.some((p) => file.startsWith(p));
});
}
module.exports = { filterFiles };