@zohodesk/react-cli 1.1.14-kubernetes → 1.1.15
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/.vscode/settings.json +25 -0
- package/README.md +294 -16
- package/bin/cli.js +30 -55
- package/docs/ComposeMinification.md +13 -0
- package/docs/CustomChunks.md +12 -9
- package/docs/MarkdownParser.md +18 -0
- package/docs/ReactLive.md +14 -0
- package/docs/SelectorWeight.md +3 -0
- package/docs/ValueReplacer.md +27 -0
- package/docs/VariableConversion.md +6 -1
- package/docs/patternFiltering.md +57 -0
- package/lib/common/buildEs.js +12 -0
- package/lib/common/runPreProcess.js +71 -0
- package/lib/common/splitChunks.js +65 -45
- package/lib/common/testPattern.js +9 -11
- package/lib/common/valueReplacer.js +1 -3
- package/lib/configs/resolvers.js +16 -5
- package/lib/configs/webpack.css.umd.config.js +3 -2
- package/lib/configs/webpack.dev.config.js +15 -5
- package/lib/configs/webpack.docs.config.js +17 -5
- package/lib/configs/webpack.impact.config.js +11 -4
- package/lib/configs/webpack.prod.config.js +15 -5
- package/lib/constants.js +3 -3
- package/lib/deprecationLogger.js +40 -0
- package/lib/loaderUtils/getCSSLoaders.js +98 -49
- package/lib/loaderUtils/tests/windowsModification.test.js +10 -0
- package/lib/loaderUtils/windowsModification.js +6 -1
- package/lib/loaders/__test__/markdownLoader.spec.js +145 -0
- package/lib/loaders/composeLoader.js +298 -0
- package/lib/loaders/docsLoader.js +18 -7
- package/lib/loaders/markdownLoader.js +71 -0
- package/lib/loaders/reactLiveConvertor.js +105 -0
- package/lib/loaders/selectorMappingLoader.js +9 -9
- package/lib/logger.js +27 -0
- package/lib/pluginUtils/getDevPlugins.js +25 -6
- package/lib/pluginUtils/getProdPlugins.js +32 -5
- package/lib/pluginUtils/getUMDCSSPlugins.js +1 -1
- package/lib/pluginUtils/getUMDComponentPlugins.js +1 -1
- package/lib/plugins/CustomAttributePlugin.js +82 -0
- package/lib/plugins/CustomAttributePlugin.md +35 -0
- package/lib/plugins/EFCPlugin.js +9 -9
- package/lib/plugins/EFCTemplatePlugin.js +10 -12
- package/lib/plugins/EfcResourceCleanupPlugin.js +43 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +8 -9
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +2 -3
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +2 -7
- package/lib/plugins/I18nSplitPlugin/index.js +1 -1
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +8 -8
- package/lib/plugins/{UglifyCSSPlugin.js → MinifyPlugin.js} +3 -3
- package/lib/plugins/ReportGeneratePlugin.js +8 -6
- package/lib/plugins/ResourceHintsPlugin.js +13 -3
- package/lib/plugins/SelectorPlugin.js +77 -37
- package/lib/plugins/StatsPlugin.js +82 -0
- package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
- package/lib/plugins/VariableConversionCollector.js +40 -101
- package/lib/plugins/index.js +7 -7
- package/lib/plugins/utils/classHandling.js +35 -0
- package/lib/plugins/utils/fileHandling.js +92 -0
- package/lib/plugins/utils/tests/fileHandling.test.js +30 -0
- package/lib/plugins/variableConvertorUtils.js +133 -0
- package/lib/postcss-plugins/EmptyPlugin.js +8 -0
- package/lib/postcss-plugins/ExcludePlugin.js +1 -1
- package/lib/postcss-plugins/IncludePlugin.js +23 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +4 -10
- package/lib/postcss-plugins/SelectorReplace.js +80 -0
- package/lib/postcss-plugins/ValueReplacer.js +8 -29
- package/lib/postcss-plugins/__test__/selectorReplace.test.js +28 -0
- package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
- package/lib/postcss-plugins/hoverActivePlugin.js +0 -6
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +0 -1
- package/lib/postcss-plugins/variableModificationPlugin/index.js +94 -38
- package/lib/schemas/index.js +95 -18
- package/lib/servers/devBuild.js +13 -11
- package/lib/servers/getCliPath.js +3 -5
- package/lib/servers/httpsOptions.js +12 -13
- package/lib/servers/nowatchserver.js +62 -55
- package/lib/servers/requireLocalOrGlobal.js +61 -0
- package/lib/servers/server.js +53 -52
- package/lib/utils/cssClassNameGenerate.js +70 -13
- package/lib/utils/deprecationSupport.js +134 -0
- package/lib/utils/getOptions.js +35 -28
- package/lib/utils/getServerURL.js +1 -9
- package/lib/utils/index.js +14 -12
- package/lib/utils/initPreCommitHook.js +5 -5
- package/lib/utils/log.js +11 -0
- package/lib/utils/object-manipulation.js +88 -0
- package/lib/utils/pullOrigin.js +3 -3
- package/lib/utils/reinstallDependencies.js +3 -3
- package/lib/utils/selectorReplacer.js +47 -0
- package/lib/utils/switchBranch.js +4 -2
- package/lib/utils/variableConverter.js +104 -0
- package/npm-shrinkwrap.json +33485 -0
- package/package.json +5 -3
- package/templates/docs/all.html +1 -0
- package/templates/docs/component.html +1 -0
- package/templates/docs/components.html +1 -0
- package/templates/docs/css/markdown.css +202 -0
- package/templates/docs/css/style.css +136 -169
- package/templates/docs/index.html +796 -632
- package/lib/plugins/composeCommonPlugin.js +0 -30
- package/lib/postcss-plugins/variableModifier.js +0 -244
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isFileNameMatchingPattern = isFileNameMatchingPattern;
|
|
7
|
+
exports.isFileNameMatchingPluginPattern = isFileNameMatchingPluginPattern;
|
|
8
|
+
|
|
9
|
+
var _ignore = _interopRequireDefault(require("ignore"));
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
const aliasNames = {
|
|
16
|
+
valueReplacer: 'postcss-value-replacer',
|
|
17
|
+
selectorReplace: 'postcss-selector-replace-new',
|
|
18
|
+
hasRTL: 'postcss-rtl',
|
|
19
|
+
combinerMediaQuery: 'postcss-combine-media-query',
|
|
20
|
+
hoverActive: 'postcss-mobile-hover',
|
|
21
|
+
cssVariableReplacement: 'postcss-variable-report',
|
|
22
|
+
composeMinification: 'postcss-compose-plugin'
|
|
23
|
+
};
|
|
24
|
+
/*
|
|
25
|
+
|
|
26
|
+
unique scenario
|
|
27
|
+
|
|
28
|
+
*/
|
|
29
|
+
// export function filterFileCssUniqueness(filename, filterObj) {
|
|
30
|
+
// let rootDir = 'supportapp';
|
|
31
|
+
// let include = false;
|
|
32
|
+
// const regex = `^(.+?)${rootDir}?\\\\`;
|
|
33
|
+
// const newFilename = windowsModificationFile(filename).replace(
|
|
34
|
+
// new RegExp(regex, 'gi'),
|
|
35
|
+
// ''
|
|
36
|
+
// );
|
|
37
|
+
// Object.keys(filterObj).forEach(key => {
|
|
38
|
+
// const ig = ignore().add(filterObj[key]);
|
|
39
|
+
// if (ig.ignores(newFilename)) {
|
|
40
|
+
// include = true;
|
|
41
|
+
// }
|
|
42
|
+
// });
|
|
43
|
+
// return include;
|
|
44
|
+
// }
|
|
45
|
+
|
|
46
|
+
function isFileNameMatchingPattern({
|
|
47
|
+
filename,
|
|
48
|
+
filterObject,
|
|
49
|
+
plugins,
|
|
50
|
+
order
|
|
51
|
+
}) {
|
|
52
|
+
const pluginObj = {};
|
|
53
|
+
plugins.forEach(p => {
|
|
54
|
+
pluginObj[p.postcssPlugin] = p;
|
|
55
|
+
});
|
|
56
|
+
const finalPlugins = order.filter(key => {
|
|
57
|
+
const pluginSpecificFilter = filterObject[key];
|
|
58
|
+
|
|
59
|
+
if (!pluginSpecificFilter || pluginSpecificFilter.length === 0) {
|
|
60
|
+
return true;
|
|
61
|
+
} // eslint-disable-next-line no-use-before-define
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const isMatching = isFilePathMatchingPattern(filename, pluginSpecificFilter);
|
|
65
|
+
return isMatching;
|
|
66
|
+
}).map(key => {
|
|
67
|
+
const p = pluginObj[aliasNames[key]];
|
|
68
|
+
return p;
|
|
69
|
+
}); // if unknown key given in plugins and pattern loop will run but post-css plugin won't be available and will be undefined in array
|
|
70
|
+
// So we do filter as safety measure.
|
|
71
|
+
|
|
72
|
+
return finalPlugins.filter(Boolean);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isFilePathMatchingPattern(filePath, patterns) {
|
|
76
|
+
if (patterns.length === 0) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const ig = (0, _ignore.default)({
|
|
81
|
+
allowRelativePaths: true
|
|
82
|
+
}).add(patterns);
|
|
83
|
+
return ig.ignores(filePath);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function isFileNameMatchingPluginPattern({
|
|
87
|
+
filename,
|
|
88
|
+
filterArr
|
|
89
|
+
}) {
|
|
90
|
+
const newFilename = path.relative(path.parse(process.cwd()).base, filename);
|
|
91
|
+
return isFilePathMatchingPattern(newFilename, filterArr);
|
|
92
|
+
}
|
|
@@ -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,133 @@
|
|
|
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 (pxReplacement && 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
|
+
let valArr = decl.value.split(' ');
|
|
99
|
+
valArr = valArr.filter(x => x.trim() !== '');
|
|
100
|
+
valArr = valArr.map(x => x.replace(/\r|\t|\n/gi, '')); // single values are considered in the above array and converted below
|
|
101
|
+
|
|
102
|
+
valArr.forEach((value, index) => {
|
|
103
|
+
if (value.includes('px')) {
|
|
104
|
+
if (value.includes('calc')) {
|
|
105
|
+
const res = convertCalcValue(pxReplacement, parseCalcValue(value));
|
|
106
|
+
valArr[index] = `calc( ${res.valOne.trim()} * ${res.valTwo.trim()} )`;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (/-(\d+)/gi.test(value)) {
|
|
111
|
+
valArr[index] = convertToCalc(pxReplacement, value);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const num = value.replace('px', '');
|
|
116
|
+
|
|
117
|
+
if (value) {
|
|
118
|
+
valArr[index] = pxReplacement.replace('$$', num);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (value.includes('px')) {
|
|
123
|
+
const num = value.replace('px', '');
|
|
124
|
+
valArr[index] = pxReplacement.replace('$$', num);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
currentNode.value = valArr.join(' ');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
return rootOriginal;
|
|
133
|
+
}
|
|
@@ -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));
|
|
@@ -0,0 +1,23 @@
|
|
|
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-include-files', opts => {
|
|
8
|
+
const {
|
|
9
|
+
plugins
|
|
10
|
+
} = opts;
|
|
11
|
+
return (root, result) => {
|
|
12
|
+
const inputFile = root.source.input.file;
|
|
13
|
+
const includeFile = opts.include.some(file => inputFile.indexOf(file) !== -1);
|
|
14
|
+
|
|
15
|
+
if (includeFile) {
|
|
16
|
+
const handler = response => response.messages.forEach(msg => result.messages.push(msg));
|
|
17
|
+
|
|
18
|
+
return (0, _postcss.default)(plugins).process(root, {
|
|
19
|
+
from: undefined
|
|
20
|
+
}).then(handler);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
});
|
|
@@ -18,7 +18,6 @@ const oppositeDir = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
function compareSelector(selector1, selector2) {
|
|
21
|
-
// console.log({ selector1, selector2 }, selector1 === selector2);
|
|
22
21
|
return selector1 === selector2;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -66,7 +65,6 @@ function mergeIfSameSelector(rule) {
|
|
|
66
65
|
|
|
67
66
|
|
|
68
67
|
function removeIfOppsiteDirRule(rule, direction, rootOptions) {
|
|
69
|
-
// console.log({ rule, type: rule.type });
|
|
70
68
|
const selectors = rule.selector.split(/\s*,\s*/); // NOTE: if we use opposite dir selector as custom override reason,
|
|
71
69
|
// and compain normal selector with it, In this case
|
|
72
70
|
// we just a have to remove that selector only not full rule
|
|
@@ -87,11 +85,10 @@ function removeIfOppsiteDirRule(rule, direction, rootOptions) {
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
function removeIfOppsiteDirKeyframe(rule, direction) {
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
const name = rule.params;
|
|
89
|
+
const keyFrameDirName = name.slice(name.lastIndexOf('-') + 1);
|
|
92
90
|
|
|
93
91
|
if (keyFrameDirName === oppositeDir[direction]) {
|
|
94
|
-
// console.log({ m: 'removed', keyFrameName: rule.params });
|
|
95
92
|
rule.remove();
|
|
96
93
|
}
|
|
97
94
|
}
|
|
@@ -109,12 +106,10 @@ function separateSingleDir(root, direction, rootOptions) {
|
|
|
109
106
|
|
|
110
107
|
function separateRtlAndLtr(css, rootOptions) {
|
|
111
108
|
// let processor = postcss([]).process(css);
|
|
112
|
-
|
|
113
|
-
// console.log(processor, root);
|
|
109
|
+
const root = postcss.parse(css); // let { root } = processor;
|
|
114
110
|
// NOTE: I did first rtl then ltr , Because for ltr I use original root ref
|
|
115
111
|
|
|
116
|
-
const rtlRoot = separateSingleDir(root.clone(), 'rtl', rootOptions);
|
|
117
|
-
|
|
112
|
+
const rtlRoot = separateSingleDir(root.clone(), 'rtl', rootOptions);
|
|
118
113
|
const ltrRoot = separateSingleDir(root, 'ltr', rootOptions);
|
|
119
114
|
return {
|
|
120
115
|
ltrRoot,
|
|
@@ -132,7 +127,6 @@ function separateRtlAndLtr(css, rootOptions) {
|
|
|
132
127
|
// // root.append(postcss.comment({ text: 'comment' }));
|
|
133
128
|
// root.append(postcss.comment({ text: 'this is spliting part ' }));
|
|
134
129
|
// root.append(rtlRoot);
|
|
135
|
-
// //console.log({root, roots:root+""}, root+"")
|
|
136
130
|
// // Transform CSS AST here
|
|
137
131
|
// }
|
|
138
132
|
// );
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
function validator(opts) {
|
|
8
|
+
if (!opts || typeof opts !== 'object') {
|
|
9
|
+
throw new Error('Always requires argment');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
before,
|
|
14
|
+
after
|
|
15
|
+
} = opts;
|
|
16
|
+
|
|
17
|
+
if (!before || !after) {
|
|
18
|
+
throw new Error('Be sure to have "before" and "after" object names');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!Array.isArray(before) || !Array.isArray(after)) {
|
|
22
|
+
throw new Error('Objects "before" and "after" must be of type Array');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (before.length !== after.length) {
|
|
26
|
+
throw new Error('Length of before and after options must be the same');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (before.length === 0) {
|
|
30
|
+
throw new Error('Array length is 1 or more');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
before.forEach((beforeOpt, idx) => {
|
|
34
|
+
const afterOpt = after[idx];
|
|
35
|
+
|
|
36
|
+
switch (true) {
|
|
37
|
+
case typeof beforeOpt === 'string':
|
|
38
|
+
{
|
|
39
|
+
if (!typeof afterOpt === 'string') {
|
|
40
|
+
throw new Error(`The after option ${afterOpt} must be a string. If you want to apply the replace callback function, then use a RegExp for the before option`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
case beforeOpt instanceof RegExp:
|
|
47
|
+
{
|
|
48
|
+
if (!typeof afterOpt === 'string' && !typeof afterOpt === 'function') {
|
|
49
|
+
throw new Error(`The after option ${afterOpt} must be either a string, or a function`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`The before option ${beforeOpt} must be either a string, or a RegExp`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = _postcss.default.plugin('postcss-selector-replace-new', opts => {
|
|
62
|
+
validator(opts);
|
|
63
|
+
const {
|
|
64
|
+
before,
|
|
65
|
+
after
|
|
66
|
+
} = opts;
|
|
67
|
+
return root => {
|
|
68
|
+
root.walkRules(rule => {
|
|
69
|
+
before.forEach((beforeOpt, idx) => {
|
|
70
|
+
const afterOpt = after[idx];
|
|
71
|
+
|
|
72
|
+
if (typeof beforeOpt === 'string') {
|
|
73
|
+
rule.selector = rule.selector.split(beforeOpt).join(afterOpt);
|
|
74
|
+
} else {
|
|
75
|
+
rule.selector = rule.selector.replace(beforeOpt, afterOpt);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
});
|
|
@@ -4,43 +4,22 @@ var _postcss = _interopRequireDefault(require("postcss"));
|
|
|
4
4
|
|
|
5
5
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
6
|
|
|
7
|
-
// module.exports = postcss.plugin('postcss-value-replacer', opts => {
|
|
8
|
-
// const { plugins } = opts;
|
|
9
|
-
// return (root, result) => {
|
|
10
|
-
// const inputFile = root.source.input.file;
|
|
11
|
-
// let isIgnoredFile= opts.ignore.some(file => inputFile.indexOf(file)!==-1);
|
|
12
|
-
// if (!isIgnoredFile) {
|
|
13
|
-
// const handler = response =>
|
|
14
|
-
// response.messages.forEach(msg => result.messages.push(msg));
|
|
15
|
-
// return postcss(plugins)
|
|
16
|
-
// .process(root, { from: undefined })
|
|
17
|
-
// .then(handler);
|
|
18
|
-
// }
|
|
19
|
-
// };
|
|
20
|
-
// });
|
|
21
|
-
// export default
|
|
22
7
|
module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
|
|
23
8
|
root => {
|
|
24
9
|
root.walkDecls(decl => {
|
|
25
10
|
valueReplacer.forEach(obj => {
|
|
26
11
|
if (obj.props.indexOf(decl.prop) !== -1) {
|
|
27
|
-
|
|
12
|
+
const ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
|
|
28
13
|
ks.forEach(k => {
|
|
29
|
-
|
|
14
|
+
// if (/^\^.*\$$/gi.test(k)) {
|
|
15
|
+
if (k.startsWith('^') && k.endsWith('$')) {
|
|
16
|
+
decl.value = decl.value.replace(new RegExp(k), obj.values[k]);
|
|
17
|
+
} else {
|
|
18
|
+
decl.value = decl.value.replace(k, obj.values[k]);
|
|
19
|
+
}
|
|
30
20
|
}); //decl.value = obj.values[decl.value];
|
|
31
21
|
}
|
|
32
22
|
}); //console.log({root, roots:root+""}, root+"")
|
|
33
23
|
// Transform CSS AST here
|
|
34
|
-
});
|
|
35
|
-
// valueReplacer.forEach(obj => {
|
|
36
|
-
// if (
|
|
37
|
-
// obj.props.indexOf(decl.prop) !== -1 &&
|
|
38
|
-
// obj.values[decl.value] !== undefined
|
|
39
|
-
// ) {
|
|
40
|
-
// decl.value = obj.values[decl.value];
|
|
41
|
-
// }
|
|
42
|
-
// });
|
|
43
|
-
// //console.log({root, roots:root+""}, root+"")
|
|
44
|
-
// // Transform CSS AST here
|
|
45
|
-
// });
|
|
24
|
+
});
|
|
46
25
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
let settings1 = {
|
|
4
|
+
selectorReplace: {
|
|
5
|
+
before: [':root', 'data-mode', 'data-theme'],
|
|
6
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__', 'data-desk-mode', 'data-desk-theme']
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
let settings2 = {
|
|
10
|
+
selectorReplace: {
|
|
11
|
+
before: [':root', 'data-'],
|
|
12
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__', 'test-']
|
|
13
|
+
}
|
|
14
|
+
}; //error case
|
|
15
|
+
|
|
16
|
+
let settings3 = {
|
|
17
|
+
selectorReplace: {
|
|
18
|
+
before: [':root', 'data-'],
|
|
19
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__']
|
|
20
|
+
}
|
|
21
|
+
}; //error case
|
|
22
|
+
|
|
23
|
+
let settings4 = {
|
|
24
|
+
selectorReplace: {
|
|
25
|
+
before: [':root'],
|
|
26
|
+
after: [':global .zohodesk_controlpanel,:global .wms-mainui,:global .wms-hysearch, :global .mcf1ee8b17_overlay,:global .wms-hvalign, :global .KB_Editor_UploadImage,:global .zdeskEditor_popup, :global .ze_dd, :global .__baseZC_Container__', 'test-']
|
|
27
|
+
}
|
|
28
|
+
}; // here conversion happens for data from one index to another
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
4
|
+
|
|
5
|
+
var _ValueReplacer = _interopRequireDefault(require("../ValueReplacer"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-use-before-define */
|
|
10
|
+
describe('postcss value replacer tests', () => {
|
|
11
|
+
it('is creating value replaced code', () => {
|
|
12
|
+
const cssInputStr = `.abc{ cursor : text }`;
|
|
13
|
+
const cssOutputStr = `.abc{ cursor : --textCursor }`;
|
|
14
|
+
const cssOptions = [{
|
|
15
|
+
props: ['font', 'font-family', 'cursor'],
|
|
16
|
+
values: {
|
|
17
|
+
'zdf-': 'zd-react-app-',
|
|
18
|
+
'^text$': '--textCursor'
|
|
19
|
+
}
|
|
20
|
+
}];
|
|
21
|
+
const result = runValueReplacerForCssString(cssInputStr, cssOptions);
|
|
22
|
+
expect(result.css).toEqual(cssOutputStr);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('postcss value replacer tests', () => {
|
|
26
|
+
it('is creating value replaced code', () => {
|
|
27
|
+
const cssInputStr = `.def{ cursor : var(--textBoxCursor) }`;
|
|
28
|
+
const cssOutputStr = `.def{ cursor : var(--textBoxCursor) }`;
|
|
29
|
+
const cssOptions = [{
|
|
30
|
+
props: ['font', 'font-family', 'cursor'],
|
|
31
|
+
values: {
|
|
32
|
+
'zdf-': 'zd-react-app-',
|
|
33
|
+
'^text$': '--textCursor'
|
|
34
|
+
}
|
|
35
|
+
}];
|
|
36
|
+
const result = runValueReplacerForCssString(cssInputStr, cssOptions);
|
|
37
|
+
expect(result.css).toEqual(cssOutputStr);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function runValueReplacerForCssString(cssInputStr, cssOptions) {
|
|
42
|
+
return (0, _postcss.default)([(0, _ValueReplacer.default)(cssOptions)]).process(cssInputStr);
|
|
43
|
+
}
|
|
@@ -158,7 +158,6 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
|
158
158
|
|
|
159
159
|
function mediaCommaQuery(rule, index) {
|
|
160
160
|
if (rule.parent.params !== undefined && !rule.parent.params.includes('hover')) {
|
|
161
|
-
//console.log(hovMed, actMed);
|
|
162
161
|
let newSelector = '';
|
|
163
162
|
const {
|
|
164
163
|
hovMed,
|
|
@@ -232,7 +231,6 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
function commaQuery(rule, index) {
|
|
235
|
-
//console.log("comma" , rule.selector.split('\n'));
|
|
236
234
|
let newSelector = '';
|
|
237
235
|
const hovQueries = [];
|
|
238
236
|
rule.selector.split(/\s*,\s*/).forEach(_subrule => {
|
|
@@ -288,13 +286,10 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
|
288
286
|
});
|
|
289
287
|
rootOriginal.walkRules(/:hover/i, (rule, index) => {
|
|
290
288
|
// media hover query with ',' ' ' '+'
|
|
291
|
-
// console.log("media query" , rule.selector)
|
|
292
289
|
if (rule.parent.type === 'atrule' && rule.selector.includes(',')) {
|
|
293
|
-
//console.log("media comma", rule.selector)
|
|
294
290
|
mediaCommaQuery(rule, index);
|
|
295
291
|
} else {
|
|
296
292
|
// plus, space and other media queries
|
|
297
|
-
//console.log("media", rule.selector)
|
|
298
293
|
mediaQuery(rule, index);
|
|
299
294
|
} // usual hover query
|
|
300
295
|
|
|
@@ -311,7 +306,6 @@ module.exports = _postcss.default.plugin('postcss-mobile-hover', mediaQueryHover
|
|
|
311
306
|
if (rule.selector.includes(',')) {
|
|
312
307
|
commaQuery(rule, index);
|
|
313
308
|
} else if (rule.selector.match(/ +|\++/g)) {
|
|
314
|
-
//console.log("plus or space" , rule.selector);
|
|
315
309
|
if (rule.selector.includes('hover')) {
|
|
316
310
|
hoverRules.push({
|
|
317
311
|
rule,
|