@zohodesk/react-cli 1.1.17 → 1.1.18-exp.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 (135) hide show
  1. package/README.md +13 -0
  2. package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
  3. package/lib/babel/cmjs-plugins-presets.js +7 -1
  4. package/lib/babel/es-plugins-presets.js +7 -1
  5. package/lib/configs/webpack.dev.config.js +7 -2
  6. package/lib/configs/webpack.prod.config.js +9 -2
  7. package/lib/loaderUtils/getDevJsLoaders.js +5 -1
  8. package/lib/schemas/index.js +4 -0
  9. package/npm-shrinkwrap.json +31 -5
  10. package/package.json +1 -1
  11. package/packages/client_build_tool/lib/allCommandsConfigs.js +23 -0
  12. package/packages/client_build_tool/lib/buildToolLoggers.js +32 -0
  13. package/packages/client_build_tool/lib/commands/build/commandExecutor.js +21 -0
  14. package/packages/client_build_tool/lib/commands/build/config.js +12 -0
  15. package/packages/client_build_tool/lib/commands/build/errorHander.js +10 -0
  16. package/packages/client_build_tool/lib/commands/build/index.js +35 -0
  17. package/packages/client_build_tool/lib/commands/build/optionsProcesser.js +40 -0
  18. package/packages/client_build_tool/lib/commands/buildEs/commandExecutor.js +17 -0
  19. package/packages/client_build_tool/lib/commands/buildEs/config.js +12 -0
  20. package/packages/client_build_tool/lib/commands/buildLib/commandExecutor.js +17 -0
  21. package/packages/client_build_tool/lib/commands/buildLib/config.js +12 -0
  22. package/packages/client_build_tool/lib/commands/start/commandExecutor.js +13 -0
  23. package/packages/client_build_tool/lib/commands/start/config.js +12 -0
  24. package/packages/client_build_tool/lib/commands/start/deprecationHandler.js +10 -0
  25. package/packages/client_build_tool/lib/commands/start/errorHander.js +10 -0
  26. package/packages/client_build_tool/lib/commands/start/optionsProcesser.js +36 -0
  27. package/packages/client_build_tool/lib/commands/start/postProcesser.js +10 -0
  28. package/packages/client_build_tool/lib/commands/start/preProcesser.js +10 -0
  29. package/packages/client_build_tool/lib/commandsRouter.js +71 -0
  30. package/packages/client_build_tool/lib/shared/bundler/webpack/common/decidePublicPath.js +44 -0
  31. package/packages/client_build_tool/lib/shared/bundler/webpack/common/libAlias.js +31 -0
  32. package/packages/client_build_tool/lib/shared/bundler/webpack/common/nameTemplates.js +51 -0
  33. package/packages/client_build_tool/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +21 -0
  34. package/packages/client_build_tool/lib/shared/bundler/webpack/cssLoaders.js +16 -0
  35. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin.js +111 -0
  36. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/EFCPlugin.js +1 -0
  37. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ContributionGuide.md +11 -0
  38. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +136 -0
  39. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nSplit.md +95 -0
  40. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/README.md +25 -0
  41. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +29 -0
  42. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +24 -0
  43. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nDependency.js +99 -0
  44. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +81 -0
  45. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nModule.js +201 -0
  46. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +401 -0
  47. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +67 -0
  48. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +23 -0
  49. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +29 -0
  50. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +49 -0
  51. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +77 -0
  52. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +63 -0
  53. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +19 -0
  54. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +31 -0
  55. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +127 -0
  56. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RTLSplitPlugin.js +1 -0
  57. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +63 -0
  58. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +89 -0
  59. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtrSplit.md +34 -0
  60. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +15 -0
  61. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +155 -0
  62. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin.js +49 -0
  63. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_postcss_loaders/ExcludePlugin.js +58 -0
  64. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_postcss_loaders/RTLSplitPlugin.js +139 -0
  65. package/packages/client_build_tool/lib/shared/bundler/webpack/devServerConfig.js +34 -0
  66. package/packages/client_build_tool/lib/shared/bundler/webpack/getCSSLoaders.js +30 -0
  67. package/packages/client_build_tool/lib/shared/bundler/webpack/jsLoaders.js +17 -0
  68. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +14 -0
  69. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +24 -0
  70. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +18 -0
  71. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +21 -0
  72. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +138 -0
  73. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +83 -0
  74. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +23 -0
  75. package/packages/client_build_tool/lib/shared/bundler/webpack/loaders/workerLoader.js +133 -0
  76. package/packages/client_build_tool/lib/shared/bundler/webpack/optimizationConfig.js +39 -0
  77. package/packages/client_build_tool/lib/shared/bundler/webpack/outputConfig.js +28 -0
  78. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +18 -0
  79. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configCopyThirdpartyFile.js +38 -0
  80. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +24 -0
  81. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +28 -0
  82. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +35 -0
  83. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +16 -0
  84. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +23 -0
  85. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +19 -0
  86. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +27 -0
  87. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +18 -0
  88. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configUglifyCSSPlugin.js +15 -0
  89. package/packages/client_build_tool/lib/shared/bundler/webpack/plugins.js +39 -0
  90. package/packages/client_build_tool/lib/shared/bundler/webpack/postcssPlugins.js +36 -0
  91. package/packages/client_build_tool/lib/shared/bundler/webpack/resolvers.js +42 -0
  92. package/packages/client_build_tool/lib/shared/bundler/webpack/splitChunksConfig.js +12 -0
  93. package/packages/client_build_tool/lib/shared/bundler/webpack/webpack.dev.config.js +17 -0
  94. package/packages/client_build_tool/lib/shared/bundler/webpack/webpackBuild.js +24 -0
  95. package/packages/client_build_tool/lib/shared/bundler/webpack/webpackConfig.js +50 -0
  96. package/packages/client_build_tool/lib/shared/commands-utlis/doBasicRequiermentCheck.js +16 -0
  97. package/packages/client_build_tool/lib/shared/commands-utlis/getCliPath.js +38 -0
  98. package/packages/client_build_tool/lib/shared/commands-utlis/index.js +29 -0
  99. package/packages/client_build_tool/lib/shared/commands-utlis/log.js +13 -0
  100. package/packages/client_build_tool/lib/shared/commands-utlis/readArgsFormCommandLine.js +11 -0
  101. package/packages/client_build_tool/lib/shared/commands-utlis/readOptionFormCommandLine.js +11 -0
  102. package/packages/client_build_tool/lib/shared/commands-utlis/spanSync.js +35 -0
  103. package/packages/client_build_tool/lib/shared/constants.js +33 -0
  104. package/packages/client_build_tool/lib/shared/schemas/applyValuesToShema.js +37 -0
  105. package/packages/client_build_tool/lib/shared/schemas/cliArgsToObject.js +37 -0
  106. package/packages/client_build_tool/lib/shared/schemas/defaultConfigValues.js +119 -0
  107. package/packages/client_build_tool/lib/shared/schemas/deprecatedOptionsHandler.js +65 -0
  108. package/packages/client_build_tool/lib/shared/schemas/getCWD.js +23 -0
  109. package/packages/client_build_tool/lib/shared/schemas/getNpmVersion.js +21 -0
  110. package/packages/client_build_tool/lib/shared/schemas/npmConfigToObject.js +32 -0
  111. package/packages/client_build_tool/lib/shared/schemas/oldDefaultConfigValues.js +480 -0
  112. package/packages/client_build_tool/lib/shared/schemas/readOptions.js +55 -0
  113. package/packages/client_build_tool/lib/shared/schemas/readOptionsForPackageJson.js +26 -0
  114. package/packages/client_build_tool/lib/shared/schemas/readOptionsOld.js +152 -0
  115. package/packages/client_build_tool/lib/shared/server/cert/Tsicsezwild-22-23.crt +37 -0
  116. package/packages/client_build_tool/lib/shared/server/cert/Tsicsezwild-22-23.key +27 -0
  117. package/packages/client_build_tool/lib/shared/server/configWebpackDevMiddleware.js +40 -0
  118. package/packages/client_build_tool/lib/shared/server/corsHandleing.js +28 -0
  119. package/packages/client_build_tool/lib/shared/server/getIp.js +30 -0
  120. package/packages/client_build_tool/lib/shared/server/getServerURL.js +29 -0
  121. package/packages/client_build_tool/lib/shared/server/httpsOptions.js +53 -0
  122. package/packages/client_build_tool/lib/shared/server/initExpressApp.js +19 -0
  123. package/packages/client_build_tool/lib/shared/server/initialHTMLHandling.js +66 -0
  124. package/packages/client_build_tool/lib/shared/server/serveContextFiles.js +24 -0
  125. package/packages/client_build_tool/lib/shared/server/serverBywebpackDevMiddleware.js +40 -0
  126. package/packages/client_build_tool/lib/shared/server/startHttpServer.js +26 -0
  127. package/packages/client_build_tool/lib/shared/server/startHttpsServer.js +34 -0
  128. package/packages/client_build_tool/lib/shared/server/unwanted/addHttp2Server.js +41 -0
  129. package/packages/client_build_tool/lib/shared/server/unwanted/configWebpackDevMiddleware.js +44 -0
  130. package/packages/client_build_tool/lib/shared/server/unwanted/devServerUtlis.js +1 -0
  131. package/packages/client_build_tool/lib/shared/server/unwanted/mockApiSupport.js +19 -0
  132. package/packages/client_build_tool/lib/shared/server/unwanted/webpackConfig.js +32 -0
  133. package/packages/client_build_tool/lib/shared/server/unwanted/websocketMockSetup.js +48 -0
  134. package/packages/client_build_tool/lib/shared/server/urlConcat.js +25 -0
  135. package/packages/client_build_tool/lib/shared/utils/utils.js +1 -0
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectI18nKeysfromAST = collectI18nKeysfromAST;
7
+ exports.collectI18nKeysfromComments = collectI18nKeysfromComments;
8
+
9
+ var _estreeWalker = require("estree-walker");
10
+
11
+ // const { walk } = require('estree-walker');
12
+ function collectI18nKeysfromAST(ast, allI18n) {
13
+ let i18nKeys = {};
14
+ (0, _estreeWalker.walk)(ast, {
15
+ enter: function (node) {
16
+ if (node.type === 'Literal') {
17
+ if ((node.raw[0] === '\'' || node.raw[0] === '"') && Object.hasOwnProperty.call(allI18n, node.value)) {
18
+ i18nKeys[node.value] = allI18n[node.value];
19
+ }
20
+ }
21
+ }
22
+ });
23
+ return Object.keys(i18nKeys);
24
+ }
25
+
26
+ const prefixI18nComment = 'I18N';
27
+ const prefixI18nComment1 = 'dynamic-i18n-key';
28
+
29
+ function getI18nKeysFromComment(comment) {
30
+ let commentString = comment.value.trim();
31
+ let i18nKeyStr;
32
+
33
+ if (commentString.startsWith(prefixI18nComment)) {
34
+ i18nKeyStr = commentString.slice(prefixI18nComment.length).trim();
35
+ } else if (commentString.startsWith(prefixI18nComment1)) {
36
+ i18nKeyStr = commentString.slice(prefixI18nComment1.length).trim();
37
+ }
38
+
39
+ if (!i18nKeyStr) {
40
+ return [];
41
+ }
42
+
43
+ const i18nKeys = i18nKeyStr.split(',');
44
+ return i18nKeys;
45
+ } // export function fromComments(comments, allI18n) {
46
+
47
+
48
+ function collectI18nKeysfromComments(comments, allI18n) {
49
+ // TODO: need to implement
50
+ let i18nKeys = {};
51
+
52
+ for (let comment of comments) {
53
+ let keys = getI18nKeysFromComment(comment);
54
+
55
+ for (let key of keys) {
56
+ if (key && allI18n[key]) {
57
+ i18nKeys[key] = allI18n[key];
58
+ }
59
+ }
60
+ }
61
+
62
+ return Object.keys(i18nKeys);
63
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.REGEXP_CONTENTHASH = void 0;
7
+ exports.hasContentHash = hasContentHash;
8
+ // export const REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi;
9
+ // export const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi;
10
+ // export const REGEXP_NAME = /\[name\]/gi;
11
+ // export const REGEXP_PLACEHOLDERS = /\[(name|id|chunkhash)\]/gi;
12
+ // TODO: want to choose file type for i18n load
13
+ const REGEXP_CONTENTHASH = /\[contenthash(?::(\d+))?\]/gi;
14
+ exports.REGEXP_CONTENTHASH = REGEXP_CONTENTHASH;
15
+
16
+ function hasContentHash(filenameTemplate) {
17
+ REGEXP_CONTENTHASH.lastIndex = 0;
18
+ return REGEXP_CONTENTHASH.test(filenameTemplate);
19
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _collectI18nKeys = require("./collectI18nKeys");
8
+
9
+ Object.keys(_collectI18nKeys).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _collectI18nKeys[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _collectI18nKeys[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _propertiesUtils = require("./propertiesUtils");
21
+
22
+ Object.keys(_propertiesUtils).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _propertiesUtils[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _propertiesUtils[key];
29
+ }
30
+ });
31
+ });
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAllI18n = getAllI18n;
7
+ exports.getPropertiesAsJSON = getPropertiesAsJSON;
8
+ exports.jsonToString = jsonToString;
9
+
10
+ var _fs = require("fs");
11
+
12
+ var _path = require("path");
13
+
14
+ function isComment(line) {
15
+ return line[0] === '#';
16
+ }
17
+
18
+ function getPropertiesAsJSON(filePath) {
19
+ try {
20
+ const data = (0, _fs.readFileSync)(filePath);
21
+ const source = data.toString();
22
+ const i18nObj = {};
23
+ source.split(/\r?\n\r?/).forEach(fline => {
24
+ const line = fline.trim();
25
+
26
+ if (!line || isComment(line)) {
27
+ return;
28
+ }
29
+
30
+ const ind = line.indexOf('=');
31
+ const key = line.slice(0, ind).replace(/\\ /g, ' ');
32
+ const value = line.slice(ind + 1);
33
+
34
+ if (key && value) {
35
+ i18nObj[key] = value;
36
+ }
37
+ }, {});
38
+ return i18nObj;
39
+ } catch (err) {
40
+ return {};
41
+ }
42
+ } // TODO: need to make it as custom option and dynamic
43
+
44
+
45
+ function getLang(file) {
46
+ const underScoreIndex = file.indexOf('_');
47
+ let language = 'en_US';
48
+
49
+ if (underScoreIndex !== -1) {
50
+ language = file.substring(underScoreIndex + 1);
51
+ language = language.slice(0, language.indexOf('.'));
52
+ }
53
+
54
+ return language;
55
+ }
56
+
57
+ function getAllI18n({
58
+ folderPath,
59
+ disableDefault,
60
+ jsResourceI18nKeys,
61
+ exclude = /^[^_]+$/,
62
+ include = /\.properties$/
63
+ }) {
64
+ try {
65
+ const files = (0, _fs.readdirSync)(folderPath, 'utf8');
66
+ const allLangI18n = {};
67
+ const context = (0, _path.join)(process.cwd(), folderPath);
68
+ files.forEach(file => {
69
+ const filePath = (0, _path.join)(context, file);
70
+
71
+ if (exclude.test(filePath) || !include.test(filePath)) {
72
+ return;
73
+ }
74
+
75
+ const i18n = getPropertiesAsJSON(filePath);
76
+ allLangI18n[getLang(file)] = disableDefault ? i18n : { ...jsResourceI18nKeys,
77
+ ...i18n
78
+ };
79
+ });
80
+ return allLangI18n;
81
+ } catch (err) {
82
+ console.log(err);
83
+ return {};
84
+ }
85
+ }
86
+
87
+ function jsonToString(json, keySeperator) {
88
+ let str = '{';
89
+ const keys = Object.keys(json);
90
+ keys.forEach((key, i) => {
91
+ const value = json[key];
92
+
93
+ if (!value) {
94
+ return;
95
+ }
96
+
97
+ str += `"${keySeperator ? key.replace(/(\.|\\(\s+))/g, keySeperator) : key}":"${value.replace(/.?"/g, match => {
98
+ if (match[0] === '\\') {
99
+ return match;
100
+ }
101
+
102
+ if (match.length === 2) {
103
+ return `${match[0]}\\${match[1]}`;
104
+ }
105
+
106
+ return `\\${match}`;
107
+ }).replace(/(\r\n|\n|\r)/g, '')}"`;
108
+
109
+ if (i !== keys.length - 1) {
110
+ str += ',';
111
+ }
112
+ });
113
+ str += '}';
114
+ return str;
115
+ }
116
+ /**
117
+ * not useable due to special charector
118
+ *
119
+ return `{${Object.keys(data).map(key => `"${key}": "${data[key]}"`).join(",")}}`
120
+ // return JSON.stringify(data);
121
+ let str = "{";
122
+ for (const key of Object.keys(data)) {
123
+ str+= `"${key}": "${data[key]}",`
124
+ }
125
+ str+="}";
126
+ return str;
127
+ */
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
+
10
+ var _JavascriptModulesPlugin = _interopRequireDefault(require("webpack/lib/javascript/JavascriptModulesPlugin"));
11
+
12
+ var _replaceCssDirTemplate = require("./replaceCssDirTemplate");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ // const HtmlWebpackPlugin = require('html-webpack-plugin');
17
+ // import { JavascriptModulesPlugin } from 'webpack';
18
+ const pluginName = 'OverwriteCssPathForRTL';
19
+
20
+ class OverwriteCssPathForRTL {
21
+ constructor(options = {
22
+ dirVarName: 'document.dir'
23
+ }) {
24
+ this.dirVarName = options.dirVarName || 'document.dir';
25
+ this.templateLabel = options.templateLabel || '{{--dir}}';
26
+ }
27
+
28
+ overwriteCssPathinHTML(compilation) {
29
+ // NOTE: need to reconsider It is not working as expected
30
+ _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync(pluginName, (data, cb) => {
31
+ const {
32
+ assets
33
+ } = data;
34
+ cb(null, { ...data,
35
+ assets: { ...assets,
36
+ css: assets.css && (0, _replaceCssDirTemplate.replaceCssDirTemplateMapper)(assets.css, this.templateLabel)
37
+ }
38
+ });
39
+ });
40
+ }
41
+
42
+ overwriteCssPathinRequireEnsure(compilation, compiler) {
43
+ const {
44
+ RawSource
45
+ } = compiler.webpack.sources;
46
+
47
+ _JavascriptModulesPlugin.default.getCompilationHooks(compilation).renderMain.tap(pluginName, source => {
48
+ const templateText = `"+(${this.dirVarName} === "rtl" ? ".rtl": ".ltr")+"`;
49
+ const replacedStr = source.source().replace(/\[dir\]/g, templateText);
50
+ return new RawSource(replacedStr);
51
+ });
52
+ }
53
+
54
+ apply(compiler) {
55
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
56
+ this.overwriteCssPathinHTML(compilation);
57
+ this.overwriteCssPathinRequireEnsure(compilation, compiler);
58
+ });
59
+ }
60
+
61
+ }
62
+
63
+ exports.default = OverwriteCssPathForRTL;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RtlCssPlugin = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _webpack = require("webpack");
11
+
12
+ var _OverwriteCssPathForRTL = _interopRequireDefault(require("./OverwriteCssPathForRTL"));
13
+
14
+ var _RTLSplitPlugin = require("../../custom_postcss_loaders/RTLSplitPlugin");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ // import HtmlWebpackPlugin from 'html-webpack-plugin';
19
+ // import rtlcss from 'rtlcss';
20
+ const pluginName = 'RtlCssPlugin';
21
+
22
+ const isCss = filename => _path.default.extname(filename) === '.css';
23
+
24
+ const isDirRelatedCss = filename => filename.includes('[dir]');
25
+
26
+ class RtlCssPlugin {
27
+ constructor(options = {}) {
28
+ /**
29
+ * @typedef {Object} Options
30
+ * @property {String} dirVarName
31
+ * @property {Boolean} sourcemap
32
+ * @property {Object} config
33
+ */
34
+ this.options = {
35
+ // dirVarName: options.dirVarName || 'document.dir',
36
+ sourcemap: options.sourcemap,
37
+ config: options.config
38
+ };
39
+ this.templateLabel = options.templateLabel || '{{--dir}}';
40
+ this.dirVarName = options.dirVarName || 'document.dir';
41
+ this.rtlSplitOptions = {
42
+ disableMinifySelector: options.disableMinifySelector
43
+ };
44
+ }
45
+
46
+ apply(compiler) {
47
+ const {
48
+ RawSource
49
+ } = compiler.webpack.sources;
50
+ new _OverwriteCssPathForRTL.default({
51
+ templateLabel: this.templateLabel,
52
+ dirVarName: this.dirVarName
53
+ }).apply(compiler); // const { filename, sourcemap, config } = this.options;
54
+ // const { devtool } = compiler.options;
55
+ // const postcssOptions = {
56
+ // map: (sourcemap === undefined && !!devtool) || !!sourcemap
57
+ // };
58
+
59
+ compiler.hooks.compilation.tap(pluginName, compilation => {
60
+ // compilation.hooks.shouldGenerateChunkAssets.tap(pluginName, (...args) => {
61
+ // console.log('shouldGenerateChunkAssets', args);
62
+ // });
63
+ compilation.hooks.processAssets.tap({
64
+ name: pluginName,
65
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
66
+ additionalAssets: true
67
+ }, assets => {
68
+ Object.keys(assets).filter(isCss).filter(isDirRelatedCss).forEach(chunkFilename => {
69
+ const {
70
+ source: asset
71
+ } = compilation.getAsset(chunkFilename);
72
+ const sourceStr = asset.source();
73
+ const {
74
+ ltr,
75
+ rtl
76
+ } = (0, _RTLSplitPlugin.separateRtlAndLtr)(sourceStr, this.rtlSplitOptions);
77
+ const ltrFilename = chunkFilename.replace('[dir]', 'ltr');
78
+ const rtlFilename = chunkFilename.replace('[dir]', 'rtl');
79
+ compilation.deleteAsset(chunkFilename);
80
+ compilation.emitAsset(ltrFilename, new RawSource(ltr));
81
+ compilation.emitAsset(rtlFilename, new RawSource(rtl));
82
+ });
83
+ });
84
+ });
85
+ }
86
+
87
+ }
88
+
89
+ exports.RtlCssPlugin = RtlCssPlugin;
@@ -0,0 +1,34 @@
1
+ # RTL Split
2
+
3
+ we are doing in build time generating rtl related css code by using @zohodesk/postcss-rt npm.
4
+ It was automated, That postcss plugin create rtl reacted css and put them into same file, with css selector [dir=rtl] and ltr realted css with [dir=ltr].
5
+ Here is problem mostly no one need rtl and ltr related css at the same time in browser,
6
+ we are try to split them by [dir] and load which type of css is needed.
7
+ For this purpose we created RTL Split Plugin
8
+
9
+ # To Try it out rtl-ltr split
10
+
11
+ ### how to use this feature?
12
+
13
+ to use this feature use have give the below oprtions
14
+ `package.json`
15
+
16
+ ```json
17
+ {
18
+ /// ...some things
19
+ "react-cli": {
20
+ // ...some things
21
+ "css": {
22
+ "plugins": {
23
+ "rtlSplit": {
24
+ "enableRTLSplit": true,
25
+ "templateLabel": "{{--dir}}", // this is for html template css file path dir template
26
+ "disableMinifySelector": false,
27
+ "dirVarName": "document.dir" // this will be used for download css based on dir
28
+ }
29
+ }
30
+ }
31
+ // ...some things
32
+ }
33
+ }
34
+ ```
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.replaceCssDirTemplate = replaceCssDirTemplate;
7
+ exports.replaceCssDirTemplateMapper = replaceCssDirTemplateMapper;
8
+
9
+ function replaceCssDirTemplate(filePath, cssDirTemplate) {
10
+ return filePath.replace('[dir]', cssDirTemplate);
11
+ }
12
+
13
+ function replaceCssDirTemplateMapper(assets, cssDirTemplate) {
14
+ return assets.map(filePath => replaceCssDirTemplate(filePath, cssDirTemplate));
15
+ }
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+
10
+ var _path = _interopRequireDefault(require("path"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ //import { getI18nFileUrlPathTemplate } from './I18nSplitPlugin/utils/getI18nFileUrlPathTemplate';
15
+ //import { getOptions } from '../utils';
16
+ //import I18nKeysIdentifer from './I18nSplitPlugin/I18nKeysIdentifer';
17
+ //import { replaceCssDirTemplateMapper } from './RtlSplitPlugin/replaceCssDirTemplate';
18
+ // const {
19
+ // css: { enableRTLSplit },
20
+ // i18n: { chunkSplitEnable }
21
+ // } = getOptions();
22
+ class ServiceWorkerPlugin {
23
+ constructor(options) {
24
+ this.i18nFileNameTemplate = options.i18nFileNameTemplate;
25
+ this.fileName = options.fileName;
26
+ this.serviceWorkerPath = options.filePath;
27
+ this.writePath = options.exitPath;
28
+ this.replaceText = options.replaceText; // this.publicPaths = options.publicPaths;
29
+ }
30
+
31
+ isInitialChunk(chunk) {
32
+ if ('canBeInitial' in chunk) {
33
+ return chunk.canBeInitial();
34
+ }
35
+
36
+ return chunk.isInitial();
37
+ }
38
+
39
+ apply(compiler) {
40
+ compiler.hooks.emit.tap('ServiceWorkerPlugin', compilation => {
41
+ _fs.default.readFile(this.serviceWorkerPath, 'utf-8', (err, data) => {
42
+ if (err) {
43
+ throw new Error(err);
44
+ } else {
45
+ /* const extractedChunks = compilation.chunks.filter(chunk => {
46
+ if ('canBeInitial' in chunk) {
47
+ return chunk.canBeInitial();
48
+ }
49
+ return chunk.isInitial();
50
+ }); */
51
+ // let [js, css, , , i18nPublicPath] = this.publicPaths;
52
+ // let initialChunkUrls = [];
53
+ let allChunkUrls = [];
54
+ let allI18nAssets = [];
55
+ let entrypoint = compilation.entrypoints.get('main');
56
+ let initialChunkUrls = entrypoint.getFiles();
57
+ const cssDirTemplate = '@dir@';
58
+ /**
59
+ * NOTE:
60
+ * if chunkSplitEnable is false means,
61
+ * serviceWorker will get i18n files path for html
62
+ */
63
+ // let initalI18nAssets = chunkSplitEnable
64
+ // ? entrypoint.chunks
65
+ // //.filter(chunk => I18nKeysIdentifer.isChunkHasI18n(chunk))
66
+ // .map(chunk =>
67
+ // getI18nFileUrlPathTemplate(
68
+ // compilation,
69
+ // chunk,
70
+ // this.i18nFileNameTemplate,
71
+ // '@locale@'
72
+ // )
73
+ // )
74
+ // : [];
75
+
76
+ let initalI18nAssets = []; //chunkSplitEnable &&
77
+
78
+ compilation.chunks.filter(c => !this.isInitialChunk(c)) //.filter(chunk => I18nKeysIdentifer.isChunkHasI18n(chunk))
79
+ .forEach(chunk => {
80
+ // let isInitial = this.isInitialChunk(chunk);
81
+ allChunkUrls = allChunkUrls.concat(chunk.files); // allI18nAssets.push(
82
+ // getI18nFileUrlPathTemplate(
83
+ // compilation,
84
+ // chunk,
85
+ // this.i18nFileNameTemplate,
86
+ // '@locale@'
87
+ // )
88
+ // );
89
+ });
90
+ /** Removing source map files from getting added */
91
+
92
+ initialChunkUrls = initialChunkUrls.filter(fileName => !fileName.endsWith('.map'));
93
+ allChunkUrls = allChunkUrls.filter(fileName => !fileName.endsWith('.map')); // if (enableRTLSplit) {
94
+ // initialChunkUrls = replaceCssDirTemplateMapper(
95
+ // initialChunkUrls,
96
+ // cssDirTemplate
97
+ // );
98
+ // allChunkUrls = replaceCssDirTemplateMapper(
99
+ // allChunkUrls,
100
+ // cssDirTemplate
101
+ // );
102
+ // }
103
+
104
+ let mod = data.replace(this.replaceText, `self.assets = ${JSON.stringify(initialChunkUrls.concat(initalI18nAssets))};self.allChunks = ${JSON.stringify(allChunkUrls.concat(allI18nAssets))};`);
105
+
106
+ if (!_fs.default.existsSync(this.writePath)) {
107
+ _fs.default.mkdirSync(this.writePath, {
108
+ recursive: true
109
+ });
110
+ }
111
+
112
+ _fs.default.writeFileSync(_path.default.join(this.writePath, `${this.fileName}`), mod);
113
+ }
114
+ });
115
+ });
116
+ }
117
+
118
+ } // compiler.hooks.thisCompilation.tap('AddAssetPlugin', compilation => {
119
+ // compilation.hooks.processAssets.tapPromise(tapOptions, async () => {
120
+ // let source;
121
+ // if (typeof this.source === 'string') {
122
+ // if (compilation.getAsset(this.filePath)) {
123
+ // // Skip emitting the asset again because it's immutable
124
+ // return;
125
+ // }
126
+ // source = this.source;
127
+ // } else {
128
+ // source = await this.source(compilation);
129
+ // }
130
+ // compilation.emitAsset(this.filePath, new RawSource(source));
131
+ // });
132
+ // });
133
+ // getContentHash(compiler, compilation, source) {
134
+ // const { outputOptions } = compilation;
135
+ // const { hashDigest, hashDigestLength, hashFunction, hashSalt } =
136
+ // outputOptions;
137
+ // const hash = compiler.webpack.util.createHash(
138
+ // /** @type {string} */ (hashFunction)
139
+ // );
140
+ // if (hashSalt) {
141
+ // hash.update(hashSalt);
142
+ // }
143
+ // hash.update(source);
144
+ // const fullContentHash = hash.digest(hashDigest);
145
+ // return fullContentHash.toString().slice(0, hashDigestLength);
146
+ // }
147
+ // const contentHash = CopyPlugin.getContentHash(
148
+ // compiler,
149
+ // compilation,
150
+ // source.buffer()
151
+ // );
152
+ //hash same as index.html file ??
153
+
154
+
155
+ exports.default = ServiceWorkerPlugin;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _uglifycss = _interopRequireDefault(require("uglifycss"));
9
+
10
+ var _webpack = require("webpack");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /* eslint-disable class-methods-use-this */
15
+ // import { RawSource } from 'webpack-sources';
16
+ const pluginName = 'UglifyCSSPlugin'; // TODO: Check for css minimizer plugin
17
+
18
+ class UglifyCSSPlugin {
19
+ apply(compiler) {
20
+ const {
21
+ RawSource
22
+ } = compiler.webpack.sources;
23
+ compiler.hooks.emit.tap(pluginName, compilation => {
24
+ compilation.hooks.processAssets.tapAsync({
25
+ name: pluginName,
26
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
27
+ }, assets => {
28
+ Object.keys(assets).filter(filename => /\.css$/.test(filename)).forEach(filename => {
29
+ try {
30
+ let asset = compilation.assets[filename].source();
31
+
32
+ if (typeof asset !== 'string') {
33
+ asset = asset.toString();
34
+ }
35
+
36
+ const result = _uglifycss.default.processString(asset);
37
+
38
+ compilation.updateAsset(filename, new RawSource(result));
39
+ } catch (e) {
40
+ compilation.errors.push(e);
41
+ }
42
+ });
43
+ });
44
+ });
45
+ }
46
+
47
+ }
48
+
49
+ exports.default = UglifyCSSPlugin;