@zohodesk/react-cli 1.0.3-exp.5 → 1.1.0
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/.eslintignore +7 -7
- package/.eslintrc.js +180 -180
- package/.prettierrc +6 -6
- package/Changelog.md +1019 -1019
- package/README.md +1201 -1197
- package/bin/cli.js +489 -489
- package/docs/ComposeMinification.md +13 -13
- package/docs/CustomChunks.md +26 -26
- package/docs/DevServerPort.md +39 -39
- package/docs/DevStart.md +18 -18
- package/docs/HoverActive.md +12 -12
- package/docs/InstallNode.md +28 -28
- package/docs/ReactLive.md +10 -0
- package/docs/SelectorWeight.md +8 -8
- package/docs/TODOS.md +10 -10
- package/docs/ValueReplacer.md +60 -60
- package/docs/VariableConversion.md +729 -729
- package/docs/patternFiltering.md +57 -27
- package/docs/warnings_while_install.txt +35 -35
- package/files/eslintrc.js +62 -62
- package/files/prettierrc.js +3 -3
- package/lib/configs/webpack.css.umd.config.js +4 -4
- package/lib/configs/webpack.dev.config.js +0 -3
- package/lib/configs/webpack.docs.config.js +4 -2
- package/lib/configs/webpack.impact.config.js +0 -2
- package/lib/configs/webpack.prod.config.js +0 -3
- package/lib/loaderUtils/configsAssetsLoaders.js +33 -33
- package/lib/loaderUtils/getCSSLoaders.js +51 -54
- package/lib/loaders/docsLoader.js +15 -7
- package/lib/loaders/reactLiveConvertor.js +107 -0
- package/lib/loaders/workerLoader.js +9 -9
- package/lib/pluginUtils/getDevPlugins.js +7 -10
- package/lib/pluginUtils/getProdPlugins.js +7 -10
- package/lib/plugins/CustomAttributePlugin.md +35 -35
- package/lib/plugins/EFCPlugin.md +6 -6
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +4 -4
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +38 -38
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +30 -30
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +8 -8
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -95
- package/lib/plugins/I18nSplitPlugin/README.md +25 -25
- package/lib/plugins/I18nSplitPlugin/index.js +57 -57
- package/lib/plugins/ResourceHintsPlugin.js +17 -17
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +6 -6
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -30
- package/lib/plugins/SelectorPlugin.js +46 -47
- package/lib/plugins/ServiceWorkerPlugin.js +9 -9
- package/lib/plugins/TPHashMappingPlugin.js +4 -4
- package/lib/plugins/VariableConversionCollector.js +66 -184
- package/lib/plugins/utils/classHandling.js +16 -1
- package/lib/plugins/utils/fileHandling.js +10 -10
- package/lib/plugins/variableConvertorUtils.js +131 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +10 -10
- package/lib/postcss-plugins/__test__/test1Input.css +38 -38
- package/lib/postcss-plugins/__test__/test1Output.css +38 -38
- package/lib/postcss-plugins/hoverActivePlugin.js +3 -3
- package/lib/schemas/index.js +4 -2
- package/lib/sh/pre-commit.sh +34 -34
- package/lib/sh/reportPublish.sh +45 -45
- package/lib/utils/buildstats.html +148 -148
- package/lib/utils/cssClassNameGenerate.js +22 -24
- package/lib/utils/resultSchema.json +73 -73
- package/lib/utils/variableConverter.js +16 -129
- package/npm-shrinkwrap.json +14407 -14407
- package/npm8.md +9 -9
- package/package.json +122 -122
- package/postpublish.js +8 -8
- package/templates/app/.eslintrc.js +140 -140
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -24
- package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
- package/templates/app/app/properties/i18nkeys.json +3 -3
- package/templates/app/docs/all.html +69 -69
- package/templates/app/mockapi/index.js +18 -18
- package/templates/app/package.json +37 -37
- package/templates/app/src/actions/SampleActions/index.js +37 -37
- package/templates/app/src/actions/index.js +65 -65
- package/templates/app/src/appUrls.js +19 -19
- package/templates/app/src/components/Alert/Alert.js +134 -134
- package/templates/app/src/components/Alert/Alert.module.css +79 -79
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -37
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -84
- package/templates/app/src/components/Sample/Sample.module.css +11 -11
- package/templates/app/src/components/Sample/SampleList.js +61 -61
- package/templates/app/src/components/Slider/Slider.css +41 -41
- package/templates/app/src/components/Slider/Slider.js +55 -55
- package/templates/app/src/containers/AlertContainer/index.js +15 -15
- package/templates/app/src/containers/AppContainer/index.js +96 -96
- package/templates/app/src/containers/AppContainer/index.module.css +27 -27
- package/templates/app/src/containers/CustomMatch/index.js +65 -65
- package/templates/app/src/containers/DevTools/index.js +10 -10
- package/templates/app/src/containers/Header/index.js +67 -67
- package/templates/app/src/containers/Header/index.module.css +43 -43
- package/templates/app/src/containers/Redirect/index.js +63 -63
- package/templates/app/src/containers/Redirector/index.js +47 -47
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -42
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -3
- package/templates/app/src/historyChange.js +5 -5
- package/templates/app/src/index.html +10 -10
- package/templates/app/src/index.js +24 -24
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -59
- package/templates/app/src/reducers/alertData.js +11 -11
- package/templates/app/src/reducers/index.js +6 -6
- package/templates/app/src/reducers/samples.js +19 -19
- package/templates/app/src/store/configureStore.dev.js +51 -51
- package/templates/app/src/store/configureStore.js +5 -5
- package/templates/app/src/store/configureStore.prod.js +26 -26
- package/templates/app/src/util/Common.js +5 -5
- package/templates/app/src/util/RequestAPI.js +132 -132
- package/templates/docs/all.html +249 -249
- package/templates/docs/component.html +178 -178
- package/templates/docs/components.html +221 -221
- package/templates/docs/css/b.min.css +6 -6
- package/templates/docs/css/component.css +42 -42
- package/templates/docs/css/componentTest.css +6 -6
- package/templates/docs/css/hopscotch.css +585 -585
- package/templates/docs/css/style.css +1022 -1022
- package/templates/docs/impactReportTemplate.html +154 -154
- package/templates/docs/index.html +1501 -1501
- package/templates/docs/js/active-line.js +72 -72
- package/templates/docs/js/b.min.js +7 -7
- package/templates/docs/js/codemirror.js +9680 -9680
- package/templates/docs/js/designTokens.js +334 -334
- package/templates/docs/js/j.min.js +4 -4
- package/templates/docs/js/javascript.js +874 -874
- package/templates/docs/js/matchbrackets.js +145 -145
|
@@ -51,11 +51,11 @@ class ServiceWorkerPlugin {
|
|
|
51
51
|
if (err) {
|
|
52
52
|
throw new Error(err);
|
|
53
53
|
} else {
|
|
54
|
-
/* const extractedChunks = compilation.chunks.filter(chunk => {
|
|
55
|
-
if ('canBeInitial' in chunk) {
|
|
56
|
-
return chunk.canBeInitial();
|
|
57
|
-
}
|
|
58
|
-
return chunk.isInitial();
|
|
54
|
+
/* const extractedChunks = compilation.chunks.filter(chunk => {
|
|
55
|
+
if ('canBeInitial' in chunk) {
|
|
56
|
+
return chunk.canBeInitial();
|
|
57
|
+
}
|
|
58
|
+
return chunk.isInitial();
|
|
59
59
|
}); */
|
|
60
60
|
// let [js, css, , , i18nPublicPath] = this.publicPaths;
|
|
61
61
|
// let initialChunkUrls = [];
|
|
@@ -64,10 +64,10 @@ class ServiceWorkerPlugin {
|
|
|
64
64
|
let entrypoint = compilation.entrypoints.get('main');
|
|
65
65
|
let initialChunkUrls = entrypoint.getFiles();
|
|
66
66
|
const cssDirTemplate = '@dir@';
|
|
67
|
-
/**
|
|
68
|
-
* NOTE:
|
|
69
|
-
* if chunkSplitEnable is false means,
|
|
70
|
-
* serviceWorker will get i18n files path for html
|
|
67
|
+
/**
|
|
68
|
+
* NOTE:
|
|
69
|
+
* if chunkSplitEnable is false means,
|
|
70
|
+
* serviceWorker will get i18n files path for html
|
|
71
71
|
*/
|
|
72
72
|
|
|
73
73
|
let initalI18nAssets = chunkSplitEnable ? entrypoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@')) : [];
|
|
@@ -15,10 +15,10 @@ var _crypto = _interopRequireDefault(require("crypto"));
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Plugin that generates hash for the provided list of third party files
|
|
20
|
-
* Map the provided key with the file hash and add it to the list of exisiting global constants.
|
|
21
|
-
* Plugin in turn uses the defineplugin to generate global constants.
|
|
18
|
+
/**
|
|
19
|
+
* Plugin that generates hash for the provided list of third party files
|
|
20
|
+
* Map the provided key with the file hash and add it to the list of exisiting global constants.
|
|
21
|
+
* Plugin in turn uses the defineplugin to generate global constants.
|
|
22
22
|
*/
|
|
23
23
|
class TPHashMappingPlugin {
|
|
24
24
|
constructor(options) {
|
|
@@ -11,12 +11,13 @@ var _ErrorHandler = require("../postcss-plugins/variableModificationPlugin/Error
|
|
|
11
11
|
|
|
12
12
|
var _fileHandling = require("./utils/fileHandling");
|
|
13
13
|
|
|
14
|
+
var _variableConvertorUtils = require("./variableConvertorUtils");
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
18
|
// import { RawSource } from 'webpack-sources';
|
|
17
19
|
const fs = require('fs');
|
|
18
20
|
|
|
19
|
-
const ignoreVals = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
|
20
21
|
let variablesRead = {};
|
|
21
22
|
|
|
22
23
|
const {
|
|
@@ -25,134 +26,18 @@ const {
|
|
|
25
26
|
errHandler
|
|
26
27
|
} = require('../postcss-plugins/variableModificationPlugin/index');
|
|
27
28
|
|
|
28
|
-
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'];
|
|
29
|
-
|
|
30
|
-
function convertCalcValue(pxReplacement, parsedValue) {
|
|
31
|
-
Object.keys(parsedValue).forEach(key => {
|
|
32
|
-
if (parsedValue[key].includes('px')) {
|
|
33
|
-
parsedValue[key] = pxReplacement.replace('$$', parsedValue[key].replace('px', ''));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return parsedValue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function parseCalcValue(calcValue) {
|
|
40
|
-
// Remove "calc(" and ")" from the string
|
|
41
|
-
const value = calcValue.replace(/calc\(/gi, '').replace(/\)/gi, '').trim(); // Split the string by "*" or "/"
|
|
42
|
-
|
|
43
|
-
const parts = value.split(/[\\/*]/); // Parse the first part as a number
|
|
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']; // -- to convert the hyphen values to values --
|
|
44
30
|
|
|
45
|
-
|
|
31
|
+
/*
|
|
32
|
+
input :
|
|
33
|
+
var(--zdt_uploadlist_default_width)
|
|
34
|
+
output :
|
|
35
|
+
--zdt_uploadlist_default_width
|
|
46
36
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
valOne: num1,
|
|
50
|
-
valTwo: num2
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function convertToCalc(pxReplacement, value) {
|
|
55
|
-
const parsedValue = parseFloat(value, 10);
|
|
56
|
-
const sign = parsedValue < 0 ? '-' : '';
|
|
57
|
-
const varName = `${parsedValue < 0 ? parsedValue * -1 : parsedValue}`;
|
|
58
|
-
return `calc( ${pxReplacement.replace('$$', varName)} * ${sign}1 )`;
|
|
59
|
-
} // const avoidProps = [];
|
|
60
|
-
// -- is issue IO --
|
|
61
|
-
|
|
62
|
-
/*
|
|
63
|
-
issues eg :
|
|
64
|
-
issues = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
|
65
|
-
input :
|
|
66
|
-
--zd_size
|
|
67
|
-
output :
|
|
68
|
-
true
|
|
69
|
-
comment :
|
|
70
|
-
do not execute when --zd_size comes as prop
|
|
37
|
+
comment :
|
|
38
|
+
to make the variable object using the output as key and decl.prop such as font-size as value
|
|
71
39
|
*/
|
|
72
40
|
|
|
73
|
-
|
|
74
|
-
function isIgnoreValuePresent(ignoreVals, prop) {
|
|
75
|
-
let present = false;
|
|
76
|
-
ignoreVals.forEach(issue => {
|
|
77
|
-
if (prop && prop.includes(issue)) {
|
|
78
|
-
present = true;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return present;
|
|
82
|
-
} // -- to convert the hyphen values to values --
|
|
83
|
-
|
|
84
|
-
/*
|
|
85
|
-
input :
|
|
86
|
-
var(--zdt_uploadlist_default_width)
|
|
87
|
-
output :
|
|
88
|
-
--zdt_uploadlist_default_width
|
|
89
|
-
|
|
90
|
-
comment :
|
|
91
|
-
to make the variable object using the output as key and decl.prop such as font-size as value
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
function extractVariableName(val) {
|
|
96
|
-
return val.replace(/calc\((.+)\)/gi, '$1').replace(/var\((.+)\)/gi, '$1').replace('-1', '').replace('*', '').replace('\n', '').trim();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function variableConvertor(rootOriginal, variables, settingsObject) {
|
|
100
|
-
rootOriginal.walkRules(rule => {
|
|
101
|
-
rule.nodes.forEach((decl, index) => {
|
|
102
|
-
const prevNode = rule.nodes[index - 1];
|
|
103
|
-
const currentNode = rule.nodes[index];
|
|
104
|
-
|
|
105
|
-
if (decl.prop && decl.prop.includes('--')) {
|
|
106
|
-
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'variable:ignore') {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (isIgnoreValuePresent(ignoreVals, decl.prop)) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (settingsObject[variables[decl.prop]]) {
|
|
115
|
-
/* if there is no value for property, set it to default so that undefined doesn't get called as key */
|
|
116
|
-
if (!variables[decl.prop]) {
|
|
117
|
-
variables[decl.prop] = 'default';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
|
|
121
|
-
const valArr = decl.value.split(' '); // single values are considered in the above array and converted below
|
|
122
|
-
|
|
123
|
-
valArr.forEach((value, index) => {
|
|
124
|
-
if (value.includes('px')) {
|
|
125
|
-
if (value.includes('calc')) {
|
|
126
|
-
const res = convertCalcValue(pxReplacement, parseCalcValue(value));
|
|
127
|
-
valArr[index] = `calc( ${res.valOne.trim()} * ${res.valTwo.trim()} )`;
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (/-(\d+)/gi.test(value)) {
|
|
132
|
-
valArr[index] = convertToCalc(pxReplacement, value);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const num = value.replace('px', '');
|
|
137
|
-
|
|
138
|
-
if (value) {
|
|
139
|
-
valArr[index] = pxReplacement.replace('$$', num);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (value.includes('px')) {
|
|
144
|
-
const num = value.replace('px', '');
|
|
145
|
-
valArr[index] = pxReplacement.replace('$$', num);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
currentNode.value = valArr.join(' ');
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
return rootOriginal;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
41
|
function createFolderIfNonExistant(path) {
|
|
157
42
|
if (!fs.existsSync(path)) {
|
|
158
43
|
fs.mkdirSync(path, {
|
|
@@ -171,8 +56,7 @@ class VariableConversionCollector {
|
|
|
171
56
|
constructor(options = {}) {
|
|
172
57
|
this.optimize = options.optimize;
|
|
173
58
|
this.filename = options.cssVariableReplacementConfig;
|
|
174
|
-
this.patterns = options.patterns;
|
|
175
|
-
this.rootDir = options.patternsRootDir; // console.log(options.patterns, this.patterns);
|
|
59
|
+
this.patterns = options.patterns; // console.log(options.patterns, this.patterns);
|
|
176
60
|
|
|
177
61
|
this.initializeFiles();
|
|
178
62
|
}
|
|
@@ -211,13 +95,13 @@ class VariableConversionCollector {
|
|
|
211
95
|
}
|
|
212
96
|
};
|
|
213
97
|
}
|
|
214
|
-
/*
|
|
215
|
-
purpose of tap : to create a variable object such as:
|
|
216
|
-
{
|
|
217
|
-
--zdt_uploadlist_default_width : width,
|
|
218
|
-
--zdt_uploadlist_default_height : height,
|
|
219
|
-
}
|
|
220
|
-
which will help in the conversion further
|
|
98
|
+
/*
|
|
99
|
+
purpose of tap : to create a variable object such as:
|
|
100
|
+
{
|
|
101
|
+
--zdt_uploadlist_default_width : width,
|
|
102
|
+
--zdt_uploadlist_default_height : height,
|
|
103
|
+
}
|
|
104
|
+
which will help in the conversion further
|
|
221
105
|
*/
|
|
222
106
|
|
|
223
107
|
|
|
@@ -240,8 +124,8 @@ class VariableConversionCollector {
|
|
|
240
124
|
rootOriginal.walkRules(rule => {
|
|
241
125
|
rule.walkDecls(decl => {
|
|
242
126
|
decl.value.split(' ').forEach(val => {
|
|
243
|
-
if (val && val.includes('--') && !new RegExp(ignoreVals.join('|'), 'gi').test(val) && decl.prop) {
|
|
244
|
-
const extractedValue = extractVariableName(val);
|
|
127
|
+
if (val && val.includes('--') && !new RegExp(_variableConvertorUtils.ignoreVals.join('|'), 'gi').test(val) && decl.prop) {
|
|
128
|
+
const extractedValue = (0, _variableConvertorUtils.extractVariableName)(val);
|
|
245
129
|
|
|
246
130
|
if (!variables[extractedValue]) {
|
|
247
131
|
variables[extractedValue] = decl.prop;
|
|
@@ -269,19 +153,19 @@ class VariableConversionCollector {
|
|
|
269
153
|
});
|
|
270
154
|
});
|
|
271
155
|
});
|
|
272
|
-
/*
|
|
273
|
-
current value example:
|
|
274
|
-
{
|
|
275
|
-
--zdt_uploadlist_default_width : --zd_upload_width,
|
|
276
|
-
--zd_upload_width : width
|
|
277
|
-
}
|
|
278
|
-
expected value :
|
|
279
|
-
{
|
|
280
|
-
--zdt_uploadlist_default_width : width,
|
|
281
|
-
--zd_upload_width : width
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
conversion is done in the while loop below
|
|
156
|
+
/*
|
|
157
|
+
current value example:
|
|
158
|
+
{
|
|
159
|
+
--zdt_uploadlist_default_width : --zd_upload_width,
|
|
160
|
+
--zd_upload_width : width
|
|
161
|
+
}
|
|
162
|
+
expected value :
|
|
163
|
+
{
|
|
164
|
+
--zdt_uploadlist_default_width : width,
|
|
165
|
+
--zd_upload_width : width
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
conversion is done in the while loop below
|
|
285
169
|
*/
|
|
286
170
|
|
|
287
171
|
Object.keys(variables).forEach(key => {
|
|
@@ -293,60 +177,58 @@ class VariableConversionCollector {
|
|
|
293
177
|
});
|
|
294
178
|
}); // -- conversion for the root using variableConvertor --
|
|
295
179
|
|
|
296
|
-
/*
|
|
297
|
-
input :
|
|
298
|
-
.a{
|
|
299
|
-
padding : 20px
|
|
300
|
-
}
|
|
301
|
-
output :
|
|
302
|
-
// on settingObject file :
|
|
303
|
-
{ padding : { replacements : { px : 'zd_size$$' }}}
|
|
304
|
-
.a{
|
|
305
|
-
padding : zd_size20;
|
|
306
|
-
}
|
|
180
|
+
/*
|
|
181
|
+
input :
|
|
182
|
+
.a{
|
|
183
|
+
padding : 20px
|
|
184
|
+
}
|
|
185
|
+
output :
|
|
186
|
+
// on settingObject file :
|
|
187
|
+
{ padding : { replacements : { px : 'zd_size$$' }}}
|
|
188
|
+
.a{
|
|
189
|
+
padding : zd_size20;
|
|
190
|
+
}
|
|
307
191
|
*/
|
|
308
192
|
|
|
309
193
|
compilation.hooks.optimizeModules.tap('VariableConversionCollector', modules => {
|
|
310
194
|
const mods = modules.filter(x => x.type.includes('css'));
|
|
311
195
|
mods.forEach(module => {
|
|
312
196
|
const filename = module.issuer.resource;
|
|
313
|
-
/*
|
|
314
|
-
input :
|
|
315
|
-
filename : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
// include src folder, include deskapp folder, exclude node modules
|
|
319
|
-
"cssVariableReplacement": [
|
|
320
|
-
"src",
|
|
321
|
-
"deskapp",
|
|
322
|
-
"!node_modules"
|
|
323
|
-
]
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
true or false
|
|
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
|
|
328
211
|
*/
|
|
329
212
|
|
|
330
213
|
if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
|
|
331
214
|
filename,
|
|
332
|
-
filterArr: this.patterns.cssVariableReplacement
|
|
333
|
-
rootDir: this.rootDir
|
|
215
|
+
filterArr: this.patterns.cssVariableReplacement
|
|
334
216
|
})) {
|
|
335
217
|
return;
|
|
336
218
|
}
|
|
337
219
|
|
|
338
220
|
const rootOriginal = _postcss.default.parse(module.content);
|
|
339
221
|
|
|
340
|
-
module.content =
|
|
222
|
+
module.content = (0, _variableConvertorUtils.variableConverter)(rootOriginal, variables, settingsObject).toString();
|
|
341
223
|
});
|
|
342
224
|
});
|
|
343
225
|
});
|
|
344
|
-
/*
|
|
345
|
-
purpose of tap : to display the errors encountered so far
|
|
346
|
-
input :
|
|
347
|
-
all css files
|
|
348
|
-
output :
|
|
349
|
-
all errors that are present in the errTable arr
|
|
226
|
+
/*
|
|
227
|
+
purpose of tap : to display the errors encountered so far
|
|
228
|
+
input :
|
|
229
|
+
all css files
|
|
230
|
+
output :
|
|
231
|
+
all errors that are present in the errTable arr
|
|
350
232
|
*/
|
|
351
233
|
|
|
352
234
|
compiler.hooks.afterEmit.tap('error-display', () => {
|
|
@@ -5,10 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.hasPrevNodeIgnore = hasPrevNodeIgnore;
|
|
7
7
|
exports.isAtRule = isAtRule;
|
|
8
|
+
exports.isComment = isComment;
|
|
9
|
+
exports.isCommentContentSame = isCommentContentSame;
|
|
8
10
|
exports.isInsideMediaQuery = isInsideMediaQuery;
|
|
11
|
+
exports.isThisComment = isThisComment;
|
|
12
|
+
|
|
13
|
+
function isComment(node) {
|
|
14
|
+
return node && node.type && node.type === 'comment';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isCommentContentSame(node, content) {
|
|
18
|
+
return node.text.toLowerCase() === content;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isThisComment(node, ignoreComment) {
|
|
22
|
+
return isComment(node) && isCommentContentSame(node, ignoreComment);
|
|
23
|
+
}
|
|
9
24
|
|
|
10
25
|
function hasPrevNodeIgnore(index, prevNode, ignoreComment) {
|
|
11
|
-
return index !== 0 && prevNode
|
|
26
|
+
return index !== 0 && isThisComment(prevNode, ignoreComment);
|
|
12
27
|
}
|
|
13
28
|
|
|
14
29
|
function isAtRule(rule) {
|
|
@@ -23,10 +23,10 @@ let aliasNames = {
|
|
|
23
23
|
cssVariableReplacement: 'postcss-variable-report',
|
|
24
24
|
composeMinification: 'postcss-compose-plugin'
|
|
25
25
|
};
|
|
26
|
-
/*
|
|
27
|
-
|
|
28
|
-
unique scenario
|
|
29
|
-
|
|
26
|
+
/*
|
|
27
|
+
|
|
28
|
+
unique scenario
|
|
29
|
+
|
|
30
30
|
*/
|
|
31
31
|
// export function filterFileCssUniqueness(filename, filterObj) {
|
|
32
32
|
// let rootDir = 'supportapp';
|
|
@@ -48,13 +48,12 @@ unique scenario
|
|
|
48
48
|
function isFileNameMatchingPattern({
|
|
49
49
|
filename,
|
|
50
50
|
filterObject,
|
|
51
|
-
plugins
|
|
52
|
-
rootDir
|
|
51
|
+
plugins
|
|
53
52
|
}) {
|
|
54
53
|
const finalPlugins = []; // console.log(rootDir);
|
|
55
54
|
// const regex = `^(.+?)${rootDir}?\\\\`;
|
|
56
55
|
|
|
57
|
-
const newFilename = path.relative(
|
|
56
|
+
const newFilename = path.relative(path.parse(process.cwd()).base, filename); //windowsModificationFile(filename).replace(
|
|
58
57
|
// new RegExp(regex, 'gi'),
|
|
59
58
|
// ''
|
|
60
59
|
// );
|
|
@@ -83,14 +82,15 @@ function isFileNameMatchingPattern({
|
|
|
83
82
|
|
|
84
83
|
function isFileNameMatchingPluginPattern({
|
|
85
84
|
filename,
|
|
86
|
-
filterArr
|
|
87
|
-
|
|
85
|
+
filterArr // =process.cwd()
|
|
86
|
+
|
|
88
87
|
}) {
|
|
88
|
+
// console.log(rootDir);
|
|
89
89
|
let include = true; // console.log(rootDir);
|
|
90
90
|
// const regex = `^(.+?)${rootDir}?\\\\`;
|
|
91
91
|
// console.log(plugin);
|
|
92
92
|
|
|
93
|
-
const newFilename = path.relative(
|
|
93
|
+
const newFilename = path.relative(path.parse(process.cwd()).base, filename); // const newFilename = windowsModificationFile(filename).replace(
|
|
94
94
|
// new RegExp(regex, 'gi'),
|
|
95
95
|
// ''
|
|
96
96
|
// );
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extractVariableName = extractVariableName;
|
|
7
|
+
exports.ignoreVals = void 0;
|
|
8
|
+
exports.variableConverter = variableConverter;
|
|
9
|
+
|
|
10
|
+
var _classHandling = require("./utils/classHandling");
|
|
11
|
+
|
|
12
|
+
const ignoreVals = ['--zd_size', '--zd_font_size', '--size', '--size_']; // const avoidProps = [];
|
|
13
|
+
// -- is issue IO --
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
issues eg :
|
|
17
|
+
issues = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
|
18
|
+
input :
|
|
19
|
+
--zd_size
|
|
20
|
+
output :
|
|
21
|
+
true
|
|
22
|
+
comment :
|
|
23
|
+
do not execute when --zd_size comes as prop
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
exports.ignoreVals = ignoreVals;
|
|
27
|
+
|
|
28
|
+
function extractVariableName(val) {
|
|
29
|
+
return val.replace(/calc\((.+)\)/gi, '$1').replace(/var\((.+)\)/gi, '$1').replace('-1', '').replace('*', '').replace('\n', '').trim();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isIgnoreValuePresent(ignoreVals, prop) {
|
|
33
|
+
return ignoreVals.some(ignoreVal => prop && prop.includes(ignoreVal)); // let present = false;
|
|
34
|
+
// return ignoreVals.forEach(issue => {
|
|
35
|
+
// if (prop && prop.includes(issue)) {
|
|
36
|
+
// present = true;
|
|
37
|
+
// }
|
|
38
|
+
// });
|
|
39
|
+
// return present;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseCalcValue(calcValue) {
|
|
43
|
+
// Remove "calc(" and ")" from the string
|
|
44
|
+
const value = calcValue.replace(/calc\(/gi, '').replace(/\)/gi, '').trim(); // Split the string by "*" or "/"
|
|
45
|
+
|
|
46
|
+
const parts = value.split(/[\\/*]/); // Parse the first part as a number
|
|
47
|
+
|
|
48
|
+
const num1 = parts[0].trim(); // Parse the second part as a number
|
|
49
|
+
|
|
50
|
+
const num2 = parts[1].trim();
|
|
51
|
+
return {
|
|
52
|
+
valOne: num1,
|
|
53
|
+
valTwo: num2
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function convertToCalc(pxReplacement, value) {
|
|
58
|
+
const parsedValue = parseFloat(value, 10);
|
|
59
|
+
const sign = parsedValue < 0 ? '-' : '';
|
|
60
|
+
const varName = `${parsedValue < 0 ? parsedValue * -1 : parsedValue}`;
|
|
61
|
+
return `calc( ${pxReplacement.replace('$$', varName)} * ${sign}1 )`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function convertCalcValue(pxReplacement, parsedValue) {
|
|
65
|
+
Object.keys(parsedValue).forEach(key => {
|
|
66
|
+
if (parsedValue[key].includes('px')) {
|
|
67
|
+
parsedValue[key] = pxReplacement.replace('$$', parsedValue[key].replace('px', ''));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return parsedValue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function variableConverter(rootOriginal, variables, settingsObject) {
|
|
74
|
+
rootOriginal.walkRules(rule => {
|
|
75
|
+
rule.nodes.forEach((decl, index) => {
|
|
76
|
+
const prevNode = rule.nodes[index - 1];
|
|
77
|
+
const currentNode = rule.nodes[index];
|
|
78
|
+
|
|
79
|
+
if (decl.prop && decl.prop.includes('--')) {
|
|
80
|
+
if ((0, _classHandling.isThisComment)(prevNode, 'variable:ignore') // prevNode &&
|
|
81
|
+
// prevNode.type === 'comment' &&
|
|
82
|
+
// prevNode.text.toLowerCase() === 'variable:ignore'
|
|
83
|
+
) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (isIgnoreValuePresent(ignoreVals, decl.prop)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (settingsObject[variables[decl.prop]]) {
|
|
92
|
+
/* if there is no value for property, set it to default so that undefined doesn't get called as key */
|
|
93
|
+
if (!variables[decl.prop]) {
|
|
94
|
+
variables[decl.prop] = 'default';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
|
|
98
|
+
const valArr = decl.value.split(' '); // single values are considered in the above array and converted below
|
|
99
|
+
|
|
100
|
+
valArr.forEach((value, index) => {
|
|
101
|
+
if (value.includes('px')) {
|
|
102
|
+
if (value.includes('calc')) {
|
|
103
|
+
const res = convertCalcValue(pxReplacement, parseCalcValue(value));
|
|
104
|
+
valArr[index] = `calc( ${res.valOne.trim()} * ${res.valTwo.trim()} )`;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (/-(\d+)/gi.test(value)) {
|
|
109
|
+
valArr[index] = convertToCalc(pxReplacement, value);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const num = value.replace('px', '');
|
|
114
|
+
|
|
115
|
+
if (value) {
|
|
116
|
+
valArr[index] = pxReplacement.replace('$$', num);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (value.includes('px')) {
|
|
121
|
+
const num = value.replace('px', '');
|
|
122
|
+
valArr[index] = pxReplacement.replace('$$', num);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
currentNode.value = valArr.join(' ');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
return rootOriginal;
|
|
131
|
+
}
|
|
@@ -37,11 +37,11 @@ function selectorMinifySameDir(selector, direction) {
|
|
|
37
37
|
const regex = getRegex(direction);
|
|
38
38
|
return selector.replace(regex, '').trim();
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
41
|
-
* this funtion will remove given rule,
|
|
42
|
-
* if given selector and it's previous sibiling rule selector are same
|
|
43
|
-
* current rule properties will move to previous sibiling rule.
|
|
44
|
-
* @param {Rule} rule current rule
|
|
40
|
+
/**
|
|
41
|
+
* this funtion will remove given rule,
|
|
42
|
+
* if given selector and it's previous sibiling rule selector are same
|
|
43
|
+
* current rule properties will move to previous sibiling rule.
|
|
44
|
+
* @param {Rule} rule current rule
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
47
|
|
|
@@ -56,11 +56,11 @@ function mergeIfSameSelector(rule) {
|
|
|
56
56
|
rule.remove();
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
60
|
-
* this funtion will remove given rule,
|
|
61
|
-
* if given selector and it's previous sibiling rule selector are same
|
|
62
|
-
* current rule properties will move to previous sibiling rule.
|
|
63
|
-
* @param {Rule} rule current rule
|
|
59
|
+
/**
|
|
60
|
+
* this funtion will remove given rule,
|
|
61
|
+
* if given selector and it's previous sibiling rule selector are same
|
|
62
|
+
* current rule properties will move to previous sibiling rule.
|
|
63
|
+
* @param {Rule} rule current rule
|
|
64
64
|
*/
|
|
65
65
|
|
|
66
66
|
|