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

Add noClean option for devextreme-themebuilder #11790

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions themebuilder/modules/less-template-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class LessMetadataPreCompiler {
}

class LessMetadataPostCompiler {
constructor(compiledMetadata, swatchSelector, colorScheme) {
constructor(compiledMetadata, swatchSelector, colorScheme, noClean) {
this._metadata = compiledMetadata;
this.swatchSelector = swatchSelector;
this.colorScheme = colorScheme;
this.useCleanCss = !noClean;
}

process(css) {
Expand Down Expand Up @@ -81,7 +82,9 @@ class LessMetadataPostCompiler {
.replace(themeMarkerRegex, '$1' + this.colorScheme + '$3');
}

css = new CleanCss(cleanCssOptions).minify(css).styles;
if(this.useCleanCss) {
css = new CleanCss(cleanCssOptions).minify(css).styles;
}

return css.replace(metadataRegex, '');
}
Expand Down Expand Up @@ -110,6 +113,7 @@ class LessTemplateLoader {
this.swatchSelector = config.makeSwatch ? SWATCH_SELECTOR_PREFIX + config.outColorScheme : '';
this.outColorScheme = config.outColorScheme;
this.version = version;
this.noClean = config.noClean;
}

load(theme, colorScheme, metadata, modifiedItems, widgets) {
Expand Down Expand Up @@ -157,7 +161,7 @@ class LessTemplateLoader {
};

const preCompiler = new LessMetadataPreCompiler(metadata, this.swatchSelector, modifyVars);
const postCompiler = new LessMetadataPostCompiler(compiledMetadata, this.swatchSelector, this.outColorScheme);
const postCompiler = new LessMetadataPostCompiler(compiledMetadata, this.swatchSelector, this.outColorScheme, this.noClean);

less = preCompiler.process(less);

Expand Down
48 changes: 48 additions & 0 deletions themebuilder/tests/less-template-loader-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,52 @@ describe('LessTemplateLoader', () => {
assert.equal(data.version, version);
});
});

it('clean-css works with noClean = false', () => {
const config = {
isBootstrap: false,
lessCompiler: lessCompiler,
reader: path => {
assert.equal(path, 'devextreme-themebuilder/data/less/bundles/dx.light.less');
return new Promise(resolve => {
resolve('@base-bg: #fff;@base-font-family:\'default\';@base-text-color:#0f0;div { font: 14px/1 DXIcons; font-size: 20px; line-height: 20px; }');
});
}
};

const lessTemplateLoader = new LessTemplateLoader(config);
lessTemplateLoader._makeInfoHeader = emptyHeader;

const promises = [];

promises.push(lessTemplateLoader.load(
themeName,
colorScheme,
metadata,
[]
).then(data => {
assert.equal(data.css, `div {
font: 20px/20px DXIcons;
}`);
}));

config.noClean = true;
const lessTemplateLoaderNoClean = new LessTemplateLoader(config);
lessTemplateLoaderNoClean._makeInfoHeader = emptyHeader;
promises.push(lessTemplateLoaderNoClean.load(
themeName,
colorScheme,
metadata,
[]
).then(data => {
assert.equal(data.css, `div {
font: 14px/1 DXIcons;
font-size: 20px;
line-height: 20px;
}
`);
}));

return promises;
});
});