@zohodesk/react-cli 0.0.1-exp.167.1 → 0.0.1-exp.167.2
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/.eslintrc.js +1 -0
- package/.prettierrc +6 -0
- package/README.md +98 -3
- package/bin/cli.js +10 -20
- package/docs/HoverActive.md +12 -0
- package/docs/InstallNode.md +28 -0
- package/docs/VariableConversion.md +678 -0
- package/lib/common/splitChunks.js +133 -7
- package/lib/configs/jest.config.js +8 -12
- package/lib/configs/libAlias.js +10 -3
- package/lib/configs/webpack.dev.config.js +21 -26
- package/lib/configs/webpack.docs.config.js +13 -19
- package/lib/configs/webpack.impact.config.js +13 -19
- package/lib/configs/webpack.prod.config.js +19 -15
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -7
- package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
- package/lib/loaderUtils/getCSSLoaders.js +51 -7
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +63 -54
- package/lib/postcss-plugins/{ExcludeRTLPlugin.js → ExcludePlugin.js} +1 -1
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +22 -0
- package/lib/postcss-plugins/__test__/test1Input.css +39 -0
- package/lib/postcss-plugins/__test__/test1Output.css +39 -0
- package/lib/postcss-plugins/hoverActivePlugin.js +385 -0
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +37 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +247 -0
- package/lib/postcss-plugins/variableModifier.js +244 -0
- package/lib/schemas/index.js +57 -6
- package/lib/servers/getCliPath.js +7 -3
- package/lib/utils/getOptions.js +29 -1
- package/package.json +4 -3
- package/cert/cert.pem +0 -37
- package/cert/key.pem +0 -27
- package/cert/passphrase.pem +0 -1
- package/eslint/NOTES.md +0 -3
- package/eslint/React_CDN.zip +0 -0
- package/eslint/a.sh +0 -14
- package/eslint/a23.c +0 -16
- package/eslint/a28.c +0 -25
- package/eslint/a29.c +0 -25
- package/eslint/a30.c +0 -29
- package/eslint/a31.c +0 -23
- package/eslint/a35.c +0 -23
- package/eslint/a36.c +0 -18
- package/eslint/a37.c +0 -25
- package/eslint/a38.c +0 -28
- package/eslint/a39.c +0 -17
- package/eslint/a40.c +0 -32
- package/eslint/mockapi.html +0 -18
- package/eslint/mockapi.md +0 -5
- package/eslint/testa/build.sh +0 -7
- package/eslint/testa/build1/index.html +0 -12
- package/eslint/testa/build1/js/2_.js +0 -15
- package/eslint/testa/build1/js/2_.js.map +0 -1
- package/eslint/testa/build1/js/main_.js +0 -40
- package/eslint/testa/build1/js/main_.js.map +0 -1
- package/eslint/testa/build1/js/runtime~main_.js +0 -251
- package/eslint/testa/build1/js/runtime~main_.js.map +0 -1
- package/eslint/testa/build2/index.html +0 -12
- package/eslint/testa/build2/js/2_.js +0 -15
- package/eslint/testa/build2/js/2_.js.map +0 -1
- package/eslint/testa/build2/js/3_.js +0 -15
- package/eslint/testa/build2/js/3_.js.map +0 -1
- package/eslint/testa/build2/js/main_.js +0 -46
- package/eslint/testa/build2/js/main_.js.map +0 -1
- package/eslint/testa/build2/js/runtime~main_.js +0 -251
- package/eslint/testa/build2/js/runtime~main_.js.map +0 -1
- package/eslint/testa/build3/index.710b00fba04c6c594ad3.html +0 -12
- package/eslint/testa/build3/js/2.321b867f0966f9c9cdfd_.js +0 -1
- package/eslint/testa/build3/js/main.eb2aec4c9f1c16a385e0_.js +0 -1
- package/eslint/testa/build3/js/runtime~main.fafbbe7484e9c126f4f7_.js +0 -1
- package/eslint/testa/build3/manifest.json +0 -1
- package/eslint/testa/build4/index.9ff03a2ccdc9b904f1fe.html +0 -12
- package/eslint/testa/build4/js/2.8b63ce57af6dd2bac274_.js +0 -1
- package/eslint/testa/build4/js/3.5208acbe37a44362090e_.js +0 -1
- package/eslint/testa/build4/js/main.a934d6c2e2329d97269e_.js +0 -1
- package/eslint/testa/build4/js/runtime~main.5b85dd9ab73069c1455a_.js +0 -1
- package/eslint/testa/build4/manifest.json +0 -1
- package/eslint/testa/package.json +0 -24
- package/eslint/testa/scr/chunk1.js +0 -3
- package/eslint/testa/scr/chunk2.js +0 -3
- package/eslint/testa/scr/index.html +0 -12
- package/eslint/testa/scr/index.js +0 -4
- package/eslint/testa/scr/utlis.js +0 -12
- package/eslint/testa/src/chunk1.js +0 -3
- package/eslint/testa/src/index.html +0 -12
- package/eslint/testa/src/index.js +0 -3
- package/eslint/testa/src/utlis.js +0 -7
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* we have give support for ignore(exclude) comments
|
|
9
|
+
* These are the comments' keyword
|
|
10
|
+
*/
|
|
11
|
+
const hoverIgnoreQuery = 'Hover:ignore',
|
|
12
|
+
activeIgnoreQuery = 'Active:ignore',
|
|
13
|
+
hoverActiveIgnoreQuery = 'HoverActive:ignore';
|
|
14
|
+
const medHoverIgnoreQuery = 'MedHover:ignore',
|
|
15
|
+
medActiveIgnoreQuery = 'MedActive:ignore',
|
|
16
|
+
medHoverActiveIgnoreQuery = 'MedHoverActive:ignore';
|
|
17
|
+
let hoverMedQuerySuffix = '';
|
|
18
|
+
let hoverNoneMedQuerySuffix = '';
|
|
19
|
+
const ruleIgnoreCommentRegex = /(Hover:ignore|Active:ignore|HoverActive:ignore)/g;
|
|
20
|
+
const mediaQueryIgnoreCommentRegex = /(MedHover:ignore|MedActive:ignore|MedHoverActive:ignore)/g;
|
|
21
|
+
|
|
22
|
+
function isComment(node) {
|
|
23
|
+
return node && node.type === 'comment' && node.text !== undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isHoverPresent(atrule) {
|
|
27
|
+
let hoverPresent = false;
|
|
28
|
+
atrule.walkRules(rule => {
|
|
29
|
+
if (rule.selector.includes('hover')) {
|
|
30
|
+
hoverPresent = true;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return hoverPresent;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function checkForUsualClass(root, sel) {
|
|
37
|
+
let present = false;
|
|
38
|
+
sel.split(',').forEach(value => {
|
|
39
|
+
if (value.includes('hover')) {
|
|
40
|
+
const valueNoHover = value.replace(':hover', '').trim();
|
|
41
|
+
root.walkRules(rule => {
|
|
42
|
+
if (rule.selector === valueNoHover) {
|
|
43
|
+
present = true;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return present;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHoverActiveString => rootOriginal => {
|
|
52
|
+
const hoverRules = [];
|
|
53
|
+
const positionsObj = {};
|
|
54
|
+
hoverMedQuerySuffix = mediaQueryHoverActiveString.hover;
|
|
55
|
+
hoverNoneMedQuerySuffix = mediaQueryHoverActiveString.none;
|
|
56
|
+
|
|
57
|
+
function isRuleHasIgnoreComment(index, type) {
|
|
58
|
+
const prevNode = rootOriginal.nodes[index - 1];
|
|
59
|
+
|
|
60
|
+
if (isComment(prevNode)) {
|
|
61
|
+
return prevNode.text === type;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isMediaQueryHasIgnoreComment(node, type) {
|
|
68
|
+
if (isComment(node)) {
|
|
69
|
+
return node.text === type;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function hasIgnoreComment({
|
|
76
|
+
index,
|
|
77
|
+
atrule,
|
|
78
|
+
type
|
|
79
|
+
}) {
|
|
80
|
+
if (type.match(mediaQueryIgnoreCommentRegex)) {
|
|
81
|
+
return isMediaQueryHasIgnoreComment(atrule.nodes[index - 1], type.slice(3));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (type.match(ruleIgnoreCommentRegex)) {
|
|
85
|
+
return isRuleHasIgnoreComment(index, type);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getPositionsOfHoverAndActiveMedQueries(parent) {
|
|
92
|
+
const allNodes = rootOriginal.nodes;
|
|
93
|
+
const hoverMediaQuery = `${parent.params} and ${hoverMedQuerySuffix}`;
|
|
94
|
+
const hoverNoneMediaQuery = `${parent.params} and ${hoverNoneMedQuerySuffix}`;
|
|
95
|
+
const positions = {
|
|
96
|
+
hovMed: allNodes[positionsObj[hoverMediaQuery]],
|
|
97
|
+
actMed: allNodes[positionsObj[hoverNoneMediaQuery]]
|
|
98
|
+
};
|
|
99
|
+
return positions;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function handleMedHoverAndHoverActiveIgnore(atrule, index) {
|
|
103
|
+
return !hasIgnoreComment({
|
|
104
|
+
atrule,
|
|
105
|
+
index,
|
|
106
|
+
type: medHoverIgnoreQuery
|
|
107
|
+
}) && !hasIgnoreComment({
|
|
108
|
+
atrule,
|
|
109
|
+
index,
|
|
110
|
+
type: medHoverActiveIgnoreQuery
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function handleMedActiveAndHoverActiveIgnore(atrule, index) {
|
|
115
|
+
return !hasIgnoreComment({
|
|
116
|
+
atrule,
|
|
117
|
+
index,
|
|
118
|
+
type: medActiveIgnoreQuery
|
|
119
|
+
}) && !hasIgnoreComment({
|
|
120
|
+
atrule,
|
|
121
|
+
index,
|
|
122
|
+
type: medHoverActiveIgnoreQuery
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function handleHoverAndHoverActiveIgnore(index) {
|
|
127
|
+
return !hasIgnoreComment({
|
|
128
|
+
index,
|
|
129
|
+
type: hoverIgnoreQuery
|
|
130
|
+
}) && !hasIgnoreComment({
|
|
131
|
+
index,
|
|
132
|
+
type: hoverActiveIgnoreQuery
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function handleActiveAndHoverActiveIgnore(index) {
|
|
137
|
+
return !hasIgnoreComment({
|
|
138
|
+
index,
|
|
139
|
+
type: activeIgnoreQuery
|
|
140
|
+
}) && !hasIgnoreComment({
|
|
141
|
+
index,
|
|
142
|
+
type: hoverActiveIgnoreQuery
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function handleAllIgnoreCases(index) {
|
|
147
|
+
return !hasIgnoreComment({
|
|
148
|
+
index,
|
|
149
|
+
type: activeIgnoreQuery
|
|
150
|
+
}) && !hasIgnoreComment({
|
|
151
|
+
index,
|
|
152
|
+
type: hoverIgnoreQuery
|
|
153
|
+
}) && !hasIgnoreComment({
|
|
154
|
+
index,
|
|
155
|
+
type: hoverActiveIgnoreQuery
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function mediaCommaQuery(rule, index) {
|
|
160
|
+
if (rule.parent.params !== undefined && !rule.parent.params.includes('hover')) {
|
|
161
|
+
//console.log(hovMed, actMed);
|
|
162
|
+
let newSelector = '';
|
|
163
|
+
const {
|
|
164
|
+
hovMed,
|
|
165
|
+
actMed
|
|
166
|
+
} = getPositionsOfHoverAndActiveMedQueries(rule.parent);
|
|
167
|
+
const hovQueries = [];
|
|
168
|
+
const actQueries = [];
|
|
169
|
+
rule.selector.split(/\s*,\s*/).forEach(_subrule => {
|
|
170
|
+
const subrule = _subrule.trim();
|
|
171
|
+
|
|
172
|
+
const clone = rule.clone();
|
|
173
|
+
|
|
174
|
+
if (subrule.includes('hover')) {
|
|
175
|
+
clone.selector = subrule;
|
|
176
|
+
|
|
177
|
+
if (handleMedHoverAndHoverActiveIgnore(rule.parent, index)) {
|
|
178
|
+
hovQueries.push(subrule);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (handleMedActiveAndHoverActiveIgnore(rule.parent, index)) {
|
|
182
|
+
actQueries.push(subrule);
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
newSelector += `${subrule}, `;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (hovQueries.length > 0) {
|
|
190
|
+
const clone = rule.clone();
|
|
191
|
+
clone.selector = hovQueries.join(',');
|
|
192
|
+
hovMed.append(clone);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (actQueries.length > 0) {
|
|
196
|
+
const clone = rule.clone();
|
|
197
|
+
clone.selector = actQueries.join(',');
|
|
198
|
+
actMed.append(clone.clone({
|
|
199
|
+
selector: clone.selector.replace(/:hover/gi, ':active')
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (handleMedHoverAndHoverActiveIgnore(rule.parent, index)) {
|
|
204
|
+
rule.selector = newSelector.substring(0, newSelector.length - 2);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (rule.selector === '') {
|
|
208
|
+
rule.remove();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function mediaQuery(rule, index) {
|
|
214
|
+
if (rule.parent.params !== undefined && !rule.parent.params.includes('hover')) {
|
|
215
|
+
const {
|
|
216
|
+
hovMed,
|
|
217
|
+
actMed
|
|
218
|
+
} = getPositionsOfHoverAndActiveMedQueries(rule.parent);
|
|
219
|
+
|
|
220
|
+
if (rule.selector.includes('hover') && hovMed !== undefined && rule.parent.type === 'atrule') {
|
|
221
|
+
if (handleMedHoverAndHoverActiveIgnore(rule.parent, index)) {
|
|
222
|
+
hovMed.append(rule);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (handleMedActiveAndHoverActiveIgnore(rule.parent, index)) {
|
|
226
|
+
actMed.append(rule.clone({
|
|
227
|
+
selector: rule.selector.replace(/:hover/gi, ':active')
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function commaQuery(rule, index) {
|
|
235
|
+
//console.log("comma" , rule.selector.split('\n'));
|
|
236
|
+
let newSelector = '';
|
|
237
|
+
const hovQueries = [];
|
|
238
|
+
rule.selector.split(/\s*,\s*/).forEach(_subrule => {
|
|
239
|
+
const subrule = _subrule.trim();
|
|
240
|
+
|
|
241
|
+
if (subrule.includes('hover')) {
|
|
242
|
+
// hoverRules.push({ rule: clone, index });
|
|
243
|
+
hovQueries.push(subrule);
|
|
244
|
+
} else {
|
|
245
|
+
newSelector += `${subrule}, `;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
if (hovQueries.length > 0) {
|
|
250
|
+
const clone = rule.clone();
|
|
251
|
+
clone.selector = hovQueries.join(',');
|
|
252
|
+
hoverRules.push({
|
|
253
|
+
rule: clone,
|
|
254
|
+
index
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (handleHoverAndHoverActiveIgnore(index)) {
|
|
259
|
+
if (checkForUsualClass(rootOriginal, rule.selector)) {
|
|
260
|
+
rule.selector = newSelector.substring(0, newSelector.length - 2).trim();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (rule.selector === '') {
|
|
265
|
+
rule.remove();
|
|
266
|
+
}
|
|
267
|
+
} // Start by identifying all :hover rules
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
rootOriginal.walkAtRules(atrule => {
|
|
271
|
+
const hoverQuery = `${atrule.params} and ${hoverMedQuerySuffix}`;
|
|
272
|
+
const activeQuery = `${atrule.params} and ${hoverNoneMedQuerySuffix}`;
|
|
273
|
+
|
|
274
|
+
if (isHoverPresent(atrule)) {
|
|
275
|
+
if (!positionsObj[hoverQuery] && !positionsObj[activeQuery]) {
|
|
276
|
+
rootOriginal.append({
|
|
277
|
+
name: 'media',
|
|
278
|
+
params: hoverQuery
|
|
279
|
+
});
|
|
280
|
+
positionsObj[hoverQuery] = rootOriginal.nodes.length - 1;
|
|
281
|
+
rootOriginal.append({
|
|
282
|
+
name: 'media',
|
|
283
|
+
params: activeQuery
|
|
284
|
+
});
|
|
285
|
+
positionsObj[activeQuery] = rootOriginal.nodes.length - 1;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
rootOriginal.walkRules(/:hover/i, (rule, index) => {
|
|
290
|
+
// media hover query with ',' ' ' '+'
|
|
291
|
+
// console.log("media query" , rule.selector)
|
|
292
|
+
if (rule.parent.type === 'atrule' && rule.selector.includes(',')) {
|
|
293
|
+
//console.log("media comma", rule.selector)
|
|
294
|
+
mediaCommaQuery(rule, index);
|
|
295
|
+
} else {
|
|
296
|
+
// plus, space and other media queries
|
|
297
|
+
//console.log("media", rule.selector)
|
|
298
|
+
mediaQuery(rule, index);
|
|
299
|
+
} // usual hover query
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
if (!rule.selector.match(/,+| +|\++/g) && rule.parent !== undefined && rule.parent.name === undefined) {
|
|
303
|
+
hoverRules.push({
|
|
304
|
+
rule,
|
|
305
|
+
index
|
|
306
|
+
});
|
|
307
|
+
} //usual hover query with ',' ' ' '+'
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
if (rule.selector.match(/,+| +|\++/g) && rule.parent.name === undefined) {
|
|
311
|
+
if (rule.selector.includes(',')) {
|
|
312
|
+
commaQuery(rule, index);
|
|
313
|
+
} else if (rule.selector.match(/ +|\++/g)) {
|
|
314
|
+
//console.log("plus or space" , rule.selector);
|
|
315
|
+
if (rule.selector.includes('hover')) {
|
|
316
|
+
hoverRules.push({
|
|
317
|
+
rule,
|
|
318
|
+
index
|
|
319
|
+
}); //rule.remove();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}); // If there are any :hover rules in the input, then create media queries
|
|
324
|
+
// to automatically translate it into :active on touch-based devices
|
|
325
|
+
|
|
326
|
+
if (hoverRules.length > 0) {
|
|
327
|
+
// Create a media query targetting devices that actually support
|
|
328
|
+
// hover
|
|
329
|
+
const hoverQuery = rootOriginal.append({
|
|
330
|
+
name: 'media',
|
|
331
|
+
params: `${hoverMedQuerySuffix}`
|
|
332
|
+
}).last; // Create a media query targetting devices that don't support hover
|
|
333
|
+
// (ie. devices where we should fall back to :active instead)
|
|
334
|
+
|
|
335
|
+
const activeQuery = rootOriginal.append({
|
|
336
|
+
name: 'media',
|
|
337
|
+
params: `${hoverNoneMedQuerySuffix}`
|
|
338
|
+
}).last; // Loop through the hover rules and apply them to each of the media
|
|
339
|
+
// queries
|
|
340
|
+
// eslint-disable-next-line no-labels
|
|
341
|
+
|
|
342
|
+
outerLoop: for (const hoverRule of hoverRules) {
|
|
343
|
+
// determine if the rule has been nested inside another media
|
|
344
|
+
// query; in that case bail out as we have no way of reliably
|
|
345
|
+
// nesting these queries
|
|
346
|
+
let parentRule = hoverRule.rule.parent;
|
|
347
|
+
|
|
348
|
+
while (parentRule) {
|
|
349
|
+
if (parentRule.type === 'atrule' && parentRule.name === 'media') {
|
|
350
|
+
// eslint-disable-next-line no-labels
|
|
351
|
+
continue outerLoop;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
parentRule = parentRule.parent;
|
|
355
|
+
} // Push a clone of the :hover rule 'as is' to queries where we
|
|
356
|
+
// expect the user's device to support hover
|
|
357
|
+
// ieQuery.append(hoverRule.clone());
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
if (handleHoverAndHoverActiveIgnore(hoverRule.index)) {
|
|
361
|
+
hoverQuery.append(hoverRule.rule.clone());
|
|
362
|
+
} // Push a clone of the :hover rule, where we transform the
|
|
363
|
+
// selector to :active to the query targetting devices that
|
|
364
|
+
// don't support hover
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
if (handleActiveAndHoverActiveIgnore(hoverRule.index)) {
|
|
368
|
+
activeQuery.append(hoverRule.rule.clone({
|
|
369
|
+
selector: hoverRule.rule.selector.replace(/:hover/gi, ':active')
|
|
370
|
+
}));
|
|
371
|
+
} // remove legacy rule from output
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
if (handleAllIgnoreCases(hoverRule.index)) {
|
|
375
|
+
hoverRule.rule.remove();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
rootOriginal.walkAtRules(atrule => {
|
|
381
|
+
if (atrule !== undefined && atrule.nodes !== undefined && atrule.nodes.length === 0 || atrule.nodes === undefined) {
|
|
382
|
+
atrule.remove();
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ErrorHandler = void 0;
|
|
7
|
+
|
|
8
|
+
class ErrorHandler {
|
|
9
|
+
constructor(allowedErrs) {
|
|
10
|
+
this.errors = [];
|
|
11
|
+
this.allowedErrs = allowedErrs;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addError(errstr) {
|
|
15
|
+
this.errors.push(`{\n${errstr}\n}\n`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
errorFunction(errStr, type) {
|
|
19
|
+
const {
|
|
20
|
+
addError,
|
|
21
|
+
allowedErrs
|
|
22
|
+
} = this;
|
|
23
|
+
|
|
24
|
+
if (type === 'DECLARATION_IGNORED' && allowedErrs.DECLARATION_IGNORED) {
|
|
25
|
+
addError(errStr);
|
|
26
|
+
} else if (type === 'UNIT_ERROR' && allowedErrs.UNIT_ERROR) {
|
|
27
|
+
addError(errStr);
|
|
28
|
+
} else if (type === 'RANGE_ERROR' && allowedErrs.RANGE_ERROR) {
|
|
29
|
+
addError(errStr);
|
|
30
|
+
} else if (type === 'VARIABLE_PRESENT' && allowedErrs.VARIABLE_PRESENT) {
|
|
31
|
+
addError(errStr);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.ErrorHandler = ErrorHandler;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const postcss = require('postcss');
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
const errors = [];
|
|
10
|
+
let allowedErrs = {};
|
|
11
|
+
const convertableProps = {
|
|
12
|
+
'font-size': true,
|
|
13
|
+
margin: true,
|
|
14
|
+
'margin-left': true,
|
|
15
|
+
'margin-right': true,
|
|
16
|
+
'margin-top': true,
|
|
17
|
+
'margin-bottom': true,
|
|
18
|
+
padding: true,
|
|
19
|
+
'padding-top': true,
|
|
20
|
+
'padding-bottom': true,
|
|
21
|
+
'padding-left': true,
|
|
22
|
+
'padding-right': true,
|
|
23
|
+
width: true,
|
|
24
|
+
'min-width': true,
|
|
25
|
+
'max-width': true,
|
|
26
|
+
height: true,
|
|
27
|
+
'min-height': true,
|
|
28
|
+
'max-height': true,
|
|
29
|
+
top: true,
|
|
30
|
+
bottom: true,
|
|
31
|
+
left: true,
|
|
32
|
+
right: true
|
|
33
|
+
};
|
|
34
|
+
const constantValues = {
|
|
35
|
+
inherit: true,
|
|
36
|
+
initial: true,
|
|
37
|
+
auto: true,
|
|
38
|
+
'fit-content': true,
|
|
39
|
+
unset: true
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function getNumericValue(value) {
|
|
43
|
+
if (value.includes('var')) {
|
|
44
|
+
return parseInt(value.replace(/var\(--zd_size(\d+)\)/gi, '$1').replace(/var\(--zd_font_size(\d+)\)/gi, '$1'));
|
|
45
|
+
} // Not need for this dum loop
|
|
46
|
+
// allowed.forEach(alwdUnit => {
|
|
47
|
+
// if (value.includes(alwdUnit)) {
|
|
48
|
+
// return parseInt(value);
|
|
49
|
+
// }
|
|
50
|
+
// });
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if (constantValues[value.toLowerCase()]) {
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return parseInt(value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function pxToCalc(value) {
|
|
61
|
+
const arr = value.split(' ');
|
|
62
|
+
arr.forEach((val, index) => {
|
|
63
|
+
['px'].forEach(unit => {
|
|
64
|
+
const valWithUnit = new RegExp(`(\\d+)${unit}`, 'gi');
|
|
65
|
+
|
|
66
|
+
if (valWithUnit.test(val)) {
|
|
67
|
+
arr[index] = val.replace(valWithUnit, '(var(--zd_size$1))');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
return arr.join(' ');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const addError = errstr => {
|
|
75
|
+
errors.push(`{\n${errstr}\n}\n`);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const errorFunction = (errStr, type) => {
|
|
79
|
+
if (type === 'DECLARATION_IGNORED' && allowedErrs.DECLARATION_IGNORED) {
|
|
80
|
+
addError(errStr);
|
|
81
|
+
} else if (type === 'UNIT_ERROR' && allowedErrs.UNIT_ERROR) {
|
|
82
|
+
addError(errStr);
|
|
83
|
+
} else if (type === 'RANGE_ERROR' && allowedErrs.RANGE_ERROR) {
|
|
84
|
+
addError(errStr);
|
|
85
|
+
} else if (type === 'VARIABLE_PRESENT' && allowedErrs.VARIABLE_PRESENT) {
|
|
86
|
+
addError(errStr);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const singleConvertor = (value, changeVal, details, range) => {
|
|
91
|
+
const {
|
|
92
|
+
path,
|
|
93
|
+
filename,
|
|
94
|
+
decl
|
|
95
|
+
} = details;
|
|
96
|
+
|
|
97
|
+
if (getNumericValue(value) >= range.start && getNumericValue(value) <= range.end || getNumericValue(value) === 0) {
|
|
98
|
+
let retVal = value.replace(/(\d+)px/gi, changeVal.replace('$$', '$1'));
|
|
99
|
+
|
|
100
|
+
if (/^-var/.test(retVal)) {
|
|
101
|
+
retVal = `calc( ${retVal.substring(1)} * -1 )`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return retVal;
|
|
105
|
+
} // if(unitErrorVal && unitErrorVal != '0' ){
|
|
106
|
+
// console.log(value, 'not within range')
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
errorFunction(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${path} ,\n line : ${decl.source.start.line} ,\n message : value (${value}) (${typeof value}) not within range (${range.start},${range.end})\r`, 'RANGE_ERROR'); // }
|
|
110
|
+
// addError(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${path} ,\n line : ${decl.source.start.line} ,\n message : value (${value}) not within range (${range.start},${range.end})\r`)
|
|
111
|
+
|
|
112
|
+
return value;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
module.exports = postcss.plugin('postcss-variable-report', cssVariableReplacementConfig => {
|
|
116
|
+
const rawdata = fs.readFileSync(cssVariableReplacementConfig);
|
|
117
|
+
const data = JSON.parse(rawdata);
|
|
118
|
+
const {
|
|
119
|
+
errorsAllowed,
|
|
120
|
+
settings: settingsObject,
|
|
121
|
+
errorLog: errorLogStatus,
|
|
122
|
+
errorInConsole: errorConsoleStatus
|
|
123
|
+
} = data; // const keys = Object.keys(settingsObject);
|
|
124
|
+
|
|
125
|
+
allowedErrs = errorsAllowed;
|
|
126
|
+
const replacementArray = [];
|
|
127
|
+
Object.keys(settingsObject).forEach(key => {
|
|
128
|
+
Object.values(settingsObject[key].replacements).forEach(val => {
|
|
129
|
+
if (!replacementArray.includes(val)) {
|
|
130
|
+
replacementArray.push(val);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
let regValStr = '';
|
|
135
|
+
replacementArray.forEach((val, index) => {
|
|
136
|
+
if (index !== replacementArray.length - 1) {
|
|
137
|
+
regValStr += `${val.replace('$$', '\\d+').replace('(', '\\(').replace(')', '\\)')}|`;
|
|
138
|
+
} else {
|
|
139
|
+
regValStr += `${val.replace('$$', '\\d+').replace('(', '\\(').replace(')', '\\)')}`;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const valRegex = new RegExp(regValStr, 'gi');
|
|
143
|
+
return rootOriginal => {
|
|
144
|
+
rootOriginal.walkRules(rule => {
|
|
145
|
+
// rule.nodes[-1] = {}
|
|
146
|
+
// need map, forEach fine less memory
|
|
147
|
+
rule.nodes.forEach((decl, position) => {
|
|
148
|
+
// case font-size
|
|
149
|
+
const commentStr = 'variable:ignore';
|
|
150
|
+
const prevNode = rule.nodes[position - 1];
|
|
151
|
+
const fromPath = rootOriginal.source.input.from; // this will be problem for linux and mac use require('path').sep
|
|
152
|
+
// split not need use slice and lastIndexOf less memory
|
|
153
|
+
|
|
154
|
+
const filename = fromPath.split(path.sep).pop();
|
|
155
|
+
|
|
156
|
+
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase().includes(commentStr)) {
|
|
157
|
+
const errStr = ` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${fromPath} ,\n line : ${decl.source.start.line} ,\n message : Declaration Ignored \r`;
|
|
158
|
+
errorFunction(errStr, 'DECLARATION_IGNORED');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (settingsObject[decl.prop] && !decl.value.includes('var(--')) {
|
|
163
|
+
const settings = settingsObject[decl.prop]; // console.log(settings)
|
|
164
|
+
|
|
165
|
+
const {
|
|
166
|
+
allowed,
|
|
167
|
+
range
|
|
168
|
+
} = settings; // suggestion filter !decl.value.includes('calc')
|
|
169
|
+
// Reason below some of logic happen based on this
|
|
170
|
+
|
|
171
|
+
const unit = decl.value.toString() // no need round braket since you do not need group for less memory
|
|
172
|
+
.replace(/\d+/gi, '').replace('var(--zd_size)', 'px').replace('var(--zd_font_size)', 'px').split(' ').filter(x => x !== ''); // unit = unit.replace(unit, unit.replace('-',''))
|
|
173
|
+
// console.log('unit : ');
|
|
174
|
+
// console.log(unit);
|
|
175
|
+
|
|
176
|
+
unit.forEach((val, index) => {
|
|
177
|
+
allowed.forEach(alwdVal => {
|
|
178
|
+
if (val.includes(alwdVal)) {
|
|
179
|
+
// ## for what purpose
|
|
180
|
+
unit[index] = val.replace(`-${alwdVal}`, `${alwdVal}`).replace(`-.${alwdVal}`, `${alwdVal}`);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
let unitError = false;
|
|
185
|
+
let unitErrorVal = '';
|
|
186
|
+
unit.forEach(val => {
|
|
187
|
+
if (!val.includes('calc')) {
|
|
188
|
+
if (!allowed.includes(val.toString())) {
|
|
189
|
+
unitError = true;
|
|
190
|
+
unitErrorVal = val;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}); // console.log(allowed, replacements, range)
|
|
194
|
+
|
|
195
|
+
if (!unitError) {
|
|
196
|
+
// use variable decl.value.split(' ')
|
|
197
|
+
if (range) {
|
|
198
|
+
// console.log('multiple :', decl.value)
|
|
199
|
+
let newVal = '';
|
|
200
|
+
decl.value.split(' ').forEach(singleVal => {
|
|
201
|
+
newVal += `${singleConvertor(singleVal, settings.replacements.px, {
|
|
202
|
+
decl,
|
|
203
|
+
filename,
|
|
204
|
+
path: fromPath
|
|
205
|
+
}, range)} `;
|
|
206
|
+
});
|
|
207
|
+
decl.value = newVal;
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
if (!decl.value.includes('calc')) {
|
|
211
|
+
// addError(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${path} ,\n line : ${decl.source.start.line} ,\n unit : ${unitErrorVal} ,\n message : ${unitErrorVal} (Unit) Not Allowed \r`);
|
|
212
|
+
errorFunction(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${fromPath} ,\n line : ${decl.source.start.line} ,\n unit : ${unitErrorVal} ,\n message : ${unitErrorVal} (Unit) Not Allowed \r`, 'UNIT_ERROR');
|
|
213
|
+
} else {
|
|
214
|
+
decl.value = pxToCalc(decl.value);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
if (decl.prop && decl.value && !decl.prop.includes('--') && valRegex.test(decl.value) && (settingsObject[decl.prop] || convertableProps[decl.prop]) && decl.value.includes('var') && !decl.value.includes('calc')) {
|
|
219
|
+
errorFunction(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${fromPath} ,\n line : ${decl.source.start.line} ,\n message : value (${decl.value}) has var in it, kindly check`, 'VARIABLE_PRESENT');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}); // console.log(filename)
|
|
224
|
+
// console.log('Done!')
|
|
225
|
+
// console.log('----------------------------------------------------------------------------------------------------------------------')
|
|
226
|
+
|
|
227
|
+
if (errorLogStatus) {
|
|
228
|
+
fs.writeFileSync('./css_error.log', '');
|
|
229
|
+
|
|
230
|
+
if (errors.length > 0) {
|
|
231
|
+
errors.forEach(err => {
|
|
232
|
+
fs.appendFileSync('./css_error.log', err);
|
|
233
|
+
}); // console.log('----------------------------------------------------------------------------------------------------------------------')
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (errorConsoleStatus) {
|
|
238
|
+
if (errors.length > 0) {
|
|
239
|
+
errors.forEach(err => {
|
|
240
|
+
// fs.appendFileSync('./css_error.log', err);
|
|
241
|
+
console.log(err);
|
|
242
|
+
});
|
|
243
|
+
console.log('----------------------------------------------------------------------------------------------------------------------');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
});
|