Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThemeBuilder: Rework use customer variables #25383

Merged
merged 12 commits into from
Sep 8, 2023
104 changes: 67 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/devextreme-themebuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"clean-css": "^5.3.0",
"less": "^3.13.1",
"postcss": "^8.2.6",
"sass-embedded": "1.62.0"
"sass-embedded": "1.66.0"
},
"scripts": {
"test": "jest --coverage --verbose --runInBand",
Expand Down
26 changes: 7 additions & 19 deletions packages/devextreme-themebuilder/src/metadata/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export default class MetadataGenerator {
return metaItems;
}

static getOverriddenVariables(metaItems: MetaItem[]): string {
const result = metaItems.map((item) => `${item.Key}: getCustomVar(("${item.Key}")) !default;`).join('\n');
return result;
}

static getMapFromMeta(metaItems: MetaItem[]): string {
const result = metaItems.map((item) => `"${item.Key}": ${item.Key},\n`).join('');
return `(\n${result})`;
Expand All @@ -64,22 +69,10 @@ export default class MetadataGenerator {
return fileName.includes('bundles');
}

static getMainColorsFileTheme(fileName: string): string {
const match = /widgets[/\\](material|generic)[/\\]_colors.scss/.exec(fileName);

if (match === null) return null;

return match[1];
}

static getBundleContent(content: string): string {
return content.replace(/(..\/widgets\/(material|generic))"/, '$1/tb_index"');
}

static getMainColorsFileContent(content: string, theme: string): string {
return content.replace(/\.\/variables/g, `tb_${theme}`);
}

clean(): void {
this.metadata = {
generic: [],
Expand All @@ -105,14 +98,8 @@ export default class MetadataGenerator {
}

let modifiedContent = content;
const mainFileTheme = MetadataGenerator.getMainColorsFileTheme(filePath);

if (mainFileTheme) {
modifiedContent = MetadataGenerator.getMainColorsFileContent(content, mainFileTheme);
}

const metaItems = MetadataGenerator.getMetaItems(content);

if (!metaItems.length) {
return modifiedContent;
}
Expand All @@ -121,8 +108,9 @@ export default class MetadataGenerator {
this.fillMetaData(item, filePath);
});

const overriddenVariables = MetadataGenerator.getOverriddenVariables(metaItems);
const collector = `$never-used: collector(${MetadataGenerator.getMapFromMeta(metaItems)});\n`;
modifiedContent += collector;
modifiedContent = overriddenVariables + '\n\n' + modifiedContent + collector;

return modifiedContent;
}
Expand Down
Loading
Loading