@zohodesk/react-cli 0.0.1-beta.171 → 0.0.1-beta.173
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/README.md +25 -1
- package/docs/VariableConversion.md +678 -0
- package/lib/configs/webpack.dev.config.js +12 -11
- package/lib/configs/webpack.docs.config.js +5 -4
- package/lib/configs/webpack.impact.config.js +5 -4
- package/lib/configs/webpack.prod.config.js +13 -12
- package/lib/loaderUtils/getCSSLoaders.js +22 -10
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +37 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +247 -0
- package/lib/postcss-plugins/variableModifier.js +1 -0
- package/lib/schemas/index.js +17 -4
- package/lib/utils/getOptions.js +29 -1
- package/package.json +1 -1
@@ -16,8 +16,8 @@ var _configsAssetsLoaders = require("../loaderUtils/configsAssetsLoaders");
|
|
16
16
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
const options = (0, _utils.getOptions)();
|
20
|
+
const {
|
21
21
|
unstableDepsInverse,
|
22
22
|
app: {
|
23
23
|
folder,
|
@@ -27,6 +27,7 @@ let {
|
|
27
27
|
plugins,
|
28
28
|
exclude,
|
29
29
|
mediaQueryHoverActiveString,
|
30
|
+
cssVariableReplacementConfig,
|
30
31
|
cssUniqueness,
|
31
32
|
seperateCssModules,
|
32
33
|
changeRuntimeChunkChar,
|
@@ -41,13 +42,13 @@ let {
|
|
41
42
|
crossorigin
|
42
43
|
}
|
43
44
|
} = options;
|
44
|
-
|
45
|
+
const {
|
45
46
|
disableContextURL
|
46
47
|
} = server;
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
const appPath = process.cwd();
|
49
|
+
const contextURL = disableContextURL ? '' : context;
|
50
|
+
const serverUrl = (0, _utils.getServerURL)(server, 'https');
|
51
|
+
const output = {
|
51
52
|
path: _path.default.join(appPath, outputFolder),
|
52
53
|
filename: 'js/[name].js',
|
53
54
|
chunkFilename: 'js/[name].js',
|
@@ -86,9 +87,9 @@ module.exports = {
|
|
86
87
|
test: /\.js$/,
|
87
88
|
use: (0, _loaderUtils.getDevJsLoaders)(options),
|
88
89
|
include: module => {
|
89
|
-
|
90
|
+
const srcPath = _path.default.join(appPath, folder);
|
90
91
|
|
91
|
-
|
92
|
+
const depsPath = _path.default.join(appPath, 'node_modules', '@zohodesk');
|
92
93
|
|
93
94
|
if (module.includes(srcPath) || devConsoleExculde && module.includes(depsPath)) {
|
94
95
|
return true;
|
@@ -99,10 +100,10 @@ module.exports = {
|
|
99
100
|
}, seperateCssModules ? {
|
100
101
|
test: /\.css$/,
|
101
102
|
exclude: /\.module\.css$/,
|
102
|
-
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, '[local]', false, null)
|
103
|
+
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, cssVariableReplacementConfig, '[local]', false, null)
|
103
104
|
} : null, {
|
104
105
|
test: seperateCssModules ? /\.module\.css$/ : /(\.module)?\.css$/,
|
105
|
-
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, null, cssUniqueness, selectorReplace, cssHashSelectors, classNamePrefix)
|
106
|
+
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, cssVariableReplacementConfig, null, cssUniqueness, selectorReplace, cssHashSelectors, classNamePrefix)
|
106
107
|
}, (0, _configsAssetsLoaders.configImageLoader)(nameTemplate), (0, _configsAssetsLoaders.configFontLoader)(nameTemplate), (0, _configsAssetsLoaders.configSVGLoader)(nameTemplate), (0, _configsAssetsLoaders.configVideoLoader)(nameTemplate), (0, _configsAssetsLoaders.configAudioLoader)(nameTemplate), {
|
107
108
|
test: /\.tmpl$/,
|
108
109
|
use: [{
|
@@ -14,8 +14,8 @@ var _configsAssetsLoaders = require("../loaderUtils/configsAssetsLoaders");
|
|
14
14
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
const options = (0, _utils.getOptions)();
|
18
|
+
const {
|
19
19
|
unstableDepsInverse,
|
20
20
|
docs: {
|
21
21
|
componentFolder,
|
@@ -25,6 +25,7 @@ let {
|
|
25
25
|
plugins,
|
26
26
|
exclude,
|
27
27
|
mediaQueryHoverActiveString,
|
28
|
+
cssVariableReplacementConfig,
|
28
29
|
cssHashSelectors,
|
29
30
|
classNamePrefix
|
30
31
|
},
|
@@ -32,7 +33,7 @@ let {
|
|
32
33
|
folder
|
33
34
|
}
|
34
35
|
} = options;
|
35
|
-
|
36
|
+
const appPath = process.cwd();
|
36
37
|
const nameTemplate = (0, _configsAssetsLoaders.createNameTemplate)(enableChunkHash);
|
37
38
|
|
38
39
|
module.exports = isSSTest => ({
|
@@ -74,7 +75,7 @@ module.exports = isSSTest => ({
|
|
74
75
|
exclude: /node_modules/
|
75
76
|
}, {
|
76
77
|
test: /(\.module)?\.css$/,
|
77
|
-
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, false, cssUniqueness, null, cssHashSelectors, classNamePrefix)
|
78
|
+
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, cssVariableReplacementConfig, false, cssUniqueness, null, cssHashSelectors, classNamePrefix)
|
78
79
|
}, (0, _configsAssetsLoaders.configImageLoader)(nameTemplate), (0, _configsAssetsLoaders.configFontLoader)(nameTemplate), (0, _configsAssetsLoaders.configSVGLoader)(nameTemplate), (0, _configsAssetsLoaders.configAudioLoader)(nameTemplate), (0, _configsAssetsLoaders.configVideoLoader)(nameTemplate), {
|
79
80
|
test: /\.html$/,
|
80
81
|
use: {
|
@@ -12,14 +12,15 @@ var _configsAssetsLoaders = require("../loaderUtils/configsAssetsLoaders");
|
|
12
12
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
const options = (0, _utils.getOptions)();
|
16
|
+
const {
|
17
17
|
docs: {
|
18
18
|
componentFolder,
|
19
19
|
cssUniqueness,
|
20
20
|
plugins,
|
21
21
|
exclude,
|
22
22
|
mediaQueryHoverActiveString,
|
23
|
+
cssVariableReplacementConfig,
|
23
24
|
cssHashSelectors,
|
24
25
|
enableChunkHash,
|
25
26
|
classNamePrefix
|
@@ -28,7 +29,7 @@ let {
|
|
28
29
|
folder
|
29
30
|
}
|
30
31
|
} = options;
|
31
|
-
|
32
|
+
const appPath = process.cwd();
|
32
33
|
const nameTemplate = (0, _configsAssetsLoaders.createNameTemplate)(enableChunkHash);
|
33
34
|
module.exports = {
|
34
35
|
entry: {
|
@@ -69,7 +70,7 @@ module.exports = {
|
|
69
70
|
exclude: /node_modules/
|
70
71
|
}, {
|
71
72
|
test: /(\.module)?\.css$/,
|
72
|
-
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, false, cssUniqueness, null, cssHashSelectors, classNamePrefix)
|
73
|
+
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, cssVariableReplacementConfig, false, cssUniqueness, null, cssHashSelectors, classNamePrefix)
|
73
74
|
}, (0, _configsAssetsLoaders.configImageLoader)(nameTemplate), (0, _configsAssetsLoaders.configFontLoader)(nameTemplate), (0, _configsAssetsLoaders.configSVGLoader)(nameTemplate), (0, _configsAssetsLoaders.configAudioLoader)(nameTemplate), (0, _configsAssetsLoaders.configVideoLoader)(nameTemplate), {
|
74
75
|
test: /\.html$/,
|
75
76
|
use: {
|
@@ -17,7 +17,7 @@ var _configsAssetsLoaders = require("../loaderUtils/configsAssetsLoaders");
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
18
|
|
19
19
|
// import TerserPlugin from 'terser-webpack-plugin';
|
20
|
-
|
20
|
+
const options = (0, _utils.getOptions)();
|
21
21
|
let {
|
22
22
|
unstableDepsInverse,
|
23
23
|
app: {
|
@@ -32,6 +32,7 @@ let {
|
|
32
32
|
plugins,
|
33
33
|
exclude,
|
34
34
|
mediaQueryHoverActiveString,
|
35
|
+
cssVariableReplacementConfig,
|
35
36
|
cssUniqueness,
|
36
37
|
server: {
|
37
38
|
mode
|
@@ -46,10 +47,10 @@ let {
|
|
46
47
|
crossorigin
|
47
48
|
}
|
48
49
|
} = options;
|
49
|
-
|
50
|
-
|
50
|
+
const appPath = process.cwd();
|
51
|
+
const isDevelopment = mode === 'prod' || mode === 'dev' || mode === 'dev-no-warn';
|
51
52
|
enableChunkHash = !isDevelopment && enableChunkHash;
|
52
|
-
|
53
|
+
const output = {
|
53
54
|
path: _path.default.resolve(appPath, outputFolder),
|
54
55
|
filename: enableChunkHash ? 'js/[name].[chunkhash:20]_.js' : 'js/[name]_.js',
|
55
56
|
chunkFilename: enableChunkHash ? 'js/[name].[chunkhash:20]_.js' : 'js/[name]_.js',
|
@@ -62,15 +63,15 @@ if (crossorigin) {
|
|
62
63
|
}
|
63
64
|
|
64
65
|
if (isDevelopment) {
|
65
|
-
|
66
|
+
const {
|
66
67
|
disableContextURL
|
67
68
|
} = server;
|
68
|
-
|
69
|
-
|
69
|
+
const contextURL = disableContextURL ? '' : context;
|
70
|
+
const serverUrl = (0, _utils.getServerURL)(server, 'https');
|
70
71
|
output.publicPath = `${[serverUrl, contextURL].filter(a => a).join('/')}/`;
|
71
72
|
}
|
72
73
|
|
73
|
-
|
74
|
+
const shouldRemovePropTypes = !isDevelopment && removePropTypes;
|
74
75
|
module.exports = {
|
75
76
|
entry: (0, _common.getEntries)(options, 'production'),
|
76
77
|
devtool: isDevelopment ? 'cheap-module-source-map' : enableSMap ? 'hidden-source-map' : 'none',
|
@@ -134,9 +135,9 @@ module.exports = {
|
|
134
135
|
}].filter(Boolean),
|
135
136
|
// include: path.join(appPath, folder)
|
136
137
|
include: module => {
|
137
|
-
|
138
|
+
const srcPath = _path.default.join(appPath, folder);
|
138
139
|
|
139
|
-
|
140
|
+
const depsPath = _path.default.join(appPath, 'node_modules', '@zohodesk');
|
140
141
|
|
141
142
|
if (module.includes(srcPath) || devConsoleExculde && module.includes(depsPath)) {
|
142
143
|
return true;
|
@@ -147,10 +148,10 @@ module.exports = {
|
|
147
148
|
}, seperateCssModules ? {
|
148
149
|
test: /\.css$/,
|
149
150
|
exclude: /\.module\.css$/,
|
150
|
-
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, '[local]', false, null)
|
151
|
+
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, cssVariableReplacementConfig, mediaQueryHoverActiveString, '[local]', false, null)
|
151
152
|
} : null, {
|
152
153
|
test: seperateCssModules ? /\.module\.css$/ : /\.css$/,
|
153
|
-
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, false, cssUniqueness, selectorReplace, cssHashSelectors, classNamePrefix)
|
154
|
+
use: (0, _loaderUtils.getCSSLoaders)(plugins, exclude, mediaQueryHoverActiveString, cssVariableReplacementConfig, false, cssUniqueness, selectorReplace, cssHashSelectors, classNamePrefix)
|
154
155
|
}, {
|
155
156
|
test: /\.jpe?g$|\.gif$|\.png$/,
|
156
157
|
use: [{
|
@@ -13,8 +13,10 @@ var _utils = require("../utils");
|
|
13
13
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
const fs = require('fs');
|
17
|
+
|
18
|
+
const options = (0, _utils.getOptions)();
|
19
|
+
const isWin = process.platform === 'win32';
|
18
20
|
|
19
21
|
function windowsModification(array) {
|
20
22
|
return isWin ? array.map(r => r.replace(/\//g, '\\')) : array;
|
@@ -31,7 +33,7 @@ function excludeEmptyCheckPlugin({
|
|
31
33
|
})] : [];
|
32
34
|
}
|
33
35
|
|
34
|
-
|
36
|
+
const getCSSLoaders = (plugins, exclude, mediaQueryHoverActiveString, cssVariableReplacementConfig, classNameBlob, cssUniqueness, selectorReplace, cssHashSelectors, classNamePrefix) => {
|
35
37
|
// console.log('plugins:')
|
36
38
|
// console.log(plugins)
|
37
39
|
// console.log('exclude:')
|
@@ -45,10 +47,12 @@ let getCSSLoaders = (plugins, exclude, mediaQueryHoverActiveString, classNameBlo
|
|
45
47
|
const {
|
46
48
|
cssSelectorZipPath
|
47
49
|
} = options.impactService;
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
fs.writeFileSync('./css_error.log', '');
|
51
|
+
const rtlExcludeLocal = windowsModification(exclude.rtl);
|
52
|
+
const hoverActiveExcludeLocal = windowsModification(exclude.hoverActive);
|
53
|
+
const combinerMediaQueryExcludeLocal = windowsModification(exclude.combinerMediaQuery);
|
54
|
+
const cssVariableReplacementExcludeLocal = windowsModification(exclude.cssVariableReplacement);
|
55
|
+
const cssLoaderOptions = {
|
52
56
|
// importLoaders: hasRTL||hoverActive ? 1 : 0,
|
53
57
|
importLoaders: 1,
|
54
58
|
modules: {},
|
@@ -61,7 +65,12 @@ let getCSSLoaders = (plugins, exclude, mediaQueryHoverActiveString, classNameBlo
|
|
61
65
|
cssLoaderOptions.modules.getLocalIdent = (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix);
|
62
66
|
}
|
63
67
|
|
64
|
-
const postcssPlugins = [valueReplacer && require('../postcss-plugins/ValueReplacer')(valueReplacer), selectorReplace && require('postcss-selector-replace')(selectorReplace), ...excludeEmptyCheckPlugin({
|
68
|
+
const postcssPlugins = [valueReplacer && require('../postcss-plugins/ValueReplacer')(valueReplacer), selectorReplace && require('postcss-selector-replace')(selectorReplace), // ...excludeEmptyCheckPlugin({
|
69
|
+
// enable: true,
|
70
|
+
// ignore: [],
|
71
|
+
// plugins: [require('../postcss-plugins/variablePropertiesCollector').default()]
|
72
|
+
// }),
|
73
|
+
...excludeEmptyCheckPlugin({
|
65
74
|
enable: plugins.hasRTL,
|
66
75
|
ignore: rtlExcludeLocal,
|
67
76
|
plugins: [require('@zohodesk/postcss-rtl')({
|
@@ -81,8 +90,11 @@ let getCSSLoaders = (plugins, exclude, mediaQueryHoverActiveString, classNameBlo
|
|
81
90
|
enable: plugins.hoverActive,
|
82
91
|
ignore: hoverActiveExcludeLocal,
|
83
92
|
plugins: [require('../postcss-plugins/hoverActivePlugin')(mediaQueryHoverActiveString)]
|
84
|
-
})
|
85
|
-
|
93
|
+
}), ...excludeEmptyCheckPlugin({
|
94
|
+
enable: plugins.cssVariableReplacement,
|
95
|
+
ignore: cssVariableReplacementExcludeLocal,
|
96
|
+
plugins: [require('../postcss-plugins/variableModificationPlugin/index')(cssVariableReplacementConfig)]
|
97
|
+
})].filter(Boolean);
|
86
98
|
return [cssSelectorZipPath && {
|
87
99
|
loader: require.resolve('../loaders/selectorMappingLoader')
|
88
100
|
}, {
|
@@ -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+')}|`;
|
138
|
+
} else {
|
139
|
+
regValStr += `${val.replace('$$', '\\d+')}`;
|
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
|
+
});
|
@@ -101,6 +101,7 @@ module.exports = postcss.plugin('postcss-variable-report', () => rootOriginal =>
|
|
101
101
|
rule.walkDecls((decl, position) => {
|
102
102
|
// case font-size
|
103
103
|
if (!hasIgnoreComment(rule.nodes[position - 1])) {
|
104
|
+
console.log(settings);
|
104
105
|
let unit = decl.value.replace(/[0-9]/g, '');
|
105
106
|
let settings = numberObject[decl.prop];
|
106
107
|
let path = rootOriginal.source.input.from;
|
package/lib/schemas/index.js
CHANGED
@@ -13,6 +13,7 @@ var _getCurrentBranch = _interopRequireDefault(require("../utils/getCurrentBranc
|
|
13
13
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
15
|
|
16
|
+
// TODO move deprecated options to separate file and manage seperately
|
16
17
|
var _default = {
|
17
18
|
cliRootPath: null,
|
18
19
|
unstableDepsInverse: {
|
@@ -197,6 +198,9 @@ var _default = {
|
|
197
198
|
cli: 'attr_name'
|
198
199
|
},
|
199
200
|
publicPaths: false,
|
201
|
+
// TODO: Deprecated
|
202
|
+
hasRTL: false,
|
203
|
+
rtlExclude: [],
|
200
204
|
instrumentScript: {
|
201
205
|
value: false,
|
202
206
|
cli: 'instru_script'
|
@@ -212,13 +216,16 @@ var _default = {
|
|
212
216
|
plugins: {
|
213
217
|
hasRTL: false,
|
214
218
|
hoverActive: false,
|
215
|
-
combinerMediaQuery: false
|
219
|
+
combinerMediaQuery: false,
|
220
|
+
cssVariableReplacement: false
|
216
221
|
},
|
217
222
|
exclude: {
|
218
223
|
rtl: [],
|
219
224
|
hoverActive: [],
|
220
|
-
combinerMediaQuery: []
|
225
|
+
combinerMediaQuery: [],
|
226
|
+
cssVariableReplacement: []
|
221
227
|
},
|
228
|
+
cssVariableReplacementConfig: '',
|
222
229
|
seperateCssModules: {
|
223
230
|
value: false,
|
224
231
|
cli: 'sep_cssmodules'
|
@@ -292,16 +299,22 @@ var _default = {
|
|
292
299
|
enableChunkHash: false,
|
293
300
|
folder: 'src',
|
294
301
|
disableES5Transpile: false,
|
302
|
+
// TODO: Deprecated
|
303
|
+
hasRTL: false,
|
304
|
+
rtlExclude: [],
|
295
305
|
plugins: {
|
296
306
|
hasRTL: false,
|
297
307
|
hoverActive: false,
|
298
|
-
combinerMediaQuery: false
|
308
|
+
combinerMediaQuery: false,
|
309
|
+
cssVariableReplacement: false
|
299
310
|
},
|
300
311
|
exclude: {
|
301
312
|
rtl: [],
|
302
313
|
hoverActive: [],
|
303
|
-
combinerMediaQuery: []
|
314
|
+
combinerMediaQuery: [],
|
315
|
+
cssVariableReplacement: []
|
304
316
|
},
|
317
|
+
cssVariableReplacementConfig: '',
|
305
318
|
cssHashSelectors: {
|
306
319
|
filenames: [],
|
307
320
|
packages: []
|
package/lib/utils/getOptions.js
CHANGED
@@ -122,7 +122,34 @@ let defaulter = (target, source) => {
|
|
122
122
|
return defaultObject;
|
123
123
|
};
|
124
124
|
|
125
|
-
global.reactCLIOptions = null;
|
125
|
+
global.reactCLIOptions = null; // function selectn(obj, key) {
|
126
|
+
// let temp = obj;
|
127
|
+
// let keys = key.split('.');
|
128
|
+
// for (let i = 0; i < keys.length; i++) {
|
129
|
+
// const element = keys[i];
|
130
|
+
// temp = temp && temp[element];
|
131
|
+
// }
|
132
|
+
// return temp;
|
133
|
+
// }
|
134
|
+
|
135
|
+
function deprecationSupport(options) {
|
136
|
+
// if (selectn(options, ".app.hasRTL") === true) {
|
137
|
+
if (options.app.hasRTL === true) {
|
138
|
+
options.app.plugins.hasRTL = true;
|
139
|
+
}
|
140
|
+
|
141
|
+
if (options.docs.hasRTL === true) {
|
142
|
+
options.docs.plugins.hasRTL = true;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (options.app.rtlExclude.length > 0) {
|
146
|
+
options.app.exclude.rtl = options.app.rtlExclude;
|
147
|
+
}
|
148
|
+
|
149
|
+
if (options.docs.rtlExclude.length > 0) {
|
150
|
+
options.docs.exclude.rtl = options.docs.rtlExclude;
|
151
|
+
}
|
152
|
+
}
|
126
153
|
|
127
154
|
let getOptions = () => {
|
128
155
|
if (global.reactCLIOptions) {
|
@@ -142,6 +169,7 @@ let getOptions = () => {
|
|
142
169
|
|
143
170
|
options.npmVersion = getNpmVersion();
|
144
171
|
options.cwd = getCWD();
|
172
|
+
deprecationSupport(options);
|
145
173
|
options.packageVersion = process.env.npm_package_version;
|
146
174
|
global.reactCLIOptions = options;
|
147
175
|
return options;
|