@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.
Files changed (42) hide show
  1. package/README.md +26 -1
  2. package/bin/cli.js +18 -4
  3. package/docs/ComposeMinification.md +13 -0
  4. package/docs/ReactLive.md +10 -0
  5. package/docs/patternFiltering.md +57 -0
  6. package/lib/common/buildEs.js +12 -0
  7. package/lib/configs/webpack.dev.config.js +3 -0
  8. package/lib/configs/webpack.docs.config.js +8 -1
  9. package/lib/configs/webpack.impact.config.js +2 -0
  10. package/lib/configs/webpack.prod.config.js +3 -0
  11. package/lib/loaderUtils/getCSSLoaders.js +77 -46
  12. package/lib/loaderUtils/tests/windowsModification.test.js +10 -0
  13. package/lib/loaderUtils/windowsModification.js +6 -1
  14. package/lib/loaders/composeLoader.js +172 -0
  15. package/lib/loaders/docsLoader.js +15 -7
  16. package/lib/loaders/reactLiveConvertor.js +105 -0
  17. package/lib/pluginUtils/getDevPlugins.js +10 -3
  18. package/lib/pluginUtils/getProdPlugins.js +8 -3
  19. package/lib/pluginUtils/getUMDCSSPlugins.js +1 -1
  20. package/lib/pluginUtils/getUMDComponentPlugins.js +1 -1
  21. package/lib/plugins/{UglifyCSSPlugin.js → MinifyPlugin.js} +3 -3
  22. package/lib/plugins/SelectorPlugin.js +63 -40
  23. package/lib/plugins/VariableConversionCollector.js +40 -97
  24. package/lib/plugins/index.js +7 -7
  25. package/lib/plugins/utils/classHandling.js +35 -0
  26. package/lib/plugins/utils/fileHandling.js +107 -0
  27. package/lib/plugins/utils/tests/fileHandling.test.js +30 -0
  28. package/lib/plugins/variableConvertorUtils.js +131 -0
  29. package/lib/postcss-plugins/EmptyPlugin.js +8 -0
  30. package/lib/postcss-plugins/ExcludePlugin.js +1 -1
  31. package/lib/postcss-plugins/ValueReplacer.js +5 -14
  32. package/lib/postcss-plugins/variableModificationPlugin/index.js +2 -19
  33. package/lib/schemas/index.js +75 -4
  34. package/lib/servers/server.js +2 -2
  35. package/lib/utils/cssClassNameGenerate.js +34 -9
  36. package/lib/utils/getOptions.js +45 -0
  37. package/lib/utils/selectorReplacer.js +47 -0
  38. package/lib/utils/variableConverter.js +89 -0
  39. package/{package-lock.json → npm-shrinkwrap.json} +79 -74
  40. package/package.json +3 -1
  41. package/lib/plugins/composeCommonPlugin.js +0 -30
  42. package/lib/postcss-plugins/variableModifier.js +0 -210
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ var _fileHandling = require("../plugins/utils/fileHandling");
4
+
5
+ var _getOptions = _interopRequireDefault(require("./getOptions"));
6
+
7
+ var _folderIterator = _interopRequireDefault(require("./folderIterator"));
8
+
9
+ var _variableConvertorUtils = require("../plugins/variableConvertorUtils");
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ const postcss = require('postcss');
14
+
15
+ const path = require('path');
16
+
17
+ const fs = require('fs');
18
+
19
+ const postcssVariableConvertor = require('../postcss-plugins/variableModificationPlugin/index').plugin;
20
+
21
+ const cwd = process.cwd();
22
+ const src = path.join(cwd, process.argv[2]);
23
+ const dist = path.join(cwd, process.argv[3]);
24
+ const options = (0, _getOptions.default)();
25
+
26
+ function watchHandler(fromPath, toPath) {
27
+ const css = fs.readFileSync(fromPath, 'utf-8'); // console.log(css);
28
+
29
+ const {
30
+ css: cssOptions
31
+ } = options; // console.log(cssOptions, appOptions);
32
+
33
+ const {
34
+ cssVariableReplacementConfig: cssVariableConfigFilePath,
35
+ patterns: filterArr
36
+ } = cssOptions;
37
+ const rootOriginal = postcss.parse(css);
38
+ const variables = {}; // const unassigned = {};
39
+
40
+ const rawdata = fs.readFileSync(cssVariableConfigFilePath).toString();
41
+ const cssVariableOptions = JSON.parse(rawdata);
42
+ const {
43
+ settings: settingsObject // errorLog: errorLogStatus,
44
+ // errorInConsole: errorConsoleStatus,
45
+ // errorsAllowed,
46
+ // strictMode
47
+
48
+ } = cssVariableOptions;
49
+ rootOriginal.walkRules(rule => {
50
+ rule.walkDecls(decl => {
51
+ decl.value.split(' ').forEach(val => {
52
+ if (val && val.includes('--') && !new RegExp(_variableConvertorUtils.ignoreVals.join('|'), 'gi').test(val) && decl.prop) {
53
+ const extractedValue = (0, _variableConvertorUtils.extractVariableName)(val);
54
+
55
+ if (!variables[extractedValue]) {
56
+ variables[extractedValue] = decl.prop;
57
+ }
58
+ }
59
+ });
60
+ });
61
+ });
62
+
63
+ if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
64
+ filename: fromPath,
65
+ filterArr
66
+ })) {
67
+ return;
68
+ }
69
+
70
+ const convertedCode = (0, _variableConvertorUtils.variableConverter)(rootOriginal, variables, settingsObject).toString(); // if (convertedCode.trim() !== '') {
71
+ // fs.writeFileSync(fromPath, convertedCode);
72
+ // }
73
+ // console.log(convertedCode);
74
+
75
+ postcss([postcssVariableConvertor(cssVariableConfigFilePath)]).process(convertedCode, {
76
+ from: undefined
77
+ }).then(result => {
78
+ fs.writeFileSync(toPath, result.css);
79
+ }); // console.log(variableOptions);
80
+ }
81
+
82
+ (0, _folderIterator.default)(src, dist, ['.css'], false, (fromPath, toPath) => {
83
+ // console.log(fromPath, toPath);
84
+ watchHandler(fromPath, toPath);
85
+ }); // if (canWacth) {
86
+ // useExitCleanup(() => {
87
+ // fs.unwatchFile(src, watchHandler);
88
+ // });
89
+ // }