@zohodesk/react-cli 1.1.14-exp.3 → 1.1.14-kubernetes
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 +16 -281
- package/bin/cli.js +55 -30
- package/docs/CustomChunks.md +9 -12
- package/docs/SelectorWeight.md +0 -3
- package/docs/ValueReplacer.md +0 -27
- package/docs/VariableConversion.md +1 -6
- package/lib/common/splitChunks.js +45 -65
- package/lib/common/testPattern.js +11 -9
- package/lib/common/valueReplacer.js +3 -1
- package/lib/configs/resolvers.js +5 -16
- package/lib/configs/webpack.css.umd.config.js +2 -3
- package/lib/configs/webpack.dev.config.js +5 -15
- package/lib/configs/webpack.docs.config.js +3 -14
- package/lib/configs/webpack.impact.config.js +2 -8
- package/lib/configs/webpack.prod.config.js +5 -15
- package/lib/constants.js +3 -3
- package/lib/loaderUtils/getCSSLoaders.js +49 -98
- package/lib/loaderUtils/windowsModification.js +1 -6
- package/lib/loaders/docsLoader.js +7 -18
- package/lib/loaders/selectorMappingLoader.js +9 -9
- package/lib/pluginUtils/getDevPlugins.js +6 -25
- package/lib/pluginUtils/getProdPlugins.js +5 -32
- package/lib/pluginUtils/getUMDCSSPlugins.js +1 -1
- package/lib/pluginUtils/getUMDComponentPlugins.js +1 -1
- package/lib/plugins/EFCPlugin.js +9 -9
- package/lib/plugins/EFCTemplatePlugin.js +12 -10
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +9 -8
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +3 -2
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +13 -30
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +7 -2
- package/lib/plugins/I18nSplitPlugin/index.js +1 -1
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +8 -8
- package/lib/plugins/ReportGeneratePlugin.js +6 -8
- package/lib/plugins/ResourceHintsPlugin.js +3 -13
- package/lib/plugins/SelectorPlugin.js +37 -77
- package/lib/plugins/{MinifyPlugin.js → UglifyCSSPlugin.js} +3 -3
- package/lib/plugins/UnusedFilesFindPlugin.js +5 -7
- package/lib/plugins/VariableConversionCollector.js +101 -40
- package/lib/plugins/composeCommonPlugin.js +30 -0
- package/lib/plugins/index.js +7 -7
- package/lib/postcss-plugins/ExcludePlugin.js +1 -1
- package/lib/postcss-plugins/RTLSplitPlugin.js +10 -4
- package/lib/postcss-plugins/ValueReplacer.js +29 -8
- package/lib/postcss-plugins/hoverActivePlugin.js +6 -0
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +1 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +38 -94
- package/lib/postcss-plugins/variableModifier.js +244 -0
- package/lib/schemas/index.js +18 -94
- package/lib/servers/devBuild.js +11 -13
- package/lib/servers/getCliPath.js +5 -3
- package/lib/servers/httpsOptions.js +13 -12
- package/lib/servers/nowatchserver.js +55 -62
- package/lib/servers/server.js +52 -53
- package/lib/utils/cssClassNameGenerate.js +13 -70
- package/lib/utils/getOptions.js +28 -35
- package/lib/utils/getServerURL.js +9 -1
- package/lib/utils/index.js +12 -14
- package/lib/utils/initPreCommitHook.js +5 -5
- package/lib/utils/pullOrigin.js +3 -3
- package/lib/utils/reinstallDependencies.js +3 -3
- package/lib/utils/switchBranch.js +2 -4
- package/package.json +3 -5
- package/templates/docs/all.html +0 -1
- package/templates/docs/component.html +0 -1
- package/templates/docs/components.html +0 -1
- package/templates/docs/css/style.css +169 -136
- package/templates/docs/index.html +632 -796
- package/.vscode/settings.json +0 -25
- package/docs/ComposeMinification.md +0 -13
- package/docs/MarkdownParser.md +0 -18
- package/docs/ReactLive.md +0 -14
- package/docs/patternFiltering.md +0 -57
- package/lib/common/buildEs.js +0 -12
- package/lib/common/runPreProcess.js +0 -71
- package/lib/deprecationLogger.js +0 -40
- package/lib/loaderUtils/tests/windowsModification.test.js +0 -10
- package/lib/loaders/__test__/markdownLoader.spec.js +0 -145
- package/lib/loaders/composeLoader.js +0 -298
- package/lib/loaders/markdownLoader.js +0 -71
- package/lib/loaders/reactLiveConvertor.js +0 -105
- package/lib/logger.js +0 -27
- package/lib/plugins/CustomAttributePlugin.js +0 -82
- package/lib/plugins/CustomAttributePlugin.md +0 -35
- package/lib/plugins/EfcResourceCleanupPlugin.js +0 -43
- package/lib/plugins/StatsPlugin.js +0 -82
- package/lib/plugins/utils/classHandling.js +0 -35
- package/lib/plugins/utils/fileHandling.js +0 -92
- package/lib/plugins/utils/tests/fileHandling.test.js +0 -30
- package/lib/plugins/variableConvertorUtils.js +0 -133
- package/lib/postcss-plugins/EmptyPlugin.js +0 -8
- package/lib/postcss-plugins/IncludePlugin.js +0 -23
- package/lib/postcss-plugins/SelectorReplace.js +0 -80
- package/lib/postcss-plugins/__test__/selectorReplace.test.js +0 -28
- package/lib/postcss-plugins/__test__/valueReplacer.spec.js +0 -43
- package/lib/servers/requireLocalOrGlobal.js +0 -61
- package/lib/utils/deprecationSupport.js +0 -134
- package/lib/utils/log.js +0 -11
- package/lib/utils/object-manipulation.js +0 -88
- package/lib/utils/selectorReplacer.js +0 -47
- package/lib/utils/variableConverter.js +0 -104
- package/npm-shrinkwrap.json +0 -33485
- package/templates/docs/css/markdown.css +0 -202
@@ -9,15 +9,12 @@ var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
9
|
|
10
10
|
var _ErrorHandler = require("../postcss-plugins/variableModificationPlugin/ErrorHandler");
|
11
11
|
|
12
|
-
var _fileHandling = require("./utils/fileHandling");
|
13
|
-
|
14
|
-
var _variableConvertorUtils = require("./variableConvertorUtils");
|
15
|
-
|
16
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
13
|
|
18
14
|
// import { RawSource } from 'webpack-sources';
|
19
15
|
const fs = require('fs');
|
20
16
|
|
17
|
+
const ignoreVals = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
21
18
|
let variablesRead = {};
|
22
19
|
|
23
20
|
const {
|
@@ -26,7 +23,29 @@ const {
|
|
26
23
|
errHandler
|
27
24
|
} = require('../postcss-plugins/variableModificationPlugin/index');
|
28
25
|
|
29
|
-
const supportedProps = ['font-size', 'margin', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right', 'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', '^top', '^right', '^bottom', '^left', '^width', 'min-width', 'max-width', '^height', 'min-height', 'max-height', 'text-indent', 'clip', 'flex-basis', 'row-gap', 'gap', 'column-gap', 'flex']; //
|
26
|
+
const supportedProps = ['font-size', 'margin', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right', 'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', '^top', '^right', '^bottom', '^left', '^width', 'min-width', 'max-width', '^height', 'min-height', 'max-height', 'text-indent', 'clip', 'flex-basis', 'row-gap', 'gap', 'column-gap', 'flex']; // const avoidProps = [];
|
27
|
+
// -- is issue IO --
|
28
|
+
|
29
|
+
/*
|
30
|
+
issues eg :
|
31
|
+
issues = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
32
|
+
input :
|
33
|
+
--zd_size
|
34
|
+
output :
|
35
|
+
true
|
36
|
+
comment :
|
37
|
+
do not execute when --zd_size comes as prop
|
38
|
+
*/
|
39
|
+
|
40
|
+
function isIgnoreValuePresent(ignoreVals, prop) {
|
41
|
+
let present = false;
|
42
|
+
ignoreVals.forEach(issue => {
|
43
|
+
if (prop && prop.includes(issue)) {
|
44
|
+
present = true;
|
45
|
+
}
|
46
|
+
});
|
47
|
+
return present;
|
48
|
+
} // -- to convert the hyphen values to values --
|
30
49
|
|
31
50
|
/*
|
32
51
|
input :
|
@@ -38,6 +57,49 @@ comment :
|
|
38
57
|
to make the variable object using the output as key and decl.prop such as font-size as value
|
39
58
|
*/
|
40
59
|
|
60
|
+
|
61
|
+
function extractVariableName(val) {
|
62
|
+
return val.replace(/calc\((.+)\)/gi, '$1').replace(/var\((.+)\)/gi, '$1').replace('-1', '').replace('*', '').replace('\n', '').trim();
|
63
|
+
}
|
64
|
+
|
65
|
+
function rootConvertor(rootOriginal, variables, settingsObject) {
|
66
|
+
rootOriginal.walkRules(rule => {
|
67
|
+
rule.nodes.forEach((decl, index) => {
|
68
|
+
const prevNode = rule.nodes[index - 1];
|
69
|
+
const currentNode = rule.nodes[index];
|
70
|
+
|
71
|
+
if (decl.prop && decl.prop.includes('--')) {
|
72
|
+
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'variable:ignore') {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (isIgnoreValuePresent(ignoreVals, decl.prop)) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (settingsObject[variables[decl.prop]]) {
|
81
|
+
/* if there is no value for property, set it to default so that undefined doesn't get called as key */
|
82
|
+
if (!variables[decl.prop]) {
|
83
|
+
variables[decl.prop] = 'default';
|
84
|
+
}
|
85
|
+
|
86
|
+
const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
|
87
|
+
const valArr = decl.value.split(' '); // single values are considered in the above array and converted below
|
88
|
+
|
89
|
+
valArr.forEach((value, index) => {
|
90
|
+
if (value.includes('px')) {
|
91
|
+
const num = value.replace('px', '');
|
92
|
+
valArr[index] = pxReplacement.replace('$$', num);
|
93
|
+
}
|
94
|
+
});
|
95
|
+
currentNode.value = valArr.join(' ');
|
96
|
+
}
|
97
|
+
}
|
98
|
+
});
|
99
|
+
});
|
100
|
+
return rootOriginal;
|
101
|
+
}
|
102
|
+
|
41
103
|
function createFolderIfNonExistant(path) {
|
42
104
|
if (!fs.existsSync(path)) {
|
43
105
|
fs.mkdirSync(path, {
|
@@ -56,12 +118,10 @@ class VariableConversionCollector {
|
|
56
118
|
constructor(options = {}) {
|
57
119
|
this.optimize = options.optimize;
|
58
120
|
this.filename = options.cssVariableReplacementConfig;
|
59
|
-
this.
|
60
|
-
|
61
|
-
this.initializeFiles();
|
121
|
+
this.fileHandler();
|
62
122
|
}
|
63
123
|
|
64
|
-
|
124
|
+
fileHandler() {
|
65
125
|
createFolderIfNonExistant('./.cli/logs/');
|
66
126
|
createFolderIfNonExistant('./.cli/config/variables/');
|
67
127
|
createFolderIfNonExistant('./.cli/config/selectorWeight/');
|
@@ -71,8 +131,7 @@ class VariableConversionCollector {
|
|
71
131
|
|
72
132
|
apply(compiler) {
|
73
133
|
const variables = {};
|
74
|
-
const unassigned = {};
|
75
|
-
|
134
|
+
const unassigned = {};
|
76
135
|
const rawdata = fs.readFileSync(this.filename);
|
77
136
|
const data = JSON.parse(rawdata);
|
78
137
|
const {
|
@@ -124,13 +183,16 @@ class VariableConversionCollector {
|
|
124
183
|
rootOriginal.walkRules(rule => {
|
125
184
|
rule.walkDecls(decl => {
|
126
185
|
decl.value.split(' ').forEach(val => {
|
127
|
-
if (val && val.includes('--') && !new RegExp(
|
128
|
-
const extractedValue =
|
186
|
+
if (val && val.includes('--') && !new RegExp(ignoreVals.join('|'), 'gi').test(val) && decl.prop) {
|
187
|
+
const extractedValue = extractVariableName(val);
|
129
188
|
|
130
189
|
if (!variables[extractedValue]) {
|
131
190
|
variables[extractedValue] = decl.prop;
|
132
191
|
} else {
|
133
192
|
if (new RegExp(supportedProps.join('|'), 'gi').test(decl.prop)) {
|
193
|
+
// console.log(
|
194
|
+
// `${extractedValue} : ${variables[extractedValue]} already exists please check!`
|
195
|
+
// );
|
134
196
|
if (errorsAllowed.MULTIPLE_OCCURANCES) {
|
135
197
|
const errObj = {
|
136
198
|
decl,
|
@@ -144,6 +206,7 @@ class VariableConversionCollector {
|
|
144
206
|
}
|
145
207
|
}
|
146
208
|
} else {
|
209
|
+
// console.log(decl.prop);
|
147
210
|
if (/^--/gi.test(decl.prop) && val.trim() !== '' && !variables[decl.prop]) {
|
148
211
|
if (!Object.keys(variablesRead.ignore).includes(decl.prop)) {
|
149
212
|
unassigned[decl.prop] = variables[decl.prop];
|
@@ -175,7 +238,7 @@ class VariableConversionCollector {
|
|
175
238
|
});
|
176
239
|
}
|
177
240
|
});
|
178
|
-
}); // -- conversion for the root using
|
241
|
+
}); // -- conversion for the root using rootConvertor --
|
179
242
|
|
180
243
|
/*
|
181
244
|
input :
|
@@ -193,33 +256,9 @@ class VariableConversionCollector {
|
|
193
256
|
compilation.hooks.optimizeModules.tap('VariableConversionCollector', modules => {
|
194
257
|
const mods = modules.filter(x => x.type.includes('css'));
|
195
258
|
mods.forEach(module => {
|
196
|
-
const filename = module.issuer.resource;
|
197
|
-
/*
|
198
|
-
input :
|
199
|
-
filename : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
|
200
|
-
|
201
|
-
patterns.cssVariableReplacement:
|
202
|
-
// include src folder, include deskapp folder, exclude node modules
|
203
|
-
"cssVariableReplacement": [
|
204
|
-
"src",
|
205
|
-
"deskapp",
|
206
|
-
"!node_modules"
|
207
|
-
]
|
208
|
-
|
209
|
-
output :
|
210
|
-
true or false
|
211
|
-
*/
|
212
|
-
|
213
|
-
if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
|
214
|
-
filename,
|
215
|
-
filterArr: this.patterns.cssVariableReplacement
|
216
|
-
})) {
|
217
|
-
return;
|
218
|
-
}
|
219
|
-
|
220
259
|
const rootOriginal = _postcss.default.parse(module.content);
|
221
260
|
|
222
|
-
module.content = (
|
261
|
+
module.content = rootConvertor(rootOriginal, variables, settingsObject).toString();
|
223
262
|
});
|
224
263
|
});
|
225
264
|
});
|
@@ -253,7 +292,29 @@ class VariableConversionCollector {
|
|
253
292
|
if (a.type < b.type) {
|
254
293
|
return -1;
|
255
294
|
}
|
256
|
-
});
|
295
|
+
}); // variable constructed now to be written in a json file
|
296
|
+
// const newVars = Object.keys(variables)
|
297
|
+
// //Filter Object with key contanis "NAME"
|
298
|
+
// .filter(key => variables[key].includes('--'))
|
299
|
+
// .reduce(
|
300
|
+
// (obj, key) =>
|
301
|
+
// Object.assign(obj, {
|
302
|
+
// [key]: variables[key]
|
303
|
+
// }),
|
304
|
+
// {}
|
305
|
+
// );
|
306
|
+
// console.log('new variables: ', newVars);
|
307
|
+
// try {
|
308
|
+
// fs.writeFileSync('./variableMapping.json', JSON.stringify(variables));
|
309
|
+
// } catch (err) {
|
310
|
+
// console.log(err);
|
311
|
+
// }
|
312
|
+
// fs.writeFile('./variableMapping.json', JSON.stringify(variables), err => {
|
313
|
+
// if (err) {
|
314
|
+
// throw err;
|
315
|
+
// }
|
316
|
+
// console.log('variable mapping file generated.');
|
317
|
+
// });
|
257
318
|
|
258
319
|
if (errorConsoleStatus) {
|
259
320
|
const errorHandler = new _ErrorHandler.ErrorHandler();
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
9
|
+
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
|
12
|
+
class ComposeCommonPlugin {
|
13
|
+
constructor(options = {}) {
|
14
|
+
this.optimize = options.optimize;
|
15
|
+
}
|
16
|
+
|
17
|
+
apply(compiler) {
|
18
|
+
compiler.hooks.compilation.tap('OptimizeJSPlugin', compilation => {
|
19
|
+
compilation.hooks.optimizeModules.tap('OptimizeMods', modules => {
|
20
|
+
modules.forEach(module => {
|
21
|
+
console.log(module);
|
22
|
+
});
|
23
|
+
});
|
24
|
+
});
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
var _default = ComposeCommonPlugin;
|
30
|
+
exports.default = _default;
|
package/lib/plugins/index.js
CHANGED
@@ -33,12 +33,6 @@ Object.defineProperty(exports, "ManifestPlugin", {
|
|
33
33
|
return _ManifestPlugin.default;
|
34
34
|
}
|
35
35
|
});
|
36
|
-
Object.defineProperty(exports, "MinifyPlugin", {
|
37
|
-
enumerable: true,
|
38
|
-
get: function () {
|
39
|
-
return _MinifyPlugin.default;
|
40
|
-
}
|
41
|
-
});
|
42
36
|
Object.defineProperty(exports, "ModuleStatsPlugin", {
|
43
37
|
enumerable: true,
|
44
38
|
get: function () {
|
@@ -105,6 +99,12 @@ Object.defineProperty(exports, "TPHashMappingPlugin", {
|
|
105
99
|
return _TPHashMappingPlugin.default;
|
106
100
|
}
|
107
101
|
});
|
102
|
+
Object.defineProperty(exports, "UglifyCSSPlugin", {
|
103
|
+
enumerable: true,
|
104
|
+
get: function () {
|
105
|
+
return _UglifyCSSPlugin.default;
|
106
|
+
}
|
107
|
+
});
|
108
108
|
Object.defineProperty(exports, "UnusedFilesFindPlugin", {
|
109
109
|
enumerable: true,
|
110
110
|
get: function () {
|
@@ -126,7 +126,7 @@ var _OptimizeJSPlugin = _interopRequireDefault(require("./OptimizeJSPlugin"));
|
|
126
126
|
|
127
127
|
var _ResourceHintsPlugin = _interopRequireDefault(require("./ResourceHintsPlugin"));
|
128
128
|
|
129
|
-
var
|
129
|
+
var _UglifyCSSPlugin = _interopRequireDefault(require("./UglifyCSSPlugin"));
|
130
130
|
|
131
131
|
var _ManifestPlugin = _interopRequireDefault(require("./ManifestPlugin"));
|
132
132
|
|
@@ -10,7 +10,7 @@ module.exports = _postcss.default.plugin('postcss-exclude-files', opts => {
|
|
10
10
|
} = opts;
|
11
11
|
return (root, result) => {
|
12
12
|
const inputFile = root.source.input.file;
|
13
|
-
|
13
|
+
let isIgnoredFile = opts.ignore.some(file => inputFile.indexOf(file) !== -1);
|
14
14
|
|
15
15
|
if (!isIgnoredFile) {
|
16
16
|
const handler = response => response.messages.forEach(msg => result.messages.push(msg));
|
@@ -18,6 +18,7 @@ const oppositeDir = {
|
|
18
18
|
};
|
19
19
|
|
20
20
|
function compareSelector(selector1, selector2) {
|
21
|
+
// console.log({ selector1, selector2 }, selector1 === selector2);
|
21
22
|
return selector1 === selector2;
|
22
23
|
}
|
23
24
|
|
@@ -65,6 +66,7 @@ function mergeIfSameSelector(rule) {
|
|
65
66
|
|
66
67
|
|
67
68
|
function removeIfOppsiteDirRule(rule, direction, rootOptions) {
|
69
|
+
// console.log({ rule, type: rule.type });
|
68
70
|
const selectors = rule.selector.split(/\s*,\s*/); // NOTE: if we use opposite dir selector as custom override reason,
|
69
71
|
// and compain normal selector with it, In this case
|
70
72
|
// we just a have to remove that selector only not full rule
|
@@ -85,10 +87,11 @@ function removeIfOppsiteDirRule(rule, direction, rootOptions) {
|
|
85
87
|
}
|
86
88
|
|
87
89
|
function removeIfOppsiteDirKeyframe(rule, direction) {
|
88
|
-
|
89
|
-
|
90
|
+
let name = rule.params;
|
91
|
+
let keyFrameDirName = name.slice(name.lastIndexOf('-') + 1);
|
90
92
|
|
91
93
|
if (keyFrameDirName === oppositeDir[direction]) {
|
94
|
+
// console.log({ m: 'removed', keyFrameName: rule.params });
|
92
95
|
rule.remove();
|
93
96
|
}
|
94
97
|
}
|
@@ -106,10 +109,12 @@ function separateSingleDir(root, direction, rootOptions) {
|
|
106
109
|
|
107
110
|
function separateRtlAndLtr(css, rootOptions) {
|
108
111
|
// let processor = postcss([]).process(css);
|
109
|
-
|
112
|
+
let root = postcss.parse(css); // let { root } = processor;
|
113
|
+
// console.log(processor, root);
|
110
114
|
// NOTE: I did first rtl then ltr , Because for ltr I use original root ref
|
111
115
|
|
112
|
-
const rtlRoot = separateSingleDir(root.clone(), 'rtl', rootOptions);
|
116
|
+
const rtlRoot = separateSingleDir(root.clone(), 'rtl', rootOptions); // console.log('############################');
|
117
|
+
|
113
118
|
const ltrRoot = separateSingleDir(root, 'ltr', rootOptions);
|
114
119
|
return {
|
115
120
|
ltrRoot,
|
@@ -127,6 +132,7 @@ function separateRtlAndLtr(css, rootOptions) {
|
|
127
132
|
// // root.append(postcss.comment({ text: 'comment' }));
|
128
133
|
// root.append(postcss.comment({ text: 'this is spliting part ' }));
|
129
134
|
// root.append(rtlRoot);
|
135
|
+
// //console.log({root, roots:root+""}, root+"")
|
130
136
|
// // Transform CSS AST here
|
131
137
|
// }
|
132
138
|
// );
|
@@ -4,22 +4,43 @@ 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
|
7
22
|
module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
|
8
23
|
root => {
|
9
24
|
root.walkDecls(decl => {
|
10
25
|
valueReplacer.forEach(obj => {
|
11
26
|
if (obj.props.indexOf(decl.prop) !== -1) {
|
12
|
-
|
27
|
+
let ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
|
13
28
|
ks.forEach(k => {
|
14
|
-
|
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
|
-
}
|
29
|
+
decl.value = decl.value.replace(k, obj.values[k]);
|
20
30
|
}); //decl.value = obj.values[decl.value];
|
21
31
|
}
|
22
32
|
}); //console.log({root, roots:root+""}, root+"")
|
23
33
|
// Transform CSS AST here
|
24
|
-
});
|
34
|
+
}); // root.walkDecls(decl => {
|
35
|
+
// valueReplacer.forEach(obj => {
|
36
|
+
// if (
|
37
|
+
// obj.props.indexOf(decl.prop) !== -1 &&
|
38
|
+
// obj.values[decl.value] !== undefined
|
39
|
+
// ) {
|
40
|
+
// decl.value = obj.values[decl.value];
|
41
|
+
// }
|
42
|
+
// });
|
43
|
+
// //console.log({root, roots:root+""}, root+"")
|
44
|
+
// // Transform CSS AST here
|
45
|
+
// });
|
25
46
|
});
|
@@ -158,6 +158,7 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
158
158
|
|
159
159
|
function mediaCommaQuery(rule, index) {
|
160
160
|
if (rule.parent.params !== undefined && !rule.parent.params.includes('hover')) {
|
161
|
+
//console.log(hovMed, actMed);
|
161
162
|
let newSelector = '';
|
162
163
|
const {
|
163
164
|
hovMed,
|
@@ -231,6 +232,7 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
231
232
|
}
|
232
233
|
|
233
234
|
function commaQuery(rule, index) {
|
235
|
+
//console.log("comma" , rule.selector.split('\n'));
|
234
236
|
let newSelector = '';
|
235
237
|
const hovQueries = [];
|
236
238
|
rule.selector.split(/\s*,\s*/).forEach(_subrule => {
|
@@ -286,10 +288,13 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
286
288
|
});
|
287
289
|
rootOriginal.walkRules(/:hover/i, (rule, index) => {
|
288
290
|
// media hover query with ',' ' ' '+'
|
291
|
+
// console.log("media query" , rule.selector)
|
289
292
|
if (rule.parent.type === 'atrule' && rule.selector.includes(',')) {
|
293
|
+
//console.log("media comma", rule.selector)
|
290
294
|
mediaCommaQuery(rule, index);
|
291
295
|
} else {
|
292
296
|
// plus, space and other media queries
|
297
|
+
//console.log("media", rule.selector)
|
293
298
|
mediaQuery(rule, index);
|
294
299
|
} // usual hover query
|
295
300
|
|
@@ -306,6 +311,7 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
306
311
|
if (rule.selector.includes(',')) {
|
307
312
|
commaQuery(rule, index);
|
308
313
|
} else if (rule.selector.match(/ +|\++/g)) {
|
314
|
+
//console.log("plus or space" , rule.selector);
|
309
315
|
if (rule.selector.includes('hover')) {
|
310
316
|
hoverRules.push({
|
311
317
|
rule,
|
@@ -10,6 +10,8 @@ const {
|
|
10
10
|
ErrorHandler
|
11
11
|
} = require('./ErrorHandler');
|
12
12
|
|
13
|
+
const errors = [];
|
14
|
+
const errorTable = [];
|
13
15
|
const errHandler = new ErrorHandler();
|
14
16
|
const convertableProps = {
|
15
17
|
'font-size': true,
|
@@ -92,13 +94,7 @@ function pxToCalc(value) {
|
|
92
94
|
return arr.join(' ');
|
93
95
|
}
|
94
96
|
|
95
|
-
const singleConvertor = ({
|
96
|
-
value,
|
97
|
-
changeVal,
|
98
|
-
details,
|
99
|
-
range,
|
100
|
-
allowed
|
101
|
-
}) => {
|
97
|
+
const singleConvertor = (value, changeVal, details, range) => {
|
102
98
|
const {
|
103
99
|
path,
|
104
100
|
filename,
|
@@ -112,15 +108,7 @@ const singleConvertor = ({
|
|
112
108
|
}
|
113
109
|
}
|
114
110
|
|
115
|
-
if (allowed && allowed.includes(decl.value) && decl.value.toString() !== '0') {
|
116
|
-
return decl.value;
|
117
|
-
}
|
118
|
-
|
119
111
|
if (getNumericValue(value) >= range.start && getNumericValue(value) <= range.end || getNumericValue(value) === 0) {
|
120
|
-
if (value.trim() === '0px') {
|
121
|
-
return '0';
|
122
|
-
}
|
123
|
-
|
124
112
|
let retVal = value.replace(/(\d+)px/gi, changeVal.replace('$$', '$1'));
|
125
113
|
|
126
114
|
if (/^-var/.test(retVal)) {
|
@@ -133,7 +121,7 @@ const singleConvertor = ({
|
|
133
121
|
// console.log(value, 'not within range')
|
134
122
|
|
135
123
|
|
136
|
-
|
124
|
+
let errObj = {
|
137
125
|
decl,
|
138
126
|
type: 'RANGE_ERROR',
|
139
127
|
filename,
|
@@ -141,8 +129,24 @@ const singleConvertor = ({
|
|
141
129
|
path: path
|
142
130
|
};
|
143
131
|
errHandler.errorTable.push(errObj);
|
144
|
-
errHandler.errorFunction(errObj);
|
145
|
-
|
132
|
+
errHandler.errorFunction(errObj); // errorFunction(
|
133
|
+
// {
|
134
|
+
// decl,
|
135
|
+
// type: 'RANGE_ERROR',
|
136
|
+
// filename,
|
137
|
+
// message: `value (${value}) (${typeof value}) not within range (${
|
138
|
+
// range.start
|
139
|
+
// },${range.end})\r`,
|
140
|
+
// path: path
|
141
|
+
// },
|
142
|
+
// 'RANGE_ERROR'
|
143
|
+
// );
|
144
|
+
// }
|
145
|
+
// 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`)
|
146
|
+
// return value;
|
147
|
+
// } else {
|
148
|
+
// console.log('++++++++++++++++++++++rect val!', value);
|
149
|
+
// }
|
146
150
|
};
|
147
151
|
|
148
152
|
module.exports = {
|
@@ -175,7 +179,6 @@ module.exports = {
|
|
175
179
|
});
|
176
180
|
const valRegex = new RegExp(regValStr, 'gi');
|
177
181
|
return rootOriginal => {
|
178
|
-
// console.log(rootOriginal.source.input.from, 'passed through variable Plugin');
|
179
182
|
rootOriginal.walkRules(rule => {
|
180
183
|
// rule.nodes[-1] = {}
|
181
184
|
// need map, forEach fine less memory
|
@@ -186,11 +189,10 @@ module.exports = {
|
|
186
189
|
const fromPath = rootOriginal.source.input.from; // this will be problem for linux and mac use require('path').sep
|
187
190
|
// split not need use slice and lastIndexOf less memory
|
188
191
|
|
189
|
-
const filename = fromPath.split(path.sep).pop();
|
190
|
-
// }
|
192
|
+
const filename = fromPath.split(path.sep).pop();
|
191
193
|
|
192
194
|
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase().includes(commentStr)) {
|
193
|
-
|
195
|
+
let errObj = {
|
194
196
|
decl,
|
195
197
|
type: 'DECLARATION_IGNORED',
|
196
198
|
filename,
|
@@ -203,7 +205,8 @@ module.exports = {
|
|
203
205
|
}
|
204
206
|
|
205
207
|
if (settingsObject[decl.prop] && !decl.value.includes('var(--')) {
|
206
|
-
const settings = settingsObject[decl.prop];
|
208
|
+
const settings = settingsObject[decl.prop]; // console.log(settings)
|
209
|
+
|
207
210
|
const {
|
208
211
|
allowed,
|
209
212
|
range
|
@@ -214,9 +217,6 @@ module.exports = {
|
|
214
217
|
.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('-',''))
|
215
218
|
// console.log('unit : ');
|
216
219
|
// console.log(unit);
|
217
|
-
// if (decl.prop === 'height') {
|
218
|
-
// console.log(decl.prop, unit, 'case 1');
|
219
|
-
// }
|
220
220
|
|
221
221
|
unit.forEach((val, index) => {
|
222
222
|
allowed.forEach(alwdVal => {
|
@@ -236,54 +236,26 @@ module.exports = {
|
|
236
236
|
unitErrorVal = val;
|
237
237
|
}
|
238
238
|
}
|
239
|
-
}); //
|
240
|
-
// console.log(decl.prop, unitErrorVal, unitError, unit, 'case 2');
|
241
|
-
// }
|
242
|
-
// console.log(allowed, replacements, range)
|
239
|
+
}); // console.log(allowed, replacements, range)
|
243
240
|
|
244
241
|
if (!unitError) {
|
245
|
-
|
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) {
|
242
|
+
// use variable decl.value.split(' ')
|
243
|
+
if (range) {
|
254
244
|
// 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
|
-
|
262
245
|
let newVal = '';
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
changeVal: settings.replacements.px,
|
270
|
-
details: {
|
271
|
-
decl,
|
272
|
-
filename,
|
273
|
-
path: fromPath
|
274
|
-
},
|
275
|
-
range,
|
276
|
-
allowed
|
277
|
-
})} `;
|
246
|
+
decl.value.split(' ').forEach(singleVal => {
|
247
|
+
newVal += `${singleConvertor(singleVal, settings.replacements.px, {
|
248
|
+
decl,
|
249
|
+
filename,
|
250
|
+
path: fromPath
|
251
|
+
}, range)} `;
|
278
252
|
});
|
279
|
-
decl.value = newVal;
|
280
|
-
// console.log(decl.prop, tempVal, newVal, 'case 4');
|
281
|
-
// }
|
253
|
+
decl.value = newVal;
|
282
254
|
}
|
283
255
|
} else {
|
284
256
|
if (!decl.value.includes('calc')) {
|
285
257
|
// 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`);
|
286
|
-
|
258
|
+
let errObj = {
|
287
259
|
decl,
|
288
260
|
filename,
|
289
261
|
unitErrorVal: unitErrorVal,
|
@@ -313,36 +285,8 @@ module.exports = {
|
|
313
285
|
}
|
314
286
|
}
|
315
287
|
} else {
|
316
|
-
if (settingsObject[decl.prop] && decl.value && decl.value.includes('px') && decl.value.includes('var(--')) {
|
317
|
-
const valArr = decl.value.split(' ');
|
318
|
-
const settings = settingsObject[decl.prop];
|
319
|
-
const {
|
320
|
-
range,
|
321
|
-
allowed
|
322
|
-
} = settings;
|
323
|
-
const convertedVals = valArr.map(val => {
|
324
|
-
if (val.includes('px')) {
|
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
|
-
});
|
336
|
-
return convertedVal ? convertedVal : val;
|
337
|
-
}
|
338
|
-
|
339
|
-
return val;
|
340
|
-
});
|
341
|
-
decl.value = convertedVals.join(' ');
|
342
|
-
}
|
343
|
-
|
344
288
|
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')) {
|
345
|
-
|
289
|
+
let errObj = {
|
346
290
|
decl,
|
347
291
|
type: 'VARIABLE_PRESENT',
|
348
292
|
filename,
|