@zohodesk/react-cli 0.0.1-beta.16 → 0.0.1-beta.160

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 (226) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +46 -3
  3. package/CHANGELOG.md +5 -0
  4. package/README.md +650 -0
  5. package/bin/cli.js +134 -27
  6. package/cert/cert.pem +37 -129
  7. package/cert/key.pem +27 -27
  8. package/cert/passphrase.pem +1 -0
  9. package/files/eslintrc.js +62 -0
  10. package/files/prettierrc.js +3 -0
  11. package/lib/babel/cmjs-plugins-presets.js +16 -9
  12. package/lib/babel/es-plugins-presets.js +26 -14
  13. package/lib/common/getEntries.js +33 -24
  14. package/lib/common/getPublicPathConfig.js +40 -0
  15. package/lib/common/index.js +27 -13
  16. package/lib/common/splitChunks.js +64 -26
  17. package/lib/common/sslcertUpdater.js +59 -0
  18. package/lib/common/templateParameters.js +25 -0
  19. package/lib/configs/jest.config.js +18 -28
  20. package/lib/configs/webpack.component.umd.config.js +31 -37
  21. package/lib/configs/webpack.css.umd.config.js +44 -44
  22. package/lib/configs/webpack.dev.config.js +113 -57
  23. package/lib/configs/webpack.docs.config.js +104 -98
  24. package/lib/configs/webpack.impact.config.js +116 -0
  25. package/lib/configs/webpack.prod.config.js +154 -86
  26. package/lib/hooks/docsProptypeHook.js +32 -38
  27. package/lib/jest/commitedFilesResult.js +144 -71
  28. package/lib/jest/coverageCollector.js +62 -29
  29. package/lib/jest/jsonMaker.js +54 -0
  30. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  31. package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
  32. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  33. package/lib/jest/result.js +91 -41
  34. package/lib/jest/run.js +74 -27
  35. package/lib/jest/setup.js +103 -102
  36. package/lib/loaderUtils/getCSSLoaders.js +77 -0
  37. package/lib/loaderUtils/getDevJsLoaders.js +30 -23
  38. package/lib/loaderUtils/index.js +14 -7
  39. package/lib/loaders/docsLoader.js +15 -15
  40. package/lib/loaders/docsPropsLoader.js +14 -17
  41. package/lib/loaders/fileBountryLoader.js +17 -0
  42. package/lib/loaders/fileLoader.js +47 -38
  43. package/lib/loaders/scriptInstrumentLoader.js +21 -20
  44. package/lib/loaders/selectorMappingLoader.js +75 -0
  45. package/lib/loaders/workerLoader.js +136 -0
  46. package/lib/middlewares/HMRMiddleware.js +59 -41
  47. package/lib/middlewares/SSTMiddleware.js +21 -0
  48. package/lib/pluginUtils/getDevPlugins.js +173 -26
  49. package/lib/pluginUtils/getDocsPlugins.js +32 -17
  50. package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
  51. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  52. package/lib/pluginUtils/getProdPlugins.js +238 -37
  53. package/lib/pluginUtils/getServerPlugins.js +8 -11
  54. package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
  55. package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
  56. package/lib/pluginUtils/index.js +36 -43
  57. package/lib/plugins/CdnChangePlugin.js +77 -0
  58. package/lib/plugins/CleanupStatsPlugin.js +28 -0
  59. package/lib/plugins/EFCPlugin.js +211 -0
  60. package/lib/plugins/EFCPlugin.md +6 -0
  61. package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
  62. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  63. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  64. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  65. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  66. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  67. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
  68. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  69. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  70. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  71. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  72. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  73. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  74. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  75. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  76. package/lib/plugins/ManifestPlugin.js +52 -63
  77. package/lib/plugins/ModuleStatsPlugin.js +98 -97
  78. package/lib/plugins/OptimizeJSPlugin.js +24 -41
  79. package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
  80. package/lib/plugins/PublicPathChangePlugin.js +187 -174
  81. package/lib/plugins/ReportGeneratePlugin.js +181 -0
  82. package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
  83. package/lib/plugins/ResourceHintsPlugin.js +53 -35
  84. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
  85. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
  86. package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
  87. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
  88. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  89. package/lib/plugins/ServiceWorkerPlugin.js +107 -0
  90. package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
  91. package/lib/plugins/SourceMapHookPlugin.js +25 -31
  92. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  93. package/lib/plugins/UglifyCSSPlugin.js +23 -30
  94. package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
  95. package/lib/plugins/index.js +118 -55
  96. package/lib/plugins/libraryImpactPlugin.js +190 -0
  97. package/lib/plugins/webpackwatchrunplugin.js +26 -0
  98. package/lib/postcss-plugins/ExcludeRTLPlugin.js +23 -0
  99. package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
  100. package/lib/schemas/index.js +463 -52
  101. package/lib/servers/clusterHubServer.js +22 -26
  102. package/lib/servers/docsServer.js +3 -5
  103. package/lib/servers/docsServerCore.js +93 -85
  104. package/lib/servers/helpServer.js +19 -21
  105. package/lib/servers/httpsOptions.js +19 -0
  106. package/lib/servers/impactServer.js +99 -92
  107. package/lib/servers/mockserver.js +44 -0
  108. package/lib/servers/nowatchserver.js +275 -0
  109. package/lib/servers/scrServer.js +147 -0
  110. package/lib/servers/server.js +118 -124
  111. package/lib/servers/ssServer.js +107 -65
  112. package/lib/sh/reportPublish.sh +16 -10
  113. package/lib/templates/CoverageScriptTemplate.js +45 -18
  114. package/lib/templates/WMSTemplate.js +17 -18
  115. package/lib/templates/linterConstant.js +10 -0
  116. package/lib/utils/babelPresets.js +12 -5
  117. package/lib/utils/buildstats.html +148 -0
  118. package/lib/utils/clean.js +12 -11
  119. package/lib/utils/copy.js +13 -127
  120. package/lib/utils/copyTimezones.js +21 -0
  121. package/lib/utils/createEventStream.js +24 -19
  122. package/lib/utils/cssClassNameGenerate.js +70 -0
  123. package/lib/utils/cssURLReplacer.js +67 -54
  124. package/lib/utils/dependencyPostPublish.js +42 -0
  125. package/lib/utils/fileUtils.js +125 -0
  126. package/lib/utils/folderIterator.js +47 -0
  127. package/lib/utils/getComponents.js +126 -0
  128. package/lib/utils/getCurrentBranch.js +11 -17
  129. package/lib/utils/getDependenciesImpactList.js +151 -0
  130. package/lib/utils/getHash.js +26 -0
  131. package/lib/utils/getIp.js +20 -0
  132. package/lib/utils/getOptions.js +55 -30
  133. package/lib/utils/getServerURL.js +25 -8
  134. package/lib/utils/index.js +259 -82
  135. package/lib/utils/init.js +2 -2
  136. package/lib/utils/initPreCommitHook.js +40 -31
  137. package/lib/utils/jsonHelper.js +97 -0
  138. package/lib/utils/libraryImpactConfig.js +63 -0
  139. package/lib/utils/lint/addScripts.js +27 -0
  140. package/lib/utils/lint/checkExistingConfig.js +67 -0
  141. package/lib/utils/lint/copyConfigs.js +24 -0
  142. package/lib/utils/lint/index.js +54 -0
  143. package/lib/utils/lint/lintScripts.js +11 -0
  144. package/lib/utils/lint/lintSetup.js +31 -0
  145. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  146. package/lib/utils/lint/question.js +30 -0
  147. package/lib/utils/lintReporter.js +142 -0
  148. package/lib/utils/mailSender.js +16 -25
  149. package/lib/utils/pullOrigin.js +28 -0
  150. package/lib/utils/reinstallDependencies.js +133 -0
  151. package/lib/utils/removeAttributes.js +25 -23
  152. package/lib/utils/repoClone.js +56 -63
  153. package/lib/utils/request.js +64 -77
  154. package/lib/utils/resultSchema.json +73 -0
  155. package/lib/utils/rtl.js +42 -0
  156. package/lib/utils/setEnvVariables.js +5 -6
  157. package/lib/utils/ssTestHack.js +48 -0
  158. package/lib/utils/switchBranch.js +28 -0
  159. package/lib/utils/urlConcat.js +22 -0
  160. package/package.json +92 -64
  161. package/templates/app/.eslintrc.js +140 -0
  162. package/templates/app/README.md +12 -12
  163. package/templates/app/app/index.html +24 -8
  164. package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
  165. package/templates/app/app/properties/i18nkeys.json +3 -3
  166. package/templates/app/docs/all.html +69 -69
  167. package/templates/app/mockapi/index.js +18 -13
  168. package/templates/app/package.json +37 -17
  169. package/templates/app/src/actions/SampleActions/index.js +37 -0
  170. package/templates/app/src/actions/index.js +65 -0
  171. package/templates/app/src/appUrls.js +19 -0
  172. package/templates/app/src/components/Alert/Alert.js +134 -0
  173. package/templates/app/src/components/Alert/Alert.module.css +79 -0
  174. package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
  175. package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
  176. package/templates/app/src/components/Sample/Sample.module.css +11 -0
  177. package/templates/app/src/components/Sample/SampleList.js +61 -0
  178. package/templates/app/src/components/Slider/Slider.css +41 -0
  179. package/templates/app/src/components/Slider/Slider.js +55 -0
  180. package/templates/app/src/containers/AlertContainer/index.js +15 -0
  181. package/templates/app/src/containers/AppContainer/index.js +96 -0
  182. package/templates/app/src/containers/AppContainer/index.module.css +27 -0
  183. package/templates/app/src/containers/CustomMatch/index.js +65 -0
  184. package/templates/app/src/containers/DevTools/index.js +10 -0
  185. package/templates/app/src/containers/Header/index.js +67 -0
  186. package/templates/app/src/containers/Header/index.module.css +43 -0
  187. package/templates/app/src/containers/Redirect/index.js +63 -0
  188. package/templates/app/src/containers/Redirector/index.js +47 -0
  189. package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
  190. package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
  191. package/templates/app/src/historyChange.js +5 -0
  192. package/templates/app/src/index.html +10 -0
  193. package/templates/app/src/index.js +24 -0
  194. package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
  195. package/templates/app/src/reducers/alertData.js +11 -0
  196. package/templates/app/src/reducers/index.js +6 -0
  197. package/templates/app/src/reducers/samples.js +19 -0
  198. package/templates/app/src/store/configureStore.dev.js +51 -0
  199. package/templates/app/src/store/configureStore.js +5 -0
  200. package/templates/app/src/store/configureStore.prod.js +26 -0
  201. package/templates/app/src/util/Common.js +5 -0
  202. package/templates/app/src/util/RequestAPI.js +132 -0
  203. package/templates/appold/README.md +12 -0
  204. package/templates/appold/app/index.html +8 -0
  205. package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
  206. package/templates/appold/app/properties/i18nkeys.json +3 -0
  207. package/templates/appold/docs/all.html +69 -0
  208. package/templates/appold/mockapi/index.js +13 -0
  209. package/templates/{app → appold}/mockapi/tickets.json +0 -0
  210. package/templates/appold/package.json +17 -0
  211. package/templates/appold/src/components/Text/Text.css +0 -0
  212. package/templates/appold/src/components/Text/Text.js +23 -0
  213. package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
  214. package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
  215. package/templates/appold/src/components/docs.js +1 -0
  216. package/templates/appold/src/components/index.js +5 -0
  217. package/templates/appold/src/index.js +13 -0
  218. package/templates/docs/all.html +1 -1
  219. package/templates/docs/component.html +110 -69
  220. package/templates/docs/components.html +221 -0
  221. package/templates/docs/css/component.css +12 -14
  222. package/templates/docs/css/componentTest.css +7 -0
  223. package/templates/docs/css/style.css +150 -206
  224. package/templates/docs/impactReportTemplate.html +154 -0
  225. package/templates/docs/index.html +1482 -1336
  226. package/templates/library/src/index.js +0 -0
