Skip to content

Commit e61f2e1

Browse files
authored
Parse 'widgets' option for themebuilder (#109)
1 parent c7b0bb9 commit e61f2e1

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

commands/commands.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
}, {
6868
"name": "--version",
6969
"description": "Specifies the target DevExtreme version or a tag that points to it (the default value is 'latest')"
70+
}, {
71+
"name": "--widgets",
72+
"description": "Specifies a comma-separated list of widgets whose styles should be included in the resulting CSS file (available from DevExtreme 19.2.3). If this argument is not specified, styles of all widgets are included."
7073
}]
7174
}, {
7275
"name": "export-theme-vars",

commands/themebuider.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const semver = require('semver');
34
const runCommand = require('../utility/run-command');
45
const lock = require('../utility/file-lock');
56

@@ -132,6 +133,23 @@ const getDevExtremeVersion = () => {
132133
return;
133134
};
134135

136+
const setWidgetsOption = (options, version) => {
137+
const widgets = options.widgets;
138+
const widgetsArgumentMinVersion = '19.2.3'
139+
const widgetsOptionAvailable = version === 'latest' || semver.gte(version, widgetsArgumentMinVersion);
140+
if(widgets && !widgetsOptionAvailable) {
141+
console.log(`The "--widgets" argument is supported only starting with v${widgetsArgumentMinVersion} and will be ignored.`);
142+
}
143+
if(typeof widgets === 'string') {
144+
options.widgets = widgets.split(',');
145+
}
146+
};
147+
148+
const getVarsFilter = (options) => {
149+
const vars = options.vars || [];
150+
return (vars instanceof Array) ? vars : vars.split(',');
151+
};
152+
135153
const runThemeBuilder = async rawOptions => {
136154
const options = camelize(rawOptions);
137155

@@ -165,11 +183,13 @@ const runThemeBuilder = async rawOptions => {
165183

166184
lock.release();
167185

168-
const result = await themeBuilder.buildTheme(options);
186+
setWidgetsOption(options, version);
169187

170188
let content = '';
171-
const vars = options.vars || [];
172-
let filter = (vars instanceof Array) ? vars : vars.split(',');
189+
190+
const result = await themeBuilder.buildTheme(options);
191+
const filter = getVarsFilter(options);
192+
173193
createPath(options.out);
174194

175195
if(options.command === commands.BUILD_THEME) {
@@ -192,11 +212,17 @@ const runThemeBuilder = async rawOptions => {
192212
exportedMeta.push({ key: metadataKey, value: metadata[metadataKey] });
193213
}
194214

195-
content = JSON.stringify({
215+
const meta = {
196216
baseTheme: [ options.themeName, options.colorScheme.replace(/-/g, '.') ].join('.'),
197217
items: exportedMeta,
198218
version: result.version
199-
}, ' ', 4);
219+
};
220+
221+
if(result.widgets) {
222+
Object.assign(meta, { widgets: result.widgets });
223+
}
224+
225+
content = JSON.stringify(meta, ' ', 4);
200226
}
201227

202228
fs.writeFile(options.out, content, 'utf8', error => {

0 commit comments

Comments
 (0)