@zohodesk/react-cli 0.0.1-test.148.3 → 1.0.0-exp.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintignore +7 -7
- package/.eslintrc.js +180 -183
- package/.prettierrc +6 -0
- package/{CHANGELOG.md → CHANGELOG-fz.md} +0 -0
- package/Changelog.md +1019 -0
- package/README.md +1161 -678
- package/bin/cli.js +483 -392
- package/docs/CustomChunks.md +26 -0
- package/docs/DevServerPort.md +39 -0
- package/docs/DevStart.md +18 -0
- package/docs/HoverActive.md +12 -0
- package/docs/InstallNode.md +28 -0
- package/docs/SelectorWeight.md +6 -0
- package/docs/TODOS.md +10 -0
- package/docs/ValueReplacer.md +60 -0
- package/docs/VariableConversion.md +724 -0
- package/docs/warnings_while_install.txt +35 -0
- package/files/eslintrc.js +62 -62
- package/files/prettierrc.js +3 -3
- package/lib/common/getEntries.js +9 -6
- package/lib/common/index.js +6 -6
- package/lib/common/splitChunks.js +60 -12
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/testPattern.js +69 -0
- package/lib/common/valueReplacer.js +55 -0
- package/lib/configs/jest.config.js +18 -8
- package/lib/configs/libAlias.js +38 -0
- package/lib/configs/resolvers.js +40 -0
- package/lib/configs/webpack.css.umd.config.js +4 -4
- package/lib/configs/webpack.dev.config.js +59 -54
- package/lib/configs/webpack.docs.config.js +74 -59
- package/lib/configs/webpack.docs1.config.js +122 -0
- package/lib/configs/webpack.impact.config.js +54 -50
- package/lib/configs/webpack.prod.config.js +72 -47
- package/lib/constants.js +31 -0
- package/lib/hooks/docsEntry.js +18 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -7
- package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
- package/lib/loaderUtils/getCSSLoaders.js +89 -21
- package/lib/loaderUtils/index.js +4 -4
- package/lib/loaderUtils/windowsModification.js +11 -0
- package/lib/loaders/fileBountryLoader.js +17 -0
- package/lib/loaders/scriptInstrumentLoader.js +2 -2
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +9 -9
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +60 -0
- package/lib/pluginUtils/getDevPlugins.js +70 -45
- package/lib/pluginUtils/getDocsPlugins.js +21 -10
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getProdPlugins.js +74 -58
- package/lib/pluginUtils/index.js +12 -12
- package/lib/plugins/CdnChangePlugin.js +16 -2
- package/lib/plugins/EFCPlugin.js +52 -20
- package/lib/plugins/EFCPlugin.md +6 -0
- package/lib/plugins/EFCTemplatePlugin.js +151 -0
- 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 -86
- package/lib/plugins/I18nSplitPlugin/README.md +25 -25
- package/lib/plugins/I18nSplitPlugin/index.js +57 -57
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +2 -2
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +1 -1
- package/lib/plugins/ManifestPlugin.js +8 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +17 -17
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +6 -6
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
- package/lib/plugins/SelectorPlugin.js +97 -0
- package/lib/plugins/ServiceWorkerPlugin.js +13 -9
- package/lib/plugins/SourceMapHookPlugin.js +9 -3
- package/lib/plugins/TPHashMappingPlugin.js +4 -4
- package/lib/plugins/VariableConversionCollector.js +352 -0
- package/lib/plugins/composeCommonPlugin.js +30 -0
- package/lib/plugins/index.js +36 -36
- package/lib/plugins/libraryImpactPlugin.js +14 -2
- package/lib/postcss-plugins/{ExcludeRTLPlugin.js → ExcludePlugin.js} +1 -1
- package/lib/postcss-plugins/RTLSplitPlugin.js +13 -13
- package/lib/postcss-plugins/ValueReplacer.js +46 -0
- 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 +389 -0
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +60 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +307 -0
- package/lib/postcss-plugins/variableModifier.js +244 -0
- package/lib/schemas/index.js +173 -11
- package/lib/servers/devBuild.js +102 -0
- package/lib/servers/docsServerCore.js +16 -18
- package/lib/servers/getCliPath.js +28 -0
- package/lib/servers/httpsOptions.js +49 -0
- package/lib/servers/nowatchserver.js +206 -0
- package/lib/servers/server.js +114 -82
- package/lib/sh/pre-commit.sh +34 -34
- package/lib/sh/reportPublish.sh +45 -45
- package/lib/templates/linterConstant.js +1 -1
- package/lib/utils/buildstats.html +148 -148
- package/lib/utils/cssClassNameGenerate.js +9 -2
- package/lib/utils/cssURLReplacer.js +30 -43
- package/lib/utils/getCurrentBranch.js +1 -1
- package/lib/utils/getDependenciesImpactList.js +14 -12
- package/lib/utils/getFileType.js +49 -0
- package/lib/utils/getOptions.js +118 -10
- package/lib/utils/index.js +44 -20
- package/lib/utils/jsonHelper.js +12 -3
- package/lib/utils/reinstallDependencies.js +1 -1
- package/lib/utils/repoClone.js +16 -4
- package/lib/utils/resultSchema.json +73 -73
- package/lib/utils/rtl.js +19 -2
- package/lib/utils/useExitCleanup.js +55 -0
- package/npm8.md +9 -0
- package/package.json +121 -142
- package/postpublish.js +8 -0
- package/result.json +1 -0
- 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/a.html +13 -0
- 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/docsEntry.js +14 -0
- package/templates/docs/docsRoot.js +3 -0
- package/templates/docs/impactReportTemplate.html +154 -154
- package/templates/docs/index.html +1501 -1493
- 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
- package/unittest/index.html +37 -0
- package/cert/cert.pem +0 -105
- package/cert/key.pem +0 -30
@@ -0,0 +1,307 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const postcss = require('postcss');
|
4
|
+
|
5
|
+
const fs = require('fs');
|
6
|
+
|
7
|
+
const path = require('path');
|
8
|
+
|
9
|
+
const {
|
10
|
+
ErrorHandler
|
11
|
+
} = require('./ErrorHandler');
|
12
|
+
|
13
|
+
const errors = [];
|
14
|
+
const errorTable = [];
|
15
|
+
const errHandler = new ErrorHandler();
|
16
|
+
const convertableProps = {
|
17
|
+
'font-size': true,
|
18
|
+
margin: true,
|
19
|
+
'margin-left': true,
|
20
|
+
'margin-right': true,
|
21
|
+
'margin-top': true,
|
22
|
+
'margin-bottom': true,
|
23
|
+
padding: true,
|
24
|
+
'padding-top': true,
|
25
|
+
'padding-bottom': true,
|
26
|
+
'padding-left': true,
|
27
|
+
'padding-right': true,
|
28
|
+
width: true,
|
29
|
+
'min-width': true,
|
30
|
+
'max-width': true,
|
31
|
+
height: true,
|
32
|
+
'min-height': true,
|
33
|
+
'max-height': true,
|
34
|
+
top: true,
|
35
|
+
bottom: true,
|
36
|
+
left: true,
|
37
|
+
right: true,
|
38
|
+
'text-indent': true,
|
39
|
+
clip: true,
|
40
|
+
'flex-basis': true,
|
41
|
+
'row-gap': true,
|
42
|
+
gap: true,
|
43
|
+
'column-gap': true,
|
44
|
+
flex: true
|
45
|
+
};
|
46
|
+
const constantValues = {
|
47
|
+
inherit: true,
|
48
|
+
initial: true,
|
49
|
+
auto: true,
|
50
|
+
'fit-content': true,
|
51
|
+
unset: true,
|
52
|
+
cover: true,
|
53
|
+
contain: true,
|
54
|
+
top: true,
|
55
|
+
bottom: true,
|
56
|
+
left: true,
|
57
|
+
center: true,
|
58
|
+
right: true
|
59
|
+
};
|
60
|
+
|
61
|
+
function getNumericValue(value) {
|
62
|
+
if (value.includes('var')) {
|
63
|
+
return parseInt(value.replace(/var\(--zd_size(\d+)\)/gi, '$1').replace(/var\(--zd_font_size(\d+)\)/gi, '$1'));
|
64
|
+
}
|
65
|
+
|
66
|
+
if (value.includes('rect')) {
|
67
|
+
return parseInt(value.replace('rect(', '').replace(')', '').replace(',', ''));
|
68
|
+
} // Not need for this dum loop
|
69
|
+
// allowed.forEach(alwdUnit => {
|
70
|
+
// if (value.includes(alwdUnit)) {
|
71
|
+
// return parseInt(value);
|
72
|
+
// }
|
73
|
+
// });
|
74
|
+
|
75
|
+
|
76
|
+
if (constantValues[value.toLowerCase()]) {
|
77
|
+
return 1;
|
78
|
+
}
|
79
|
+
|
80
|
+
return parseInt(value);
|
81
|
+
}
|
82
|
+
|
83
|
+
function pxToCalc(value) {
|
84
|
+
const arr = value.split(' ');
|
85
|
+
arr.forEach((val, index) => {
|
86
|
+
['px'].forEach(unit => {
|
87
|
+
const valWithUnit = new RegExp(`(\\d+)${unit}`, 'gi');
|
88
|
+
|
89
|
+
if (valWithUnit.test(val)) {
|
90
|
+
arr[index] = val.replace(valWithUnit, '(var(--zd_size$1))');
|
91
|
+
}
|
92
|
+
});
|
93
|
+
});
|
94
|
+
return arr.join(' ');
|
95
|
+
}
|
96
|
+
|
97
|
+
const singleConvertor = (value, changeVal, details, range) => {
|
98
|
+
const {
|
99
|
+
path,
|
100
|
+
filename,
|
101
|
+
decl
|
102
|
+
} = details;
|
103
|
+
|
104
|
+
if (decl.prop === 'background-position') {
|
105
|
+
if (isNaN(parseInt(value))) {
|
106
|
+
// console.log(`${value} skipped`);
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
if (getNumericValue(value) >= range.start && getNumericValue(value) <= range.end || getNumericValue(value) === 0) {
|
112
|
+
let retVal = value.replace(/(\d+)px/gi, changeVal.replace('$$', '$1'));
|
113
|
+
|
114
|
+
if (/^-var/.test(retVal)) {
|
115
|
+
retVal = `calc( ${retVal.substring(1)} * -1 )`;
|
116
|
+
}
|
117
|
+
|
118
|
+
return retVal;
|
119
|
+
} // if (!value.includes('rect')) {
|
120
|
+
// if(unitErrorVal && unitErrorVal != '0' ){
|
121
|
+
// console.log(value, 'not within range')
|
122
|
+
|
123
|
+
|
124
|
+
let errObj = {
|
125
|
+
decl,
|
126
|
+
type: 'RANGE_ERROR',
|
127
|
+
filename,
|
128
|
+
message: `value (${value}) (${typeof value}) not within range (${range.start},${range.end})\r`,
|
129
|
+
path: path
|
130
|
+
};
|
131
|
+
errHandler.errorTable.push(errObj);
|
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
|
+
// }
|
150
|
+
};
|
151
|
+
|
152
|
+
module.exports = {
|
153
|
+
plugin: postcss.plugin('postcss-variable-report', cssVariableReplacementConfig => {
|
154
|
+
const rawdata = fs.readFileSync(cssVariableReplacementConfig);
|
155
|
+
const data = JSON.parse(rawdata);
|
156
|
+
const {
|
157
|
+
errorsAllowed,
|
158
|
+
settings: settingsObject // errorLog: errorLogStatus,
|
159
|
+
// errorInConsole: errorConsoleStatus
|
160
|
+
|
161
|
+
} = data; // const keys = Object.keys(settingsObject);
|
162
|
+
|
163
|
+
errHandler.setAllowedErrs(errorsAllowed);
|
164
|
+
const replacementArray = [];
|
165
|
+
Object.keys(settingsObject).forEach(key => {
|
166
|
+
Object.values(settingsObject[key].replacements).forEach(val => {
|
167
|
+
if (!replacementArray.includes(val)) {
|
168
|
+
replacementArray.push(val);
|
169
|
+
}
|
170
|
+
});
|
171
|
+
});
|
172
|
+
let regValStr = '';
|
173
|
+
replacementArray.forEach((val, index) => {
|
174
|
+
if (index !== replacementArray.length - 1) {
|
175
|
+
regValStr += `${val.replace('$$', '\\d+').replace('(', '\\(').replace(')', '\\)')}|`;
|
176
|
+
} else {
|
177
|
+
regValStr += `${val.replace('$$', '\\d+').replace('(', '\\(').replace(')', '\\)')}`;
|
178
|
+
}
|
179
|
+
});
|
180
|
+
const valRegex = new RegExp(regValStr, 'gi');
|
181
|
+
return rootOriginal => {
|
182
|
+
rootOriginal.walkRules(rule => {
|
183
|
+
// rule.nodes[-1] = {}
|
184
|
+
// need map, forEach fine less memory
|
185
|
+
rule.nodes.forEach((decl, position) => {
|
186
|
+
// case font-size
|
187
|
+
const commentStr = 'variable:ignore';
|
188
|
+
const prevNode = rule.nodes[position - 1];
|
189
|
+
const fromPath = rootOriginal.source.input.from; // this will be problem for linux and mac use require('path').sep
|
190
|
+
// split not need use slice and lastIndexOf less memory
|
191
|
+
|
192
|
+
const filename = fromPath.split(path.sep).pop();
|
193
|
+
|
194
|
+
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase().includes(commentStr)) {
|
195
|
+
let errObj = {
|
196
|
+
decl,
|
197
|
+
type: 'DECLARATION_IGNORED',
|
198
|
+
filename,
|
199
|
+
message: 'Declaration Ignored',
|
200
|
+
path: fromPath
|
201
|
+
};
|
202
|
+
errHandler.errorTable.push(errObj);
|
203
|
+
errHandler.DECLARATION_IGNORED(errObj);
|
204
|
+
return;
|
205
|
+
}
|
206
|
+
|
207
|
+
if (settingsObject[decl.prop] && !decl.value.includes('var(--')) {
|
208
|
+
const settings = settingsObject[decl.prop]; // console.log(settings)
|
209
|
+
|
210
|
+
const {
|
211
|
+
allowed,
|
212
|
+
range
|
213
|
+
} = settings; // suggestion filter !decl.value.includes('calc')
|
214
|
+
// Reason below some of logic happen based on this
|
215
|
+
|
216
|
+
const unit = decl.value.toString() // no need round braket since you do not need group for less memory
|
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('-',''))
|
218
|
+
// console.log('unit : ');
|
219
|
+
// console.log(unit);
|
220
|
+
|
221
|
+
unit.forEach((val, index) => {
|
222
|
+
allowed.forEach(alwdVal => {
|
223
|
+
if (val.includes(alwdVal)) {
|
224
|
+
// ## for what purpose
|
225
|
+
unit[index] = val // .replace(new RegExp('(\\d+).(\\d+)(\\w+)', 'gi'), '$3')
|
226
|
+
.replace(`-${alwdVal}`, `${alwdVal}`).replace(`-.${alwdVal}`, `${alwdVal}`).replace(`${alwdVal},`, `${alwdVal}`);
|
227
|
+
}
|
228
|
+
});
|
229
|
+
});
|
230
|
+
let unitError = false;
|
231
|
+
let unitErrorVal = '';
|
232
|
+
unit.forEach(val => {
|
233
|
+
if (!val.includes('calc') && decl.prop !== 'clip') {
|
234
|
+
if (!allowed.includes(val.toString())) {
|
235
|
+
unitError = true;
|
236
|
+
unitErrorVal = val;
|
237
|
+
}
|
238
|
+
}
|
239
|
+
}); // console.log(allowed, replacements, range)
|
240
|
+
|
241
|
+
if (!unitError) {
|
242
|
+
// use variable decl.value.split(' ')
|
243
|
+
if (range) {
|
244
|
+
// console.log('multiple :', decl.value)
|
245
|
+
let newVal = '';
|
246
|
+
decl.value.split(' ').forEach(singleVal => {
|
247
|
+
newVal += `${singleConvertor(singleVal, settings.replacements.px, {
|
248
|
+
decl,
|
249
|
+
filename,
|
250
|
+
path: fromPath
|
251
|
+
}, range)} `;
|
252
|
+
});
|
253
|
+
decl.value = newVal;
|
254
|
+
}
|
255
|
+
} else {
|
256
|
+
if (!decl.value.includes('calc')) {
|
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`);
|
258
|
+
let errObj = {
|
259
|
+
decl,
|
260
|
+
filename,
|
261
|
+
unitErrorVal: unitErrorVal,
|
262
|
+
path: fromPath
|
263
|
+
};
|
264
|
+
|
265
|
+
if (unitErrorVal.trim() === '.') {
|
266
|
+
errObj.type = 'DECIMAL_CHECK';
|
267
|
+
errObj.message = `${unitErrorVal} (Decimal Value) Please check`;
|
268
|
+
errHandler.errorTable.push(errObj);
|
269
|
+
errHandler.DECIMAL_CHECK(errObj);
|
270
|
+
} else if (unitErrorVal.includes('.') && !unitErrorVal.includes('%')) {
|
271
|
+
errObj.type = 'DECIMAL_REJECT';
|
272
|
+
errObj.message = `${unitErrorVal} (Decimal Value) Not Allowed \r`;
|
273
|
+
errHandler.errorTable.push(errObj);
|
274
|
+
errHandler.DECIMAL_REJECT(errObj);
|
275
|
+
} else {
|
276
|
+
if (!unitErrorVal.includes('%')) {
|
277
|
+
errObj.type = 'UNIT_ERROR';
|
278
|
+
errObj.message = `${unitErrorVal} (Unit) Not Allowed`;
|
279
|
+
errHandler.errorTable.push(errObj);
|
280
|
+
errHandler.UNIT_ERROR(errObj);
|
281
|
+
}
|
282
|
+
}
|
283
|
+
} else {
|
284
|
+
decl.value = pxToCalc(decl.value);
|
285
|
+
}
|
286
|
+
}
|
287
|
+
} else {
|
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')) {
|
289
|
+
let errObj = {
|
290
|
+
decl,
|
291
|
+
type: 'VARIABLE_PRESENT',
|
292
|
+
filename,
|
293
|
+
message: `value (${decl.value}) has var in it, kindly check`,
|
294
|
+
path: fromPath
|
295
|
+
};
|
296
|
+
errHandler.errorTable.push(errObj);
|
297
|
+
errHandler.VARIABLE_PRESENT(errObj);
|
298
|
+
}
|
299
|
+
}
|
300
|
+
});
|
301
|
+
});
|
302
|
+
};
|
303
|
+
}),
|
304
|
+
errors: errHandler.errors,
|
305
|
+
errTable: errHandler.errorTable,
|
306
|
+
errHandler
|
307
|
+
};
|
@@ -0,0 +1,244 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const postcss = require('postcss');
|
4
|
+
|
5
|
+
const path = require('path');
|
6
|
+
|
7
|
+
const fs = require('fs');
|
8
|
+
|
9
|
+
function populateArray(start, end) {
|
10
|
+
let temp = [];
|
11
|
+
|
12
|
+
for (var i = start; i < end; i++) {
|
13
|
+
temp.push(i);
|
14
|
+
}
|
15
|
+
|
16
|
+
return temp;
|
17
|
+
}
|
18
|
+
|
19
|
+
let allwdVars = {
|
20
|
+
'font-size': ['px', 'em']
|
21
|
+
};
|
22
|
+
let numberObject = {
|
23
|
+
'font-size': {
|
24
|
+
allowed: ['px', 'em'],
|
25
|
+
replacements: {
|
26
|
+
px: 'var(--zd_font_size$$)',
|
27
|
+
em: 'var(--zd_font_size$$em)'
|
28
|
+
},
|
29
|
+
//[5,10,15,20,25],
|
30
|
+
available: populateArray(0, 251),
|
31
|
+
replacementValues: {
|
32
|
+
px: [],
|
33
|
+
em: []
|
34
|
+
}
|
35
|
+
},
|
36
|
+
'margin': {
|
37
|
+
allowed: ['px'],
|
38
|
+
replacements: {
|
39
|
+
px: 'var(--zd_size$$)'
|
40
|
+
},
|
41
|
+
available: populateArray(-250, 251),
|
42
|
+
replacementValues: {
|
43
|
+
px: []
|
44
|
+
}
|
45
|
+
},
|
46
|
+
'margin-left': {
|
47
|
+
allowed: ['px'],
|
48
|
+
replacements: {
|
49
|
+
px: 'var(--zd_size$$)'
|
50
|
+
},
|
51
|
+
available: populateArray(-250, 251),
|
52
|
+
replacementValues: {
|
53
|
+
px: []
|
54
|
+
}
|
55
|
+
},
|
56
|
+
'margin-right': {
|
57
|
+
allowed: ['px'],
|
58
|
+
replacements: {
|
59
|
+
px: 'var(--zd_size$$)'
|
60
|
+
},
|
61
|
+
available: populateArray(-250, 251),
|
62
|
+
replacementValues: {
|
63
|
+
px: []
|
64
|
+
}
|
65
|
+
},
|
66
|
+
'margin-top': {
|
67
|
+
allowed: ['px'],
|
68
|
+
replacements: {
|
69
|
+
px: 'var(--zd_size$$)'
|
70
|
+
},
|
71
|
+
available: populateArray(-250, 251),
|
72
|
+
replacementValues: {
|
73
|
+
px: []
|
74
|
+
}
|
75
|
+
},
|
76
|
+
'margin-bottom': {
|
77
|
+
allowed: ['px'],
|
78
|
+
replacements: {
|
79
|
+
px: 'var(--zd_size$$)'
|
80
|
+
},
|
81
|
+
available: populateArray(-250, 251),
|
82
|
+
replacementValues: {
|
83
|
+
px: []
|
84
|
+
}
|
85
|
+
}
|
86
|
+
};
|
87
|
+
|
88
|
+
function hasIgnoreComment(node) {
|
89
|
+
return node ? node.type == 'comment' ? node.text == 'Variable:Ignore' ? true : false : false : false;
|
90
|
+
}
|
91
|
+
|
92
|
+
let errors = [];
|
93
|
+
module.exports = postcss.plugin('postcss-variable-report', () => rootOriginal => {
|
94
|
+
// console.log('inside postcss plugin')
|
95
|
+
// fs.writeFile('./css_error.log', '\r\nLog File: \r\n\r\n', (err) => {
|
96
|
+
// if(err)console.log(err);
|
97
|
+
// });
|
98
|
+
// console.log(rootOriginal.source.input.file);
|
99
|
+
if (!rootOriginal.source.input.file.includes('css_error')) {
|
100
|
+
rootOriginal.walkRules(rule => {
|
101
|
+
rule.walkDecls((decl, position) => {
|
102
|
+
// case font-size
|
103
|
+
if (!hasIgnoreComment(rule.nodes[position - 1])) {
|
104
|
+
console.log(settings);
|
105
|
+
let unit = decl.value.replace(/[0-9]/g, '');
|
106
|
+
let settings = numberObject[decl.prop];
|
107
|
+
let path = rootOriginal.source.input.from;
|
108
|
+
let filename = path.split('\\');
|
109
|
+
filename = filename[filename.length - 1];
|
110
|
+
|
111
|
+
if (decl.prop === 'font-size' || decl.prop === 'margin-left' || decl.prop === 'margin-right' || decl.prop === 'margin-top' || decl.prop === 'margin-bottom') {
|
112
|
+
let {
|
113
|
+
allowed,
|
114
|
+
replacements,
|
115
|
+
available
|
116
|
+
} = settings;
|
117
|
+
|
118
|
+
if (!rootOriginal.source.input.from.includes('node_modules')) {
|
119
|
+
if (unit != 0) {
|
120
|
+
if (allowed.includes(unit)) {
|
121
|
+
// console.log(available, parseInt(decl.value))
|
122
|
+
if (available.includes(parseInt(decl.value))) {
|
123
|
+
// replacementValues[unit].push({[decl.value] : replacements[unit].replace('$$', parseInt(decl.value))})
|
124
|
+
decl.value = replacements[unit].replace('$$', parseInt(decl.value)); //console.log("replacements:")
|
125
|
+
} else {
|
126
|
+
let err = {
|
127
|
+
prop: decl.prop,
|
128
|
+
value: decl.value,
|
129
|
+
filename,
|
130
|
+
filepath: rootOriginal.source.input.from,
|
131
|
+
line: decl.source.start.line,
|
132
|
+
unit,
|
133
|
+
message: 'value not available consider others'
|
134
|
+
};
|
135
|
+
errors.push(err);
|
136
|
+
}
|
137
|
+
} else {
|
138
|
+
let err = {
|
139
|
+
prop: decl.prop,
|
140
|
+
value: decl.value,
|
141
|
+
filename,
|
142
|
+
filepath: rootOriginal.source.input.from,
|
143
|
+
line: decl.source.start.line,
|
144
|
+
unit,
|
145
|
+
message: 'Unit not supported'
|
146
|
+
};
|
147
|
+
errors.push(err);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
} else if (decl.prop === 'margin') {
|
152
|
+
let {
|
153
|
+
allowed,
|
154
|
+
replacements,
|
155
|
+
available
|
156
|
+
} = settings; //console.log(decl.prop + " " + decl.value)
|
157
|
+
|
158
|
+
let valArr = decl.value.split(' '); //console.log(valArr)
|
159
|
+
//console.log(allowed, replacements, available)
|
160
|
+
|
161
|
+
let hasError = false;
|
162
|
+
let newVal = '';
|
163
|
+
valArr.forEach(val => {
|
164
|
+
let unit = val.replace(parseInt(val), '');
|
165
|
+
let numVal = parseInt(val);
|
166
|
+
|
167
|
+
if (unit != 0) {
|
168
|
+
if (allowed.includes(unit)) {
|
169
|
+
if (available.includes(numVal)) {
|
170
|
+
if (numVal >= 0) {
|
171
|
+
if (!hasError) {
|
172
|
+
newVal += replacements[unit].replace('$$', numVal) + " ";
|
173
|
+
}
|
174
|
+
} else {
|
175
|
+
if (!hasError) {
|
176
|
+
newVal += `calc(${replacements[unit].replace('$$', numVal * -1)} * -1)` + " ";
|
177
|
+
}
|
178
|
+
}
|
179
|
+
} else {
|
180
|
+
hasError = true;
|
181
|
+
let err = {
|
182
|
+
prop: decl.prop,
|
183
|
+
value: numVal,
|
184
|
+
filename,
|
185
|
+
filepath: rootOriginal.source.input.from,
|
186
|
+
line: decl.source.start.line,
|
187
|
+
unit,
|
188
|
+
message: 'value not available consider others'
|
189
|
+
};
|
190
|
+
errors.push(err);
|
191
|
+
}
|
192
|
+
} else {
|
193
|
+
hasError = true;
|
194
|
+
let err = {
|
195
|
+
prop: decl.prop,
|
196
|
+
value: decl.value,
|
197
|
+
filename,
|
198
|
+
filepath: rootOriginal.source.input.from,
|
199
|
+
line: decl.source.start.line,
|
200
|
+
unit,
|
201
|
+
message: 'Unit not supported'
|
202
|
+
};
|
203
|
+
errors.push(err);
|
204
|
+
}
|
205
|
+
}
|
206
|
+
});
|
207
|
+
|
208
|
+
if (!hasError) {
|
209
|
+
decl.value = newVal;
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
});
|
214
|
+
}); //fs.writeFile('./src/trial.json', JSON.stringify(variables) ,(err) =>{
|
215
|
+
// if(err)console.log(err);
|
216
|
+
// else{
|
217
|
+
// console.log('updated successfully');
|
218
|
+
// }
|
219
|
+
// })
|
220
|
+
// console.log(errors)
|
221
|
+
|
222
|
+
let errorArr = [];
|
223
|
+
errors.forEach(errStr => {
|
224
|
+
errorArr.push(` prop: ${errStr.prop} ,\n value : ${errStr.value} ,\n filename : ${errStr.filename} ,\n filepath : ${errStr.filepath} ,\n line : ${errStr.line} ,\n unit : ${errStr.unit} ,\n message : ${errStr.message} \r`);
|
225
|
+
}); //fs.writeFile('./css_error.log','', (err) =>{
|
226
|
+
// if(err){
|
227
|
+
// console.log(err);
|
228
|
+
// }
|
229
|
+
//});
|
230
|
+
// errorArr.forEach(err => {
|
231
|
+
// let data = `\n{\n${err}\n},\n`;
|
232
|
+
// //fs.appendFile('./css_error.log',data,(err)=>{
|
233
|
+
// // if(err){
|
234
|
+
// // console.log(err);
|
235
|
+
// // }
|
236
|
+
// //})
|
237
|
+
// });
|
238
|
+
// fs.writeFileSync('./css_error.log','');
|
239
|
+
// errorArr.forEach(err => {
|
240
|
+
// let data = `\n{\n${err}\n},\n`;
|
241
|
+
// fs.appendFileSync('./css_error.log',data);
|
242
|
+
// });
|
243
|
+
}
|
244
|
+
});
|