@zohodesk/react-cli 0.0.1-beta.17 → 0.0.1-beta.170

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 (292) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +49 -10
  3. package/.prettierrc +6 -0
  4. package/CHANGELOG.md +5 -0
  5. package/README.md +855 -0
  6. package/bin/cli.js +215 -46
  7. package/cert/Tsicsezwild-22-23.crt +37 -0
  8. package/cert/Tsicsezwild-22-23.key +27 -0
  9. package/docs/CustomChunks.md +26 -0
  10. package/docs/DevStart.md +18 -0
  11. package/docs/HoverActive.md +12 -0
  12. package/docs/InstallNode.md +28 -0
  13. package/docs/TODOS.md +10 -0
  14. package/docs/ValueReplacer.md +60 -0
  15. package/docs/warnings_while_install.txt +35 -0
  16. package/files/eslintrc.js +62 -0
  17. package/files/prettierrc.js +3 -0
  18. package/lib/babel/cmjs-plugins-presets.js +24 -0
  19. package/lib/babel/es-plugins-presets.js +34 -0
  20. package/lib/common/getEntries.js +33 -46
  21. package/lib/common/getPublicPathConfig.js +40 -0
  22. package/lib/common/index.js +24 -19
  23. package/lib/common/splitChunks.js +110 -25
  24. package/lib/common/sslcertUpdater.js +59 -0
  25. package/lib/common/templateParameters.js +25 -0
  26. package/lib/common/testPattern.js +69 -0
  27. package/lib/common/valueReplacer.js +55 -0
  28. package/lib/configs/jest.config.js +31 -27
  29. package/lib/configs/libAlias.js +31 -0
  30. package/lib/configs/webpack.component.umd.config.js +46 -53
  31. package/lib/configs/webpack.css.umd.config.js +47 -46
  32. package/lib/configs/webpack.dev.config.js +98 -84
  33. package/lib/configs/webpack.docs.config.js +64 -57
  34. package/lib/configs/webpack.impact.config.js +108 -0
  35. package/lib/configs/webpack.prod.config.js +146 -104
  36. package/lib/hooks/docsProptypeHook.js +32 -38
  37. package/lib/jest/commitedFilesResult.js +144 -71
  38. package/lib/jest/coverageCollector.js +68 -35
  39. package/lib/jest/jsonMaker.js +54 -0
  40. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  41. package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
  42. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  43. package/lib/jest/result.js +92 -42
  44. package/lib/jest/run.js +75 -28
  45. package/lib/jest/setup.js +103 -102
  46. package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
  47. package/lib/loaderUtils/getCSSLoaders.js +113 -0
  48. package/lib/loaderUtils/getDevJsLoaders.js +35 -23
  49. package/lib/loaderUtils/index.js +14 -7
  50. package/lib/loaders/docsLoader.js +15 -15
  51. package/lib/loaders/docsPropsLoader.js +14 -17
  52. package/lib/loaders/fileBountryLoader.js +17 -0
  53. package/lib/loaders/fileLoader.js +47 -38
  54. package/lib/loaders/scriptInstrumentLoader.js +23 -20
  55. package/lib/loaders/selectorMappingLoader.js +75 -0
  56. package/lib/loaders/workerLoader.js +136 -0
  57. package/lib/middlewares/HMRMiddleware.js +90 -72
  58. package/lib/middlewares/SSTMiddleware.js +21 -0
  59. package/lib/pluginUtils/getDevPlugins.js +177 -30
  60. package/lib/pluginUtils/getDocsPlugins.js +36 -15
  61. package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
  62. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  63. package/lib/pluginUtils/getProdPlugins.js +244 -37
  64. package/lib/pluginUtils/getServerPlugins.js +8 -11
  65. package/lib/pluginUtils/getUMDCSSPlugins.js +14 -18
  66. package/lib/pluginUtils/getUMDComponentPlugins.js +14 -9
  67. package/lib/pluginUtils/index.js +36 -43
  68. package/lib/plugins/CdnChangePlugin.js +77 -0
  69. package/lib/plugins/CleanupStatsPlugin.js +28 -0
  70. package/lib/plugins/EFCPlugin.js +241 -0
  71. package/lib/plugins/EFCPlugin.md +6 -0
  72. package/lib/plugins/EFCTemplatePlugin.js +151 -0
  73. package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
  74. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  75. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  76. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  77. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  78. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  79. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -0
  80. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  81. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  82. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  83. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  84. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  85. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  86. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  87. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  88. package/lib/plugins/ManifestPlugin.js +86 -0
  89. package/lib/plugins/ModuleStatsPlugin.js +98 -97
  90. package/lib/plugins/OptimizeJSPlugin.js +41 -0
  91. package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
  92. package/lib/plugins/PublicPathChangePlugin.js +226 -0
  93. package/lib/plugins/ReportGeneratePlugin.js +181 -0
  94. package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
  95. package/lib/plugins/ResourceHintsPlugin.js +67 -0
  96. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
  97. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
  98. package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
  99. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
  100. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  101. package/lib/plugins/ServiceWorkerPlugin.js +107 -0
  102. package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
  103. package/lib/plugins/SourceMapHookPlugin.js +25 -59
  104. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  105. package/lib/plugins/UglifyCSSPlugin.js +39 -0
  106. package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
  107. package/lib/plugins/index.js +127 -37
  108. package/lib/plugins/libraryImpactPlugin.js +190 -0
  109. package/lib/plugins/webpackwatchrunplugin.js +26 -0
  110. package/lib/postcss-plugins/ExcludePlugin.js +23 -0
  111. package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
  112. package/lib/postcss-plugins/ValueReplacer.js +46 -0
  113. package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +22 -0
  114. package/lib/postcss-plugins/__test__/test1Input.css +39 -0
  115. package/lib/postcss-plugins/__test__/test1Output.css +39 -0
  116. package/lib/postcss-plugins/hoverActivePlugin.js +365 -0
  117. package/lib/postcss-plugins/variableModifier.js +243 -0
  118. package/lib/schemas/index.js +534 -66
  119. package/lib/servers/clusterHubServer.js +22 -26
  120. package/lib/servers/devBuild.js +102 -0
  121. package/lib/servers/docsServer.js +3 -5
  122. package/lib/servers/docsServerCore.js +94 -79
  123. package/lib/servers/getCliPath.js +28 -0
  124. package/lib/servers/helpServer.js +19 -21
  125. package/lib/servers/httpsOptions.js +18 -0
  126. package/lib/servers/impactServer.js +123 -115
  127. package/lib/servers/mockserver.js +44 -0
  128. package/lib/servers/nowatchserver.js +200 -0
  129. package/lib/servers/scrServer.js +147 -0
  130. package/lib/servers/server.js +134 -132
  131. package/lib/servers/ssServer.js +106 -70
  132. package/lib/sh/reportPublish.sh +16 -10
  133. package/lib/templates/CoverageScriptTemplate.js +45 -18
  134. package/lib/templates/WMSTemplate.js +17 -18
  135. package/lib/templates/linterConstant.js +10 -0
  136. package/lib/utils/babelPresets.js +12 -4
  137. package/lib/utils/buildstats.html +148 -0
  138. package/lib/utils/clean.js +12 -11
  139. package/lib/utils/copy.js +16 -109
  140. package/lib/utils/copyTimezones.js +21 -0
  141. package/lib/utils/createEventStream.js +24 -19
  142. package/lib/utils/cssClassNameGenerate.js +77 -0
  143. package/lib/utils/cssURLReplacer.js +136 -0
  144. package/lib/utils/dependencyPostPublish.js +42 -0
  145. package/lib/utils/fileUtils.js +125 -0
  146. package/lib/utils/folderIterator.js +47 -0
  147. package/lib/utils/getComponents.js +126 -0
  148. package/lib/utils/getCurrentBranch.js +11 -17
  149. package/lib/utils/getDependenciesImpactList.js +151 -0
  150. package/lib/utils/getHash.js +26 -0
  151. package/lib/utils/getIp.js +20 -0
  152. package/lib/utils/getOptions.js +113 -28
  153. package/lib/utils/getServerURL.js +25 -8
  154. package/lib/utils/index.js +283 -68
  155. package/lib/utils/init.js +2 -2
  156. package/lib/utils/initPreCommitHook.js +47 -27
  157. package/lib/utils/jsonHelper.js +106 -0
  158. package/lib/utils/libraryImpactConfig.js +63 -0
  159. package/lib/utils/lint/addScripts.js +27 -0
  160. package/lib/utils/lint/checkExistingConfig.js +67 -0
  161. package/lib/utils/lint/copyConfigs.js +24 -0
  162. package/lib/utils/lint/index.js +54 -0
  163. package/lib/utils/lint/lintScripts.js +11 -0
  164. package/lib/utils/lint/lintSetup.js +31 -0
  165. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  166. package/lib/utils/lint/question.js +30 -0
  167. package/lib/utils/lintReporter.js +142 -0
  168. package/lib/utils/mailSender.js +16 -25
  169. package/lib/utils/pullOrigin.js +28 -0
  170. package/lib/utils/reinstallDependencies.js +133 -0
  171. package/lib/utils/removeAttributes.js +25 -23
  172. package/lib/utils/repoClone.js +59 -63
  173. package/lib/utils/request.js +64 -77
  174. package/lib/utils/resultSchema.json +73 -0
  175. package/lib/utils/rtl.js +59 -0
  176. package/lib/utils/setEnvVariables.js +13 -0
  177. package/lib/utils/ssTestHack.js +48 -0
  178. package/lib/utils/switchBranch.js +28 -0
  179. package/lib/utils/urlConcat.js +22 -0
  180. package/lib/utils/useExitCleanup.js +55 -0
  181. package/npm8.md +9 -0
  182. package/package.json +96 -64
  183. package/postpublish.js +6 -0
  184. package/templates/app/.eslintrc.js +140 -0
  185. package/templates/app/README.md +12 -12
  186. package/templates/app/app/index.html +24 -8
  187. package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
  188. package/templates/app/app/properties/i18nkeys.json +3 -3
  189. package/templates/app/docs/all.html +69 -69
  190. package/templates/app/mockapi/index.js +18 -13
  191. package/templates/app/package.json +37 -17
  192. package/templates/app/src/actions/SampleActions/index.js +37 -0
  193. package/templates/app/src/actions/index.js +65 -0
  194. package/templates/app/src/appUrls.js +19 -0
  195. package/templates/app/src/components/Alert/Alert.js +134 -0
  196. package/templates/app/src/components/Alert/Alert.module.css +79 -0
  197. package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
  198. package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
  199. package/templates/app/src/components/Sample/Sample.module.css +11 -0
  200. package/templates/app/src/components/Sample/SampleList.js +61 -0
  201. package/templates/app/src/components/Slider/Slider.css +41 -0
  202. package/templates/app/src/components/Slider/Slider.js +55 -0
  203. package/templates/app/src/containers/AlertContainer/index.js +15 -0
  204. package/templates/app/src/containers/AppContainer/index.js +96 -0
  205. package/templates/app/src/containers/AppContainer/index.module.css +27 -0
  206. package/templates/app/src/containers/CustomMatch/index.js +65 -0
  207. package/templates/app/src/containers/DevTools/index.js +10 -0
  208. package/templates/app/src/containers/Header/index.js +67 -0
  209. package/templates/app/src/containers/Header/index.module.css +43 -0
  210. package/templates/app/src/containers/Redirect/index.js +63 -0
  211. package/templates/app/src/containers/Redirector/index.js +47 -0
  212. package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
  213. package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
  214. package/templates/app/src/historyChange.js +5 -0
  215. package/templates/app/src/index.html +10 -0
  216. package/templates/app/src/index.js +24 -0
  217. package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
  218. package/templates/app/src/reducers/alertData.js +11 -0
  219. package/templates/app/src/reducers/index.js +6 -0
  220. package/templates/app/src/reducers/samples.js +19 -0
  221. package/templates/app/src/store/configureStore.dev.js +51 -0
  222. package/templates/app/src/store/configureStore.js +5 -0
  223. package/templates/app/src/store/configureStore.prod.js +26 -0
  224. package/templates/app/src/util/Common.js +5 -0
  225. package/templates/app/src/util/RequestAPI.js +132 -0
  226. package/templates/appold/README.md +12 -0
  227. package/templates/appold/app/index.html +8 -0
  228. package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
  229. package/templates/appold/app/properties/i18nkeys.json +3 -0
  230. package/templates/appold/docs/all.html +69 -0
  231. package/templates/appold/mockapi/index.js +13 -0
  232. package/templates/{app → appold}/mockapi/tickets.json +0 -0
  233. package/templates/appold/package.json +17 -0
  234. package/templates/appold/src/components/Text/Text.css +0 -0
  235. package/templates/appold/src/components/Text/Text.js +23 -0
  236. package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
  237. package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
  238. package/templates/appold/src/components/docs.js +1 -0
  239. package/templates/appold/src/components/index.js +5 -0
  240. package/templates/appold/src/index.js +13 -0
  241. package/templates/docs/all.html +1 -1
  242. package/templates/docs/component.html +110 -69
  243. package/templates/docs/components.html +221 -0
  244. package/templates/docs/css/component.css +12 -14
  245. package/templates/docs/css/componentTest.css +7 -0
  246. package/templates/docs/css/style.css +150 -206
  247. package/templates/docs/impactReportTemplate.html +154 -0
  248. package/templates/docs/index.html +1482 -1336
  249. package/templates/library/src/index.js +0 -0
  250. package/.npmignore +0 -3
  251. package/cert/cert.pem +0 -129
  252. package/cert/key.pem +0 -27
  253. package/lib/common/getInsertAt.js +0 -36
  254. package/lib/common/getInsertIntoFunction.js +0 -13
  255. package/lib/configs/webpack.server.config.js +0 -93
  256. package/lib/plugins/ChunkManifestReplacePlugin.js +0 -94
  257. package/lib/plugins/RuntimePublicPathPlugin.js +0 -46
  258. package/lib/rmcntrlm.sh +0 -14
  259. package/lib/servers/nodeServer.js +0 -238
  260. package/lib/templates/HMRTemplate.js +0 -256
  261. package/lib/templates/publicPathTemplate.js +0 -16
  262. package/lib/utils/setConfig.js +0 -14
  263. package/node_modules/history/CHANGES.md +0 -395
  264. package/node_modules/history/DOMUtils.js +0 -3
  265. package/node_modules/history/ExecutionEnvironment.js +0 -3
  266. package/node_modules/history/LICENSE +0 -21
  267. package/node_modules/history/LocationUtils.js +0 -3
  268. package/node_modules/history/PathUtils.js +0 -3
  269. package/node_modules/history/README.md +0 -282
  270. package/node_modules/history/cjs/history.js +0 -933
  271. package/node_modules/history/cjs/history.min.js +0 -1
  272. package/node_modules/history/createBrowserHistory.js +0 -3
  273. package/node_modules/history/createHashHistory.js +0 -3
  274. package/node_modules/history/createMemoryHistory.js +0 -3
  275. package/node_modules/history/createTransitionManager.js +0 -3
  276. package/node_modules/history/es/DOMUtils.js +0 -7
  277. package/node_modules/history/es/ExecutionEnvironment.js +0 -7
  278. package/node_modules/history/es/LocationUtils.js +0 -7
  279. package/node_modules/history/es/PathUtils.js +0 -7
  280. package/node_modules/history/es/createBrowserHistory.js +0 -7
  281. package/node_modules/history/es/createHashHistory.js +0 -7
  282. package/node_modules/history/es/createMemoryHistory.js +0 -7
  283. package/node_modules/history/es/createTransitionManager.js +0 -7
  284. package/node_modules/history/es/warnAboutDeprecatedESMImport.js +0 -35
  285. package/node_modules/history/esm/history.js +0 -904
  286. package/node_modules/history/index.js +0 -7
  287. package/node_modules/history/package.json +0 -134
  288. package/node_modules/history/umd/history.js +0 -1059
  289. package/node_modules/history/umd/history.min.js +0 -1
  290. package/node_modules/history/warnAboutDeprecatedCJSRequire.js +0 -35
  291. package/templates/app/.npmignore +0 -9
  292. package/templates/library/.npmignore +0 -9
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = require("./utils");
9
+
10
+ var _webpack = require("webpack");
11
+
12
+ var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
13
+
14
+ var _I18nFilesEmitter = _interopRequireDefault(require("./I18nFilesEmitter"));
15
+
16
+ var _I18nDownlodLogic = _interopRequireDefault(require("./I18nDownlodLogic"));
17
+
18
+ var _getI18nKeysFormModules = _interopRequireDefault(require("./utils/getI18nKeysFormModules"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ // #region initial
23
+
24
+ /**
25
+ * @TODO:
26
+ * [?] add comment line options for properties file and get all keys form property file do right way to genarate them
27
+ * [?] need to discuss with collectI18n Keys with js comment need to conform "what is the comment? "
28
+ */
29
+
30
+ /**
31
+ * Notes: this plugin has done below works
32
+ * 1. collect I18n Keys from js files and make it as Depenencies
33
+ * 2. we create file(asset) for chunk specific i18nChunk Files
34
+ * 3. create hash for the specific i18nChunk Files
35
+ * 4. write logic to requireEnsure method for dowlod I18n chunk download dynamicaly
36
+ * 5. create manifest.json file which has the mapping of chunk-locales-i18nChunkFile
37
+ * for the external referrece.
38
+ * Hints :-
39
+ * - file means your machine files
40
+ * - asset means that also file but that will create by webpack after build
41
+ */
42
+ // const getI18nLocales = require('./utils/getI18nLocales');
43
+ // const { ConcatSource, SourceMapSource, OriginalSource } = sources;
44
+ const {
45
+ createHash
46
+ } = _webpack.util;
47
+ const MODULE_TYPE = 'json/i18n';
48
+
49
+ const i18ntype = locale => `${MODULE_TYPE}/${locale}`;
50
+
51
+ const pluginName = 'i18n-plugin';
52
+ /**
53
+ * @typedef I18nPluginOptions
54
+ * @property {String} filenameTemplate this was template for i18n chunk
55
+ * @property {String} jsResource this was path for jsResource i18n file
56
+ * @property {String} propertiesFolder this was path for propertiesFolder i18n file
57
+ * @property {Boolean} disableDefault this option for disable defulat value for i18n keys, means if the language file does not have some key we don't give jsResource value
58
+ * @property {String} i18nManifestFileName this was ouput path for i18n manifest.
59
+ * @property {String} jsonpFunc this was function name, we will call that function everytime i18n chunk download.
60
+ * @property {String} localeVarName this was variable name, we will call that function everytime i18n chunk download.
61
+ *
62
+ */
63
+
64
+ class I18nPlugin {
65
+ constructor(options = {}) {
66
+ // initialize options
67
+ this.options = Object.assign({
68
+ filenameTemplate: 'i18n/[locale]/[name].i18n.js'
69
+ }, options);
70
+ const {
71
+ filenameTemplate,
72
+ publicPath,
73
+ localeVarName,
74
+ i18nManifestFileName,
75
+ disableDefault,
76
+ jsResource,
77
+ propertiesFolder,
78
+ jsonpFunc
79
+ } = this.options;
80
+ this.publicPath = publicPath; // gethere i18n keys and values
81
+
82
+ this.jsResourceI18nKeys = jsResource ? (0, _utils.getPropertiesAsJSON)(jsResource) : {};
83
+ this.allI18nObject = (0, _utils.getAllI18n)({
84
+ folderPath: propertiesFolder,
85
+ disableDefault,
86
+ jsResourceI18nKeys: this.jsResourceI18nKeys
87
+ }); // initialize base data's and plugis
88
+
89
+ this.locales = Object.keys(this.allI18nObject);
90
+ this.i18nKeysIdentifer = new _I18nKeysIdentifer.default(this.jsResourceI18nKeys);
91
+ this.i18nFilesEmitter = new _I18nFilesEmitter.default({
92
+ allI18nObject: this.allI18nObject,
93
+ locales: this.locales,
94
+ i18nManifestFileName,
95
+ filenameTemplate,
96
+ jsonpFunc
97
+ });
98
+ this.i18nDownlodLogic = new _I18nDownlodLogic.default({
99
+ filenameTemplate,
100
+ publicPath,
101
+ locales: this.locales,
102
+ localeVarName
103
+ });
104
+ }
105
+
106
+ maintainHashForAllI18nAssets(compilation) {
107
+ /**
108
+ * we write chunkHash logic inside of our plugin Because we only add Dependency not Module.
109
+ * So we need to update chunkHash for our assets
110
+ * and we not able tell with just Modules.
111
+ * Because, if we add Module for the Depenentcy then that module must has some hash.
112
+ * But our I18n Hash is no module specific it was chunk specific,
113
+ * that's why we do the stuf in the chunkHash hook.
114
+ */
115
+ compilation.hooks.chunkHash.tap(pluginName, (chunk, chunkHash) => {
116
+ const {
117
+ outputOptions
118
+ } = compilation;
119
+ const {
120
+ hashFunction,
121
+ hashDigest,
122
+ hashDigestLength
123
+ } = outputOptions;
124
+ const i18nKeys = (0, _getI18nKeysFormModules.default)(chunk.modulesIterable);
125
+
126
+ if (!i18nKeys.length) {
127
+ return;
128
+ }
129
+
130
+ const {
131
+ contentHash
132
+ } = chunk; // contentHash = {
133
+ // javascript: 'abcd2938',
134
+ // 'css/mini-extract': 'askdijasod'
135
+ // };
136
+
137
+ this.locales.forEach(locale => {
138
+ const contentHashStr = createHash(hashFunction).update(this.i18nFilesEmitter.getTemplateString(i18nKeys, locale)).digest(hashDigest);
139
+ contentHash[i18ntype(locale)] = contentHashStr.substring(0, hashDigestLength);
140
+ chunkHash.update(contentHashStr);
141
+ });
142
+ });
143
+ }
144
+
145
+ apply(compiler) {
146
+ this.i18nKeysIdentifer.apply(compiler);
147
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
148
+ // this below hook was tapped for hash for the specific i18nChunk Files and write logic to requireEnsure
149
+ this.maintainHashForAllI18nAssets(compilation); // const { mainTemplate } = compilation;
150
+ // this.addDownloadLogicOfI18nInMainTemplate(mainTemplate);
151
+ });
152
+ this.i18nFilesEmitter.apply(compiler);
153
+ this.i18nDownlodLogic.apply(compiler);
154
+ }
155
+
156
+ }
157
+ /*
158
+ // TODO: need to reimplement this logic
159
+ // NOTE: this logic for split all content hash per mani chunk
160
+ // like add chunk content hash to main locale i18n file
161
+
162
+ // let isEntry = chunk.name === this.options.mainChunkName;
163
+ // if (chunk.name === 'main' && chunk.hasEntryModule()) {
164
+ if (isEntry) {
165
+ const hashSource = new ConcatSource();
166
+ const dummyChunk = new chunk.constructor();
167
+ hashSource.add('// it wil be I18N file hash');
168
+ const templateHooks = compilation.chunkTemplate.hooks;
169
+ let c = templateHooks.render.call(
170
+ templateHooks.module.call(
171
+ hashSource,
172
+ dummyChunk,
173
+ compilation.moduleTemplate.javascript,
174
+ compilation.dependencyTemplates
175
+ ),
176
+ dummyChunk,
177
+ compilation.moduleTemplate.javascript,
178
+ compilation.dependencyTemplates
179
+ );
180
+ console.log('entry, ', c, hashSource.toString());
181
+ }
182
+ */
183
+
184
+
185
+ exports.default = I18nPlugin;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectI18nKeysfromAST = collectI18nKeysfromAST;
7
+ exports.collectI18nKeysfromComments = collectI18nKeysfromComments;
8
+
9
+ const {
10
+ walk
11
+ } = require('estree-walker');
12
+
13
+ function collectI18nKeysfromAST(ast, allI18n) {
14
+ let i18nKeys = {};
15
+ walk(ast, {
16
+ enter: function (node) {
17
+ if (node.type === 'Literal') {
18
+ if ((node.raw[0] === '\'' || node.raw[0] === '"') && Object.hasOwnProperty.call(allI18n, node.value)) {
19
+ i18nKeys[node.value] = allI18n[node.value];
20
+ }
21
+ }
22
+ }
23
+ });
24
+ return Object.keys(i18nKeys);
25
+ }
26
+
27
+ const prefixI18nComment = 'I18N';
28
+ const prefixI18nComment1 = 'dynamic-i18n-key';
29
+
30
+ function getI18nKeysFromComment(comment) {
31
+ let commentString = comment.value.trim();
32
+ let i18nKeyStr;
33
+
34
+ if (commentString.startsWith(prefixI18nComment)) {
35
+ i18nKeyStr = commentString.slice(prefixI18nComment.length).trim();
36
+ } else if (commentString.startsWith(prefixI18nComment1)) {
37
+ i18nKeyStr = commentString.slice(prefixI18nComment1.length).trim();
38
+ }
39
+
40
+ if (!i18nKeyStr) {
41
+ return [];
42
+ }
43
+
44
+ const i18nKeys = i18nKeyStr.split(',');
45
+ return i18nKeys;
46
+ } // export function fromComments(comments, allI18n) {
47
+
48
+
49
+ function collectI18nKeysfromComments(comments, allI18n) {
50
+ // TODO: need to implement
51
+ let i18nKeys = {};
52
+
53
+ for (let comment of comments) {
54
+ let keys = getI18nKeysFromComment(comment);
55
+
56
+ for (let key of keys) {
57
+ if (key && allI18n[key]) {
58
+ i18nKeys[key] = allI18n[key];
59
+ }
60
+ }
61
+ }
62
+
63
+ return Object.keys(i18nKeys);
64
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getI18nFileUrlPathTemplate = getI18nFileUrlPathTemplate;
7
+
8
+ function getI18nFileUrlPathTemplate(compilation, chunk, filenameTemplate, localeTemplate) {
9
+ let urlpath = compilation.getPath(filenameTemplate, {
10
+ chunk
11
+ });
12
+ return urlpath.replace('[locale]', localeTemplate);
13
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = getI18nKeysFormModules;
7
+
8
+ var _I18nDependency = require("../I18nDependency");
9
+
10
+ function getI18nKeysFormModules(modules) {
11
+ const i18nTemObj = {};
12
+
13
+ for (let m of modules) {
14
+ for (let dep of m.dependencies) {
15
+ if (!(dep instanceof _I18nDependency.I18nDependency)) {
16
+ continue;
17
+ }
18
+
19
+ for (const key of dep.i18nKeys) {
20
+ i18nTemObj[key] = 1;
21
+ }
22
+ }
23
+ }
24
+
25
+ return Object.keys(i18nTemObj);
26
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.REGEXP_CONTENTHASH = void 0;
7
+ exports.getShortI18nAssets = getShortI18nAssets;
8
+ exports.hasContentHash = hasContentHash;
9
+
10
+ var _urlConcat = require("../../../utils/urlConcat");
11
+
12
+ // export const REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi;
13
+ // export const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi;
14
+ // export const REGEXP_NAME = /\[name\]/gi;
15
+ // export const REGEXP_PLACEHOLDERS = /\[(name|id|chunkhash)\]/gi;
16
+ // TODO: want to choose file type for i18n load
17
+ const REGEXP_CONTENTHASH = /\[contenthash(?::(\d+))?\]/gi;
18
+ exports.REGEXP_CONTENTHASH = REGEXP_CONTENTHASH;
19
+
20
+ function hasContentHash(filenameTemplate) {
21
+ return REGEXP_CONTENTHASH.test(filenameTemplate);
22
+ }
23
+
24
+ function getShortI18nAssets(chunks, i18nManifest, publicPathPrefix) {
25
+ const i18nAssets = {};
26
+ chunks.forEach(chunk => {
27
+ const i18nFiles = i18nManifest[chunk.id];
28
+
29
+ if (i18nFiles) {
30
+ Object.keys(i18nFiles).forEach(locale => {
31
+ if (!i18nAssets[locale]) {
32
+ i18nAssets[locale] = [];
33
+ }
34
+
35
+ i18nAssets[locale].push((0, _urlConcat.urlConcat)(publicPathPrefix, i18nFiles[locale]));
36
+ });
37
+ }
38
+ });
39
+ return i18nAssets;
40
+ }
@@ -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,112 @@
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
+ let 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
+ }
43
+
44
+ function getLang(file) {
45
+ let underScoreIndex = file.indexOf('_');
46
+ let language = 'en_US';
47
+
48
+ if (underScoreIndex !== -1) {
49
+ language = file.substring(underScoreIndex + 1);
50
+ language = language.slice(0, language.indexOf('.'));
51
+ }
52
+
53
+ return language;
54
+ }
55
+
56
+ function getAllI18n({
57
+ folderPath,
58
+ disableDefault,
59
+ jsResourceI18nKeys,
60
+ exclude = /^[^_]+$/,
61
+ include = /\.properties$/
62
+ }) {
63
+ try {
64
+ const files = (0, _fs.readdirSync)(folderPath, 'utf8');
65
+ const allLangI18n = {};
66
+ const context = (0, _path.join)(process.cwd(), folderPath);
67
+ files.forEach(file => {
68
+ const filePath = (0, _path.join)(context, file);
69
+
70
+ if (exclude.test(filePath) || !include.test(filePath)) {
71
+ // console.log('exclude', filePath);
72
+ return;
73
+ } // console.log('include', filePath);
74
+
75
+
76
+ const i18n = getPropertiesAsJSON(filePath);
77
+ allLangI18n[getLang(file)] = disableDefault ? i18n : Object.assign({}, jsResourceI18nKeys, i18n);
78
+ });
79
+ return allLangI18n;
80
+ } catch (err) {
81
+ // console.log(err);
82
+ return {};
83
+ }
84
+ }
85
+
86
+ function jsonToString(json, keySeperator) {
87
+ let str = '{';
88
+ let keys = Object.keys(json);
89
+ keys.forEach((key, i) => {
90
+ let value = json[key];
91
+
92
+ if (!value) {
93
+ return;
94
+ }
95
+
96
+ str += `"${keySeperator ? key.replace(/(\.|\\(\s+))/g, keySeperator) : key}":"${value.replace(/.?"/g, match => {
97
+ if (match[0] === '\\') {
98
+ return match;
99
+ } else if (match.length === 2) {
100
+ return `${match[0]}\\${match[1]}`;
101
+ }
102
+
103
+ return `\\${match}`;
104
+ }).replace(/(\r\n|\n|\r)/g, '')}"`;
105
+
106
+ if (i !== keys.length - 1) {
107
+ str += ',';
108
+ }
109
+ });
110
+ str += '}';
111
+ return str;
112
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _webpackSources = require("webpack-sources");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ let filenameParser = filename => {
15
+ let filepaths = filename.split('/');
16
+ let hashedName = filepaths[filepaths.length - 1];
17
+
18
+ let {
19
+ name,
20
+ ext
21
+ } = _path.default.parse(hashedName);
22
+
23
+ let nameparts = name.split('.');
24
+
25
+ if (ext === '.css' && /^(rtl|ltr)$/.test(nameparts[nameparts.length - 1])) {
26
+ return {
27
+ name: nameparts.slice(0, nameparts.length - 2).join('.') + ext,
28
+ hashedName
29
+ };
30
+ }
31
+
32
+ return {
33
+ name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
34
+ hashedName
35
+ };
36
+ };
37
+
38
+ class ManifestPlugin {
39
+ constructor(options) {
40
+ this.options = options;
41
+ }
42
+
43
+ apply(compiler) {
44
+ compiler.hooks.emit.tap('PublicPathChangePlugin', compilation => {
45
+ let stats = compilation.getStats().toJson();
46
+ let manifest = compilation.chunks.reduce((files, chunk) => chunk.files.reduce((files, name) => {
47
+ let {
48
+ name: filename,
49
+ hashedName
50
+ } = filenameParser(name);
51
+
52
+ if (chunk.canBeInitial()) {
53
+ if (!files.entryFiles) {
54
+ files.entryFiles = {};
55
+ }
56
+
57
+ files.entryFiles[filename] = hashedName;
58
+ }
59
+
60
+ files[filename] = hashedName;
61
+ return files;
62
+ }, files), {});
63
+ manifest = stats.assets.reduce((files, asset) => {
64
+ let isEntryAsset = asset.chunks.length > 0;
65
+
66
+ if (isEntryAsset) {
67
+ return files;
68
+ }
69
+
70
+ let {
71
+ name: filename
72
+ } = asset;
73
+ let {
74
+ name,
75
+ hashedName
76
+ } = filenameParser(filename);
77
+ files[name] = hashedName;
78
+ return files;
79
+ }, manifest);
80
+ compilation.assets[this.options.fileName] = new _webpackSources.RawSource(JSON.stringify(manifest));
81
+ });
82
+ }
83
+
84
+ }
85
+
86
+ exports.default = ManifestPlugin;