-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfeatureEliminationUtil.ts
63 lines (55 loc) · 1.79 KB
/
featureEliminationUtil.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import configFeatures from "./module.config";
/**
* @interface ConfigFeature
*/
interface ConfigFeature {
skippedFeatures: string[];
features: {
[featureName: string]: {
pages?: string[];
components?: {
name: string;
path: string;
}[];
};
};
skippedComponents?: string[];
includes: (componentName: string) => void;
}
// Cast the imported configFeatures to the defined interface
const typedConfigFeatures = configFeatures as ConfigFeature;
/**
* Generic function to check if a feature or component is skipped.
* @param {string} name
* @param {("feature" | "component")} type
* @returns {boolean}
*/
export const isEliminatedFromBuild = (name: string, type: "feature" | "component"): boolean => {
if (!name || name.trim() === "") return false;
// For feature check
if (type === "feature") {
const skippedFeatures = typedConfigFeatures.skippedFeatures || [];
const validSkippedFeatures = skippedFeatures.filter(f => f.trim() !== "");
return validSkippedFeatures.includes(name);
}
// For component check
if (type === "component") {
const skippedComponents: string[] = [];
const skippedFeatures = typedConfigFeatures.skippedFeatures || [];
skippedFeatures.forEach((featureName) => {
// Find the corresponding feature in the config
const feature = typedConfigFeatures.features[featureName];
if (feature && feature.components) {
// If the feature has components, push them to the skippedComponents array
feature.components.forEach((component) => {
if (component.name) {
skippedComponents.push(component.name);
}
});
}
});
console.log('Filtered skippedComponents', skippedComponents);
return skippedComponents.includes(name);
}
return false;
};