@zohodesk/react-cli 1.1.13 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/docs/ValueReplacer.md +27 -0
- package/lib/plugins/variableConvertorUtils.js +4 -2
- package/lib/postcss-plugins/ValueReplacer.js +7 -17
- package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +65 -17
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -44,6 +44,18 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.1.14 (11-9-2023)
|
48
|
+
|
49
|
+
**Feature:-**
|
50
|
+
|
51
|
+
- Value Replacer supports `^` before and `$` after the word to consider the whole word for replacement. Only if the exact word comes as value, there will be a replacement made.
|
52
|
+
|
53
|
+
**Issue Fix**
|
54
|
+
|
55
|
+
- 'space' character on variable conversion changes to undefined fixed.
|
56
|
+
- calc(100%) variable conversion to undefined fixed.
|
57
|
+
- height value if text converts to undefined, issue fixed.
|
58
|
+
|
47
59
|
# 1.1.13 (4-9-2023)
|
48
60
|
|
49
61
|
**Changes**
|
package/docs/ValueReplacer.md
CHANGED
@@ -58,3 +58,30 @@ new option `valueReplacer` added for replace css property value while build runn
|
|
58
58
|
font: zdf-rCallBar_1 !important;
|
59
59
|
}
|
60
60
|
```
|
61
|
+
|
62
|
+
|
63
|
+
If we need the exact word to be considered for replacement ( that is, if value is `text` and only if the value is `text` and not `text_cursor` or `cursortext` for example, the conversion happens ) we have to use `^` before the word and `$` after the word in the key.
|
64
|
+
|
65
|
+
# For Example :
|
66
|
+
{
|
67
|
+
valueReplacer: [
|
68
|
+
{
|
69
|
+
"props": [
|
70
|
+
"cursor",
|
71
|
+
"--label_cursor",
|
72
|
+
"--checkbox_cursor",
|
73
|
+
"--tag_cursor",
|
74
|
+
"--button_cursor",
|
75
|
+
"--textboxicon_icon_cursor",
|
76
|
+
],
|
77
|
+
"values": {
|
78
|
+
"^default$": "var(--zdr-cursor-default)",
|
79
|
+
"^pointer$": "var(--zdr-cursor-pointer)",
|
80
|
+
"^text$": "var(--zdr-cursor-text)",
|
81
|
+
"^move$": "var(--zdr-cursor-move)",
|
82
|
+
}
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
|
87
|
+
- Here we have added `^` before and `$` after default, pointer, text and move. Only if the exact words default, pointer, text and move are used, the values will be converted.
|
@@ -63,7 +63,7 @@ function convertToCalc(pxReplacement, value) {
|
|
63
63
|
|
64
64
|
function convertCalcValue(pxReplacement, parsedValue) {
|
65
65
|
Object.keys(parsedValue).forEach(key => {
|
66
|
-
if (parsedValue[key].includes('px')) {
|
66
|
+
if (pxReplacement && parsedValue[key].includes('px')) {
|
67
67
|
parsedValue[key] = pxReplacement.replace('$$', parsedValue[key].replace('px', ''));
|
68
68
|
}
|
69
69
|
});
|
@@ -95,7 +95,9 @@ function variableConverter(rootOriginal, variables, settingsObject) {
|
|
95
95
|
}
|
96
96
|
|
97
97
|
const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
|
98
|
-
|
98
|
+
let valArr = decl.value.split(' ');
|
99
|
+
valArr = valArr.filter(x => x.trim() !== '');
|
100
|
+
valArr = valArr.map(x => x.replace(/\r|\t|\n/gi, '')); // single values are considered in the above array and converted below
|
99
101
|
|
100
102
|
valArr.forEach((value, index) => {
|
101
103
|
if (value.includes('px')) {
|
@@ -4,29 +4,19 @@ var _postcss = _interopRequireDefault(require("postcss"));
|
|
4
4
|
|
5
5
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
6
|
|
7
|
-
// module.exports = postcss.plugin('postcss-value-replacer', opts => {
|
8
|
-
// const { plugins } = opts;
|
9
|
-
// return (root, result) => {
|
10
|
-
// const inputFile = root.source.input.file;
|
11
|
-
// let isIgnoredFile= opts.ignore.some(file => inputFile.indexOf(file)!==-1);
|
12
|
-
// if (!isIgnoredFile) {
|
13
|
-
// const handler = response =>
|
14
|
-
// response.messages.forEach(msg => result.messages.push(msg));
|
15
|
-
// return postcss(plugins)
|
16
|
-
// .process(root, { from: undefined })
|
17
|
-
// .then(handler);
|
18
|
-
// }
|
19
|
-
// };
|
20
|
-
// });
|
21
|
-
// export default
|
22
7
|
module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
|
23
8
|
root => {
|
24
9
|
root.walkDecls(decl => {
|
25
10
|
valueReplacer.forEach(obj => {
|
26
11
|
if (obj.props.indexOf(decl.prop) !== -1) {
|
27
|
-
|
12
|
+
const ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
|
28
13
|
ks.forEach(k => {
|
29
|
-
|
14
|
+
// if (/^\^.*\$$/gi.test(k)) {
|
15
|
+
if (k.startsWith('^') && k.endsWith('$')) {
|
16
|
+
decl.value = decl.value.replace(new RegExp(k), obj.values[k]);
|
17
|
+
} else {
|
18
|
+
decl.value = decl.value.replace(k, obj.values[k]);
|
19
|
+
}
|
30
20
|
}); //decl.value = obj.values[decl.value];
|
31
21
|
}
|
32
22
|
}); //console.log({root, roots:root+""}, root+"")
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
var _ValueReplacer = _interopRequireDefault(require("../ValueReplacer"));
|
6
|
+
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
|
+
|
9
|
+
/* eslint-disable no-use-before-define */
|
10
|
+
describe('postcss value replacer tests', () => {
|
11
|
+
it('is creating value replaced code', () => {
|
12
|
+
const cssInputStr = `.abc{ cursor : text }`;
|
13
|
+
const cssOutputStr = `.abc{ cursor : --textCursor }`;
|
14
|
+
const cssOptions = [{
|
15
|
+
props: ['font', 'font-family', 'cursor'],
|
16
|
+
values: {
|
17
|
+
'zdf-': 'zd-react-app-',
|
18
|
+
'^text$': '--textCursor'
|
19
|
+
}
|
20
|
+
}];
|
21
|
+
const result = runValueReplacerForCssString(cssInputStr, cssOptions);
|
22
|
+
expect(result.css).toEqual(cssOutputStr);
|
23
|
+
});
|
24
|
+
});
|
25
|
+
describe('postcss value replacer tests', () => {
|
26
|
+
it('is creating value replaced code', () => {
|
27
|
+
const cssInputStr = `.def{ cursor : var(--textBoxCursor) }`;
|
28
|
+
const cssOutputStr = `.def{ cursor : var(--textBoxCursor) }`;
|
29
|
+
const cssOptions = [{
|
30
|
+
props: ['font', 'font-family', 'cursor'],
|
31
|
+
values: {
|
32
|
+
'zdf-': 'zd-react-app-',
|
33
|
+
'^text$': '--textCursor'
|
34
|
+
}
|
35
|
+
}];
|
36
|
+
const result = runValueReplacerForCssString(cssInputStr, cssOptions);
|
37
|
+
expect(result.css).toEqual(cssOutputStr);
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
function runValueReplacerForCssString(cssInputStr, cssOptions) {
|
42
|
+
return (0, _postcss.default)([(0, _ValueReplacer.default)(cssOptions)]).process(cssInputStr);
|
43
|
+
}
|
@@ -92,7 +92,13 @@ function pxToCalc(value) {
|
|
92
92
|
return arr.join(' ');
|
93
93
|
}
|
94
94
|
|
95
|
-
const singleConvertor = (
|
95
|
+
const singleConvertor = ({
|
96
|
+
value,
|
97
|
+
changeVal,
|
98
|
+
details,
|
99
|
+
range,
|
100
|
+
allowed
|
101
|
+
}) => {
|
96
102
|
const {
|
97
103
|
path,
|
98
104
|
filename,
|
@@ -106,6 +112,10 @@ const singleConvertor = (value, changeVal, details, range) => {
|
|
106
112
|
}
|
107
113
|
}
|
108
114
|
|
115
|
+
if (allowed && allowed.includes(decl.value) && decl.value.toString() !== '0') {
|
116
|
+
return decl.value;
|
117
|
+
}
|
118
|
+
|
109
119
|
if (getNumericValue(value) >= range.start && getNumericValue(value) <= range.end || getNumericValue(value) === 0) {
|
110
120
|
if (value.trim() === '0px') {
|
111
121
|
return '0';
|
@@ -204,6 +214,9 @@ module.exports = {
|
|
204
214
|
.replace(/\d+/gi, '').replace('var(--zd_size)', 'px').replace('var(--zd_font_size)', 'px').replace('rect(', '').replace(')', '').replace('px,', 'px').replace(',', '').split(' ').filter(x => x !== ''); // unit = unit.replace(unit, unit.replace('-',''))
|
205
215
|
// console.log('unit : ');
|
206
216
|
// console.log(unit);
|
217
|
+
// if (decl.prop === 'height') {
|
218
|
+
// console.log(decl.prop, unit, 'case 1');
|
219
|
+
// }
|
207
220
|
|
208
221
|
unit.forEach((val, index) => {
|
209
222
|
allowed.forEach(alwdVal => {
|
@@ -223,21 +236,49 @@ module.exports = {
|
|
223
236
|
unitErrorVal = val;
|
224
237
|
}
|
225
238
|
}
|
226
|
-
}); //
|
239
|
+
}); // if (decl.prop === 'height') {
|
240
|
+
// console.log(decl.prop, unitErrorVal, unitError, unit, 'case 2');
|
241
|
+
// }
|
242
|
+
// console.log(allowed, replacements, range)
|
227
243
|
|
228
244
|
if (!unitError) {
|
229
|
-
|
230
|
-
|
245
|
+
let calcValue = false;
|
246
|
+
|
247
|
+
if (decl.value.includes('calc')) {
|
248
|
+
decl.value = pxToCalc(decl.value);
|
249
|
+
calcValue = true;
|
250
|
+
} // use variable decl.value.split(' ')
|
251
|
+
|
252
|
+
|
253
|
+
if (range && !calcValue) {
|
231
254
|
// console.log('multiple :', decl.value)
|
255
|
+
const tempVal = decl.value; // if (decl.prop === 'height') {
|
256
|
+
// console.log(decl.prop, tempVal, decl.value, allowed, 'case 3');
|
257
|
+
// }
|
258
|
+
// if (decl.prop === 'height') {
|
259
|
+
// console.log('allowed!', decl.prop, decl.value, allowed);
|
260
|
+
// }
|
261
|
+
|
232
262
|
let newVal = '';
|
233
|
-
decl.value.split(' ')
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
263
|
+
let splitValues = decl.value.split(' ');
|
264
|
+
splitValues = splitValues.filter(val => val.trim() !== '');
|
265
|
+
splitValues = splitValues.map(val => val.replace(/\r|\t|\n/gi, ''));
|
266
|
+
splitValues.forEach(singleVal => {
|
267
|
+
newVal += `${singleConvertor({
|
268
|
+
value: singleVal,
|
269
|
+
changeVal: settings.replacements.px,
|
270
|
+
details: {
|
271
|
+
decl,
|
272
|
+
filename,
|
273
|
+
path: fromPath
|
274
|
+
},
|
275
|
+
range,
|
276
|
+
allowed
|
277
|
+
})} `;
|
239
278
|
});
|
240
|
-
decl.value = newVal;
|
279
|
+
decl.value = newVal; // if (decl.prop === 'height') {
|
280
|
+
// console.log(decl.prop, tempVal, newVal, 'case 4');
|
281
|
+
// }
|
241
282
|
}
|
242
283
|
} else {
|
243
284
|
if (!decl.value.includes('calc')) {
|
@@ -276,15 +317,22 @@ module.exports = {
|
|
276
317
|
const valArr = decl.value.split(' ');
|
277
318
|
const settings = settingsObject[decl.prop];
|
278
319
|
const {
|
279
|
-
range
|
320
|
+
range,
|
321
|
+
allowed
|
280
322
|
} = settings;
|
281
323
|
const convertedVals = valArr.map(val => {
|
282
324
|
if (val.includes('px')) {
|
283
|
-
const convertedVal = singleConvertor(
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
325
|
+
const convertedVal = singleConvertor({
|
326
|
+
value: val,
|
327
|
+
changeVal: settings.replacements.px,
|
328
|
+
details: {
|
329
|
+
decl,
|
330
|
+
filename,
|
331
|
+
path: fromPath
|
332
|
+
},
|
333
|
+
range,
|
334
|
+
allowed
|
335
|
+
});
|
288
336
|
return convertedVal ? convertedVal : val;
|
289
337
|
}
|
290
338
|
|
package/npm-shrinkwrap.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zohodesk/react-cli",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.14",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "@zohodesk/react-cli",
|
9
|
-
"version": "1.1.
|
9
|
+
"version": "1.1.14",
|
10
10
|
"license": "ISC",
|
11
11
|
"dependencies": {
|
12
12
|
"@babel/cli": "7.10.5",
|