@zohodesk/react-cli 1.0.3 → 1.1.1
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 +26 -1
- package/bin/cli.js +18 -4
- package/docs/ComposeMinification.md +13 -0
- package/docs/ReactLive.md +10 -0
- package/docs/patternFiltering.md +57 -0
- package/lib/common/buildEs.js +12 -0
- package/lib/configs/webpack.dev.config.js +3 -0
- package/lib/configs/webpack.docs.config.js +8 -1
- package/lib/configs/webpack.impact.config.js +2 -0
- package/lib/configs/webpack.prod.config.js +3 -0
- package/lib/loaderUtils/getCSSLoaders.js +77 -46
- package/lib/loaderUtils/tests/windowsModification.test.js +10 -0
- package/lib/loaderUtils/windowsModification.js +6 -1
- package/lib/loaders/composeLoader.js +172 -0
- package/lib/loaders/docsLoader.js +15 -7
- package/lib/loaders/reactLiveConvertor.js +105 -0
- package/lib/pluginUtils/getDevPlugins.js +10 -3
- package/lib/pluginUtils/getProdPlugins.js +8 -3
- package/lib/pluginUtils/getUMDCSSPlugins.js +1 -1
- package/lib/pluginUtils/getUMDComponentPlugins.js +1 -1
- package/lib/plugins/{UglifyCSSPlugin.js → MinifyPlugin.js} +3 -3
- package/lib/plugins/SelectorPlugin.js +63 -40
- package/lib/plugins/VariableConversionCollector.js +40 -97
- package/lib/plugins/index.js +7 -7
- package/lib/plugins/utils/classHandling.js +35 -0
- package/lib/plugins/utils/fileHandling.js +107 -0
- package/lib/plugins/utils/tests/fileHandling.test.js +30 -0
- package/lib/plugins/variableConvertorUtils.js +131 -0
- package/lib/postcss-plugins/EmptyPlugin.js +8 -0
- package/lib/postcss-plugins/ExcludePlugin.js +1 -1
- package/lib/postcss-plugins/ValueReplacer.js +5 -14
- package/lib/postcss-plugins/variableModificationPlugin/index.js +2 -19
- package/lib/schemas/index.js +75 -4
- package/lib/servers/server.js +2 -2
- package/lib/utils/cssClassNameGenerate.js +34 -9
- package/lib/utils/getOptions.js +45 -0
- package/lib/utils/selectorReplacer.js +47 -0
- package/lib/utils/variableConverter.js +89 -0
- package/{package-lock.json → npm-shrinkwrap.json} +79 -74
- package/package.json +3 -1
- package/lib/plugins/composeCommonPlugin.js +0 -30
- package/lib/postcss-plugins/variableModifier.js +0 -210
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.hasPrevNodeIgnore = hasPrevNodeIgnore;
|
7
|
+
exports.isAtRule = isAtRule;
|
8
|
+
exports.isComment = isComment;
|
9
|
+
exports.isCommentContentSame = isCommentContentSame;
|
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
|
+
}
|
24
|
+
|
25
|
+
function hasPrevNodeIgnore(index, prevNode, ignoreComment) {
|
26
|
+
return index !== 0 && isThisComment(prevNode, ignoreComment);
|
27
|
+
}
|
28
|
+
|
29
|
+
function isAtRule(rule) {
|
30
|
+
return rule.parent && rule.parent.type === 'atrule';
|
31
|
+
}
|
32
|
+
|
33
|
+
function isInsideMediaQuery(rule) {
|
34
|
+
return isAtRule(rule) && rule.parent && rule.parent.name === 'media' ? true : false;
|
35
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.isFileNameMatchingPattern = isFileNameMatchingPattern;
|
7
|
+
exports.isFileNameMatchingPluginPattern = isFileNameMatchingPluginPattern;
|
8
|
+
|
9
|
+
var _windowsModification = require("../../loaderUtils/windowsModification");
|
10
|
+
|
11
|
+
var _ignore = _interopRequireDefault(require("ignore"));
|
12
|
+
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
|
+
|
15
|
+
const path = require('path');
|
16
|
+
|
17
|
+
let aliasNames = {
|
18
|
+
valueReplacer: 'postcss-value-replacer',
|
19
|
+
selectorReplace: 'postcss-selector-replace-new',
|
20
|
+
hasRTL: 'postcss-rtl',
|
21
|
+
combinerMediaQuery: 'postcss-combine-media-query',
|
22
|
+
hoverActive: 'postcss-mobile-hover',
|
23
|
+
cssVariableReplacement: 'postcss-variable-report',
|
24
|
+
composeMinification: 'postcss-compose-plugin'
|
25
|
+
};
|
26
|
+
/*
|
27
|
+
|
28
|
+
unique scenario
|
29
|
+
|
30
|
+
*/
|
31
|
+
// export function filterFileCssUniqueness(filename, filterObj) {
|
32
|
+
// let rootDir = 'supportapp';
|
33
|
+
// let include = false;
|
34
|
+
// const regex = `^(.+?)${rootDir}?\\\\`;
|
35
|
+
// const newFilename = windowsModificationFile(filename).replace(
|
36
|
+
// new RegExp(regex, 'gi'),
|
37
|
+
// ''
|
38
|
+
// );
|
39
|
+
// Object.keys(filterObj).forEach(key => {
|
40
|
+
// const ig = ignore().add(filterObj[key]);
|
41
|
+
// if (ig.ignores(newFilename)) {
|
42
|
+
// include = true;
|
43
|
+
// }
|
44
|
+
// });
|
45
|
+
// return include;
|
46
|
+
// }
|
47
|
+
|
48
|
+
function isFileNameMatchingPattern({
|
49
|
+
filename,
|
50
|
+
filterObject,
|
51
|
+
plugins
|
52
|
+
}) {
|
53
|
+
const finalPlugins = []; // console.log(rootDir);
|
54
|
+
// const regex = `^(.+?)${rootDir}?\\\\`;
|
55
|
+
|
56
|
+
const newFilename = path.relative(path.parse(process.cwd()).base, filename); //windowsModificationFile(filename).replace(
|
57
|
+
// new RegExp(regex, 'gi'),
|
58
|
+
// ''
|
59
|
+
// );
|
60
|
+
// path.relative('supportapp', 'd:\')
|
61
|
+
|
62
|
+
Object.keys(filterObject).forEach(key => {
|
63
|
+
plugins.forEach(x => {
|
64
|
+
// console.log(key, x.postcssPlugin);
|
65
|
+
if (aliasNames[key] === x.postcssPlugin) {
|
66
|
+
const ig = (0, _ignore.default)({
|
67
|
+
allowRelativePaths: true
|
68
|
+
}).add(filterObject[key]);
|
69
|
+
|
70
|
+
if (ig.ignores(newFilename)) {
|
71
|
+
// console.log(newFilename);
|
72
|
+
finalPlugins.push(x);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}); // console.log(filename);
|
77
|
+
// console.log(finalPlugins);
|
78
|
+
// console.log('----------------------------------------------------------------------')
|
79
|
+
|
80
|
+
return finalPlugins; // console.log(filename, filterObject);
|
81
|
+
}
|
82
|
+
|
83
|
+
function isFileNameMatchingPluginPattern({
|
84
|
+
filename,
|
85
|
+
filterArr // =process.cwd()
|
86
|
+
|
87
|
+
}) {
|
88
|
+
// console.log(rootDir);
|
89
|
+
let include = true; // console.log(rootDir);
|
90
|
+
// const regex = `^(.+?)${rootDir}?\\\\`;
|
91
|
+
// console.log(plugin);
|
92
|
+
|
93
|
+
const newFilename = path.relative(path.parse(process.cwd()).base, filename); // const newFilename = windowsModificationFile(filename).replace(
|
94
|
+
// new RegExp(regex, 'gi'),
|
95
|
+
// ''
|
96
|
+
// );
|
97
|
+
|
98
|
+
const ig = (0, _ignore.default)({
|
99
|
+
allowRelativePaths: true
|
100
|
+
}).add(filterArr);
|
101
|
+
|
102
|
+
if (!ig.ignores(newFilename)) {
|
103
|
+
include = false;
|
104
|
+
}
|
105
|
+
|
106
|
+
return include;
|
107
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const ignore = require('ignore');
|
4
|
+
|
5
|
+
const ignoreArr1 = ['src', '!src\\components', 'src\\Accessibility'];
|
6
|
+
const ignoreArr2 = ['src\\', '!node_modules\\'];
|
7
|
+
const ignoreArr3 = ['*'];
|
8
|
+
|
9
|
+
const {
|
10
|
+
windowsModificationFile
|
11
|
+
} = require('../../../../lib/loaderUtils/windowsModification');
|
12
|
+
|
13
|
+
const files = ['D:\\MyWork\\React Build\\desk_client_app\\jsapps\\supportapp\\src\\components\\Accessibility\\Accessibility.module.css', 'D:\\MyWork\\React Build\\desk_client_app\\jsapps\\supportapp\\src\\components\\Avatar\\Avatar.module.css', 'D:/MyWork/React Build/desk_client_app/jsapps/supportapp/src/components/Accessibility/Accessibility.module.css', 'D:/MyWork/React Build/desk_client_app/jsapps/supportapp/src/components/Accessibility/AccessibilityNavigation.module.css', 'desk_client_app\\jsapps\\supportapp\\src\\components\\Test.module.css', 'desk_client_app\\jsapps\\supportapp\\src\\components\\Accessibility\\Accessibility.module.css', 'desk_client_app/jsapps/supportapp/src/components/Accessibility/Accessibility.module.css', 'src\\components\\Accessibility\\Accessibility.module.css', 'src/components/Accessibility/Accessibility.module.css', 'Accessibility.module.css', ''];
|
14
|
+
const ignore1 = ignore().add(ignoreArr1);
|
15
|
+
const ignore2 = ignore().add(ignoreArr2);
|
16
|
+
const ignore3 = ignore().add(ignoreArr3);
|
17
|
+
files.forEach(file => {
|
18
|
+
// console.log(file);
|
19
|
+
const rootDir = 'supportapp';
|
20
|
+
const regex = `^(.+?)${rootDir}?\\\\`;
|
21
|
+
const newFilename = windowsModificationFile(file).replace(new RegExp(regex, 'gi'), '');
|
22
|
+
console.log(newFilename);
|
23
|
+
|
24
|
+
if (newFilename.trim() !== '') {
|
25
|
+
console.log(ignore1.ignores(newFilename));
|
26
|
+
console.log(ignore2.ignores(newFilename));
|
27
|
+
console.log(ignore3.ignores(newFilename));
|
28
|
+
console.log('--------------------------------------------------------------------');
|
29
|
+
}
|
30
|
+
});
|
@@ -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
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
+
|
7
|
+
module.exports = _postcss.default.plugin('postcss-empty', () => (root, result) => {// console.log(root.source.input.from, result);
|
8
|
+
});
|
@@ -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
|
+
const 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,27 +18,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
18
18
|
// }
|
19
19
|
// };
|
20
20
|
// });
|
21
|
-
// export default
|
21
|
+
// export default
|
22
22
|
module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
|
23
23
|
root => {
|
24
24
|
root.walkDecls(decl => {
|
25
25
|
valueReplacer.forEach(obj => {
|
26
26
|
if (obj.props.indexOf(decl.prop) !== -1) {
|
27
|
-
|
27
|
+
let ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
|
28
28
|
ks.forEach(k => {
|
29
29
|
decl.value = decl.value.replace(k, obj.values[k]);
|
30
30
|
}); //decl.value = obj.values[decl.value];
|
31
31
|
}
|
32
|
-
}); //
|
33
|
-
|
34
|
-
|
35
|
-
// if (
|
36
|
-
// obj.props.indexOf(decl.prop) !== -1 &&
|
37
|
-
// obj.values[decl.value] !== undefined
|
38
|
-
// ) {
|
39
|
-
// decl.value = obj.values[decl.value];
|
40
|
-
// }
|
41
|
-
// });
|
42
|
-
// // Transform CSS AST here
|
43
|
-
// });
|
32
|
+
}); //console.log({root, roots:root+""}, root+"")
|
33
|
+
// Transform CSS AST here
|
34
|
+
});
|
44
35
|
});
|
@@ -89,6 +89,7 @@ function pxToCalc(value) {
|
|
89
89
|
}
|
90
90
|
});
|
91
91
|
});
|
92
|
+
console.log(arr.join(' '));
|
92
93
|
return arr.join(' ');
|
93
94
|
}
|
94
95
|
|
@@ -127,25 +128,7 @@ const singleConvertor = (value, changeVal, details, range) => {
|
|
127
128
|
path: path
|
128
129
|
};
|
129
130
|
errHandler.errorTable.push(errObj);
|
130
|
-
errHandler.errorFunction(errObj);
|
131
|
-
// {
|
132
|
-
// decl,
|
133
|
-
// type: 'RANGE_ERROR',
|
134
|
-
// filename,
|
135
|
-
// message: `value (${value}) (${typeof value}) not within range (${
|
136
|
-
// range.start
|
137
|
-
// },${range.end})\r`,
|
138
|
-
// path: path
|
139
|
-
// },
|
140
|
-
// 'RANGE_ERROR'
|
141
|
-
// );
|
142
|
-
// }
|
143
|
-
// 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`)
|
144
|
-
// return value;
|
145
|
-
// } else {
|
146
|
-
// console.log('++++++++++++++++++++++rect val!', value);
|
147
|
-
// }
|
148
|
-
|
131
|
+
errHandler.errorFunction(errObj);
|
149
132
|
return;
|
150
133
|
};
|
151
134
|
|
package/lib/schemas/index.js
CHANGED
@@ -63,7 +63,46 @@ var _default = {
|
|
63
63
|
// ],
|
64
64
|
templateLabel: '{{--dir}}',
|
65
65
|
disableMiniFiySelector: false,
|
66
|
-
dirVarName: 'document.dir'
|
66
|
+
dirVarName: 'document.dir',
|
67
|
+
selectorReplace: {
|
68
|
+
before: [],
|
69
|
+
after: []
|
70
|
+
},
|
71
|
+
plugins: {
|
72
|
+
valueReplacer: false,
|
73
|
+
selectorReplace: false,
|
74
|
+
hasRTL: false,
|
75
|
+
hoverActive: false,
|
76
|
+
combinerMediaQuery: false,
|
77
|
+
cssVariableReplacement: false,
|
78
|
+
selectorWeight: false,
|
79
|
+
minifier: false,
|
80
|
+
composeMinification: false
|
81
|
+
},
|
82
|
+
patterns: {
|
83
|
+
valueReplacer: [],
|
84
|
+
selectorReplace: [],
|
85
|
+
hoverActive: [],
|
86
|
+
combinerMediaQuery: [],
|
87
|
+
hasRTL: [],
|
88
|
+
cssVariableReplacement: [],
|
89
|
+
selectorWeight: [],
|
90
|
+
cssUniqueness: [],
|
91
|
+
composeMinification: []
|
92
|
+
},
|
93
|
+
exclude: {
|
94
|
+
rtl: [],
|
95
|
+
hoverActive: [],
|
96
|
+
combinerMediaQuery: [],
|
97
|
+
cssVariableReplacement: [],
|
98
|
+
selectorWeight: []
|
99
|
+
},
|
100
|
+
cssVariableReplacementConfig: '',
|
101
|
+
selectorWeightConfig: {
|
102
|
+
defaultSelector: '',
|
103
|
+
customFileDetails: '',
|
104
|
+
excludeStrings: []
|
105
|
+
}
|
67
106
|
},
|
68
107
|
efc: {
|
69
108
|
hasEFC: {
|
@@ -229,11 +268,26 @@ var _default = {
|
|
229
268
|
cli: 'enable_smaphook'
|
230
269
|
},
|
231
270
|
plugins: {
|
271
|
+
valueReplacer: false,
|
272
|
+
selectorReplace: false,
|
232
273
|
hasRTL: false,
|
233
274
|
hoverActive: false,
|
234
275
|
combinerMediaQuery: false,
|
235
276
|
cssVariableReplacement: false,
|
236
|
-
selectorWeight: false
|
277
|
+
selectorWeight: false,
|
278
|
+
minifier: false,
|
279
|
+
composeMinification: false
|
280
|
+
},
|
281
|
+
patterns: {
|
282
|
+
valueReplacer: [],
|
283
|
+
selectorReplace: [],
|
284
|
+
hoverActive: [],
|
285
|
+
combinerMediaQuery: [],
|
286
|
+
hasRTL: [],
|
287
|
+
cssVariableReplacement: [],
|
288
|
+
selectorWeight: [],
|
289
|
+
cssUniqueness: [],
|
290
|
+
composeMinification: []
|
237
291
|
},
|
238
292
|
exclude: {
|
239
293
|
rtl: [],
|
@@ -324,13 +378,30 @@ var _default = {
|
|
324
378
|
disableES5Transpile: false,
|
325
379
|
// TODO: Deprecated
|
326
380
|
hasRTL: false,
|
381
|
+
enableReactLive: {
|
382
|
+
value: true,
|
383
|
+
cli: 'react_live'
|
384
|
+
},
|
327
385
|
rtlExclude: [],
|
386
|
+
selectorReplace: null,
|
328
387
|
plugins: {
|
329
|
-
|
388
|
+
rtl: false,
|
330
389
|
hoverActive: false,
|
331
390
|
combinerMediaQuery: false,
|
332
391
|
cssVariableReplacement: false,
|
333
|
-
selectorWeight: false
|
392
|
+
selectorWeight: false,
|
393
|
+
minifier: false,
|
394
|
+
composeMinification: false,
|
395
|
+
selectorReplace: false
|
396
|
+
},
|
397
|
+
patterns: {
|
398
|
+
valueReplacer: [],
|
399
|
+
selectorReplace: [],
|
400
|
+
hoverActive: [],
|
401
|
+
combinerMediaQuery: [],
|
402
|
+
hasRTL: [],
|
403
|
+
cssVariableReplacement: [],
|
404
|
+
selectorWeight: []
|
334
405
|
},
|
335
406
|
exclude: {
|
336
407
|
rtl: [],
|
package/lib/servers/server.js
CHANGED
@@ -202,8 +202,8 @@ if (httpsOptions) {
|
|
202
202
|
port: http2Port
|
203
203
|
}, 'htt' + 'ps')}${contextURL}/`, 'http2 server');
|
204
204
|
});
|
205
|
-
} else {
|
206
|
-
(0, _utils.log)(
|
205
|
+
} else if (httpsOptions) {
|
206
|
+
(0, _utils.log)('Your node version didn\'t adopted http2 support. Kindly update that to 8 LTS or above you can engage the http2');
|
207
207
|
}
|
208
208
|
}
|
209
209
|
|
@@ -9,6 +9,8 @@ var _os = _interopRequireDefault(require("os"));
|
|
9
9
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
11
11
|
|
12
|
+
var _fileHandling = require("../plugins/utils/fileHandling");
|
13
|
+
|
12
14
|
var _getHash = _interopRequireDefault(require("./getHash"));
|
13
15
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -39,32 +41,55 @@ const isSelectorPackage = (resourcePath, packages) => {
|
|
39
41
|
var _default = (unique = true, {
|
40
42
|
filenames,
|
41
43
|
packages
|
42
|
-
}, classNamePrefix) => (context, localIdentName, localName) => {
|
44
|
+
}, classNamePrefix, patterns) => (context, localIdentName, localName) => {
|
45
|
+
// console.log(patterns, context.resourcePath);
|
43
46
|
// NOTE: in build macine we use date as folder path.
|
44
47
|
// So every time we create new build there is path will alway different
|
45
48
|
// in order to minmaze that problem we try in relative path;
|
49
|
+
// console.log('context.resourcePath', context.resourcePath, context);
|
46
50
|
// let contextResourcePath = context.resourcePath;
|
51
|
+
const filePaths = context.resourcePath.split(_path.default.sep);
|
52
|
+
const fileName = filePaths[filePaths.length - 1];
|
53
|
+
const [fileNameWithoutExt] = fileName.split('.');
|
54
|
+
const cleanFileName = fileNameWithoutExt.replace(/-/g, '_').toLowerCase();
|
55
|
+
|
47
56
|
const relativePath = _path.default.relative(context.rootContext, context.resourcePath);
|
57
|
+
/*
|
58
|
+
input :
|
59
|
+
context.resourcePath : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
|
60
|
+
|
61
|
+
patterns.cssVariableReplacement:
|
62
|
+
// include src folder, include deskapp folder, exclude node modules
|
63
|
+
"cssUniqueness": [
|
64
|
+
"src",
|
65
|
+
"deskapp",
|
66
|
+
"!node_modules"
|
67
|
+
]
|
68
|
+
output :
|
69
|
+
true or false
|
70
|
+
*/
|
71
|
+
|
48
72
|
|
49
73
|
if (context.resourcePath.endsWith('.plain.css')) {
|
50
74
|
return localName;
|
51
75
|
}
|
76
|
+
|
77
|
+
if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
|
78
|
+
filename: context.resourcePath,
|
79
|
+
filterArr: patterns.cssUniqueness
|
80
|
+
})) {
|
81
|
+
return `${classNamePrefix}-${cleanFileName}-${localName}`;
|
82
|
+
}
|
52
83
|
/* old production mode start without breaking so added. may be removed in future*/
|
53
84
|
|
54
85
|
|
55
86
|
if (unique) {
|
56
87
|
const h = (0, _getHash.default)(`${relativePath}-${localName}`, 10);
|
57
88
|
return `${classNamePrefix}${h}`;
|
58
|
-
}
|
59
|
-
/* old production mode end*/
|
60
|
-
|
61
|
-
|
62
|
-
const filePaths = context.resourcePath.split(_path.default.sep);
|
63
|
-
const fileName = filePaths[filePaths.length - 1];
|
64
|
-
const [fileNameWithoutExt] = fileName.split('.');
|
65
|
-
const cleanFileName = fileNameWithoutExt.replace(/-/g, '_').toLowerCase(); //css file has casesensitive selector issue so can't toLowerCase
|
89
|
+
} //css file has casesensitive selector issue so can't toLowerCase
|
66
90
|
//let local = localName.toLowerCase()
|
67
91
|
|
92
|
+
|
68
93
|
if (isSelectorPackage(context.resourcePath, packages) || filenames.indexOf(cleanFileName) !== -1) {
|
69
94
|
const h = (0, _getHash.default)(`${relativePath}-${localName}`, 10);
|
70
95
|
return `${classNamePrefix}${h}`;
|
package/lib/utils/getOptions.js
CHANGED
@@ -149,6 +149,51 @@ function deprecationSupport(options) {
|
|
149
149
|
if (options.docs.rtlExclude.length > 0) {
|
150
150
|
options.docs.exclude.rtl = options.docs.rtlExclude;
|
151
151
|
}
|
152
|
+
|
153
|
+
if (options.app.selectorReplace !== null) {
|
154
|
+
options.app.plugins.selectorReplace = true;
|
155
|
+
}
|
156
|
+
|
157
|
+
if (options.docs.selectorReplace !== null) {
|
158
|
+
options.docs.plugins.selectorReplace = true;
|
159
|
+
}
|
160
|
+
|
161
|
+
if (options.css.valueReplacer !== null) {
|
162
|
+
options.app.plugins.valueReplacer = true;
|
163
|
+
}
|
164
|
+
|
165
|
+
options.app.exclude.hasRTL = options.app.exclude.rtl;
|
166
|
+
|
167
|
+
if (!options.app.patterns) {
|
168
|
+
options.app.patterns = {};
|
169
|
+
}
|
170
|
+
|
171
|
+
if (options.app.patterns.valueReplacer.length === 0) {
|
172
|
+
options.app.patterns.valueReplacer = ['*'];
|
173
|
+
}
|
174
|
+
|
175
|
+
if (options.app.patterns.selectorReplace.length === 0) {
|
176
|
+
options.app.patterns.selectorReplace = ['*'];
|
177
|
+
}
|
178
|
+
|
179
|
+
if (options.docs.patterns.selectorReplace.length === 0) {
|
180
|
+
options.docs.patterns.selectorReplace = ['*'];
|
181
|
+
}
|
182
|
+
|
183
|
+
Object.keys(options.app.patterns).forEach(key => {
|
184
|
+
if (options.app.exclude[key] && options.app.patterns[key].length === 0) {
|
185
|
+
let tempArr = options.app.exclude[key];
|
186
|
+
tempArr = tempArr.map(x => `!${x}`);
|
187
|
+
options.app.patterns[key] = tempArr;
|
188
|
+
}
|
189
|
+
});
|
190
|
+
Object.keys(options.docs.patterns).forEach(key => {
|
191
|
+
if (options.docs.exclude[key] && options.docs.patterns[key].length === 0) {
|
192
|
+
let tempArr = options.docs.exclude[key];
|
193
|
+
tempArr = tempArr.map(x => `!${x}`);
|
194
|
+
options.docs.patterns[key] = tempArr;
|
195
|
+
}
|
196
|
+
});
|
152
197
|
}
|
153
198
|
|
154
199
|
const getOptions = () => {
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _getOptions = _interopRequireDefault(require("./getOptions"));
|
4
|
+
|
5
|
+
var _folderIterator = _interopRequireDefault(require("./folderIterator"));
|
6
|
+
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
|
+
|
9
|
+
const postcss = require('postcss');
|
10
|
+
|
11
|
+
const path = require('path');
|
12
|
+
|
13
|
+
const fs = require('fs');
|
14
|
+
|
15
|
+
const SelectorReplacePlugin = require('../postcss-plugins/SelectorReplace');
|
16
|
+
|
17
|
+
const cwd = process.cwd();
|
18
|
+
const src = path.join(cwd, process.argv[2]);
|
19
|
+
const dist = path.join(cwd, process.argv[3]);
|
20
|
+
const options = (0, _getOptions.default)();
|
21
|
+
|
22
|
+
function watchHandler(fromPath, toPath) {
|
23
|
+
const css = fs.readFileSync(fromPath, 'utf-8'); // console.log(css);
|
24
|
+
|
25
|
+
const {
|
26
|
+
css: cssOptions
|
27
|
+
} = options; // console.log(cssOptions, appOptions);
|
28
|
+
|
29
|
+
const {
|
30
|
+
selectorReplace
|
31
|
+
} = cssOptions;
|
32
|
+
postcss([SelectorReplacePlugin(selectorReplace)]).process(css, {
|
33
|
+
from: fromPath,
|
34
|
+
to: toPath
|
35
|
+
}).then(result => {
|
36
|
+
fs.writeFileSync(toPath, result.css);
|
37
|
+
}); // console.log(variableOptions);
|
38
|
+
}
|
39
|
+
|
40
|
+
(0, _folderIterator.default)(src, dist, ['.css'], false, (fromPath, toPath) => {
|
41
|
+
// console.log(fromPath, toPath);
|
42
|
+
watchHandler(fromPath, toPath);
|
43
|
+
}); // if (canWacth) {
|
44
|
+
// useExitCleanup(() => {
|
45
|
+
// fs.unwatchFile(src, watchHandler);
|
46
|
+
// });
|
47
|
+
// }
|