@@ -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.hasContentHash = hasContentHash;
7
+ exports.getShortI18nAssets = getShortI18nAssets;
8
+ exports.REGEXP_CONTENTHASH = void 0;
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.getPropertiesAsJSON = getPropertiesAsJSON;
7
+ exports.getAllI18n = getAllI18n;
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
+ }
@@ -1,89 +1,78 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
+ var _path = _interopRequireDefault(require("path"));
8
9
 
9
- var _path = require('path');
10
-
11
- var _path2 = _interopRequireDefault(_path);
12
-
13
- var _webpackSources = require('webpack-sources');
10
+ var _webpackSources = require("webpack-sources");
14
11
 
15
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
13
 
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ let filenameParser = filename => {
15
+ let filepaths = filename.split('/');
16
+ let hashedName = filepaths[filepaths.length - 1];
18
17
 
19
- var filenameParser = function filenameParser(filename) {
20
- var filepaths = filename.split('/');
21
- var hashedName = filepaths[filepaths.length - 1];
18
+ let {
19
+ name,
20
+ ext
21
+ } = _path.default.parse(hashedName);
22
22
 
23
- var _path$parse = _path2.default.parse(hashedName),
24
- name = _path$parse.name,
25
- ext = _path$parse.ext;
26
-
27
- var nameparts = name.split('.');
23
+ let nameparts = name.split('.');
28
24
  return {
29
25
  name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
30
- hashedName: hashedName
26
+ hashedName
31
27
  };
32
28
  };
33
29
 
34
- var ManifestPlugin = function () {
35
- function ManifestPlugin(options) {
36
- _classCallCheck(this, ManifestPlugin);
37
-
30
+ class ManifestPlugin {
31
+ constructor(options) {
38
32
  this.options = options;
39
33
  }
40
34
 
41
- _createClass(ManifestPlugin, [{
42
- key: 'apply',
43
- value: function apply(compiler) {
44
- var _this = this;
45
-
46
- compiler.hooks.emit.tap('PublicPathChangePlugin', function (compilation) {
47
- var stats = compilation.getStats().toJson();
48
-
49
- var manifest = compilation.chunks.reduce(function (files, chunk) {
50
- return chunk.files.reduce(function (files, name) {
51
- var _filenameParser = filenameParser(name),
52
- filename = _filenameParser.name,
53
- hashedName = _filenameParser.hashedName;
54
-
55
- if (chunk.canBeInitial()) {
56
- if (!files.entryFiles) {
57
- files.entryFiles = {};
58
- }
59
- files.entryFiles[filename] = hashedName;
60
- }
61
- files[filename] = hashedName;
62
- return files;
63
- }, files);
64
- }, {});
65
-
66
- manifest = stats.assets.reduce(function (files, asset) {
67
- var isEntryAsset = asset.chunks.length > 0;
68
- if (isEntryAsset) {
69
- return files;
35
+ apply(compiler) {
36
+ compiler.hooks.emit.tap('PublicPathChangePlugin', compilation => {
37
+ let stats = compilation.getStats().toJson();
38
+ let manifest = compilation.chunks.reduce((files, chunk) => chunk.files.reduce((files, name) => {
39
+ let {
40
+ name: filename,
41
+ hashedName
42
+ } = filenameParser(name);
43
+
44
+ if (chunk.canBeInitial()) {
45
+ if (!files.entryFiles) {
46
+ files.entryFiles = {};
70
47
  }
71
- var filename = asset.name;
72
48
 
73
- var _filenameParser2 = filenameParser(filename),
74
- name = _filenameParser2.name,
75
- hashedName = _filenameParser2.hashedName;
49
+ files.entryFiles[filename] = hashedName;
50
+ }
76
51
 
77
- files[name] = hashedName;
78
- return files;
79
- }, manifest);
52
+ files[filename] = hashedName;
53
+ return files;
54
+ }, files), {});
55
+ manifest = stats.assets.reduce((files, asset) => {
56
+ let isEntryAsset = asset.chunks.length > 0;
80
57
 
81
- compilation.assets[_this.options.fileName] = new _webpackSources.RawSource(JSON.stringify(manifest));
82
- });
83
- }
84
- }]);
58
+ if (isEntryAsset) {
59
+ return files;
60
+ }
61
+
62
+ let {
63
+ name: filename
64
+ } = asset;
65
+ let {
66
+ name,
67
+ hashedName
68
+ } = filenameParser(filename);
69
+ files[name] = hashedName;
70
+ return files;
71
+ }, manifest);
72
+ compilation.assets[this.options.fileName] = new _webpackSources.RawSource(JSON.stringify(manifest));
73
+ });
74
+ }
85
75
 
86
- return ManifestPlugin;
87
- }();
76
+ }
88
77
 
89
78
  exports.default = ManifestPlugin;