@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,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ class CleanUpStatsPlugin {
9
+ shouldPickStatChild(child) {
10
+ return child.name.indexOf('mini-css-extract-plugin') !== 0;
11
+ }
12
+
13
+ apply(compiler) {
14
+ compiler.hooks.done.tap('CleanUpStatsPlugin', stats => {
15
+ const {
16
+ children
17
+ } = stats.compilation;
18
+
19
+ if (Array.isArray(children)) {
20
+ // eslint-disable-next-line no-param-reassign
21
+ stats.compilation.children = children.filter(child => this.shouldPickStatChild(child));
22
+ }
23
+ });
24
+ }
25
+
26
+ }
27
+
28
+ exports.default = CleanUpStatsPlugin;
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _webpackSources = require("webpack-sources");
9
+
10
+ var _utils = require("../utils");
11
+
12
+ var _path = _interopRequireDefault(require("path"));
13
+
14
+ var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
15
+
16
+ var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nKeysIdentifer"));
17
+
18
+ var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ // import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
23
+ const cliOptions = (0, _utils.getOptions)();
24
+ const {
25
+ app: {
26
+ publicPaths
27
+ },
28
+ i18n: {
29
+ chunkSplitEnable
30
+ },
31
+ css: {
32
+ enableRTLSplit
33
+ },
34
+ efc: efcOptios
35
+ } = cliOptions;
36
+ const {
37
+ createSDkFile
38
+ } = efcOptios;
39
+
40
+ class EFCPlugin {
41
+ constructor(options = {}) {
42
+ this.isDevelopment = options.isDevelopment;
43
+ this.serverUrl = options.serverUrl;
44
+ this.i18nFileNameTemplate = options.i18nFileNameTemplate; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
45
+ // this.i18nManifestFileName = options.i18nManifestFileName;
46
+ // IMPORTANT: here we mergeing optionds from pacakge.json and options via constructor
47
+ // So when debugging consider this as well
48
+
49
+ this.options = Object.assign({}, efcOptios, options);
50
+ this.options.entryPointName = options.entryPointName || 'efc';
51
+ this.options.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
52
+ this.options.nameScope = options.nameScope || 'EFComponents';
53
+ const localeAttr = this.options.localeAttr || 'data-efc-locale';
54
+ const cssDirAttr = this.options.cssDirAttr || 'data-efc-dir';
55
+ const localeDefaultValue = this.options.localeDefaultValue || 'en_US';
56
+ const cssDirDefaultValue = this.options.cssDirDefaultValue || 'ltr';
57
+ this.options.localeStatement = options.localeStatement || // Statment 1: return langEle && langEle.getAttribute('${localeAttr}') || 'en_US';
58
+ // Statment 2: return langEle ? langEle.getAttribute('${localeAttr}') : 'en_US';
59
+ // We are using statement1 not statment2,
60
+ // Because even that attribute doesn't have value, We need default value
61
+ `(() => {
62
+ let langEle = document.querySelector('[${localeAttr}]');
63
+ return langEle && langEle.getAttribute('${localeAttr}') || '${localeDefaultValue}';
64
+ })();`;
65
+ this.options.cssDirStatement = options.cssDirStatement || `(() => {
66
+ let dirEle = document.querySelector('[${cssDirAttr}]');
67
+ return dirEle && dirEle.getAttribute('${cssDirAttr}') || '${cssDirDefaultValue}';
68
+ })();`;
69
+ } // NOTE: this logic may be needed for i18n splited file name with contenthash cases
70
+ // getI18nManifest(compilation) {
71
+ // const i18nManifestFile =
72
+ // compilation.assets[this.options.i18nManifestFileName];
73
+ // if (i18nManifestFile) {
74
+ // const manifest = JSON.parse(i18nManifestFile.source());
75
+ // return manifest;
76
+ // }
77
+ // return {};
78
+ // }
79
+
80
+
81
+ getI18nAssetsStr(entryPoint, compilation) {
82
+ if (!chunkSplitEnable) {
83
+ let i18nAsstes = {};
84
+ let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
85
+
86
+ i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
87
+ let fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
88
+ let splittedFileName = fileName.split('.');
89
+ res[splittedFileName[0]] = i18nFilePath;
90
+ return res;
91
+ }, {});
92
+ return `[${JSON.stringify(i18nAsstes)}[lang]]`;
93
+ }
94
+
95
+ let initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
96
+ return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
97
+ }
98
+
99
+ createFileContent(compilation) {
100
+ const {
101
+ entryPointName,
102
+ localeStatement,
103
+ cssDirStatement,
104
+ nameScope,
105
+ cdnVariableName = null
106
+ } = this.options;
107
+ const {
108
+ serverUrl
109
+ } = this;
110
+ const cssDirTemplate = '@dir@'; // const i18nManifest = this.getI18nManifest(compilation);
111
+
112
+ const entryPoint = compilation.entrypoints.get(entryPointName); // const chunk = compilation.namedChunks.get(entryPointName);
113
+
114
+ const [jsPath, cssPath,,, i18nJsPath] = !this.isDevelopment ? publicPaths : [];
115
+ const initialFiles = entryPoint.getFiles();
116
+ const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file)); // const i18nAssets = getShortI18nAssets(
117
+ // entryPoint.chunks,
118
+ // i18nManifest,
119
+ // i18nJsPath
120
+ // );
121
+
122
+ const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, i18nJsPath);
123
+ return `(() => {
124
+ const lang = ${localeStatement};
125
+ ${enableRTLSplit ? `const cssDir = ${cssDirStatement};` : ''}
126
+ const prod = !${this.isDevelopment};
127
+ let cdnVariableName = "${cdnVariableName}";
128
+ let assetURLs = {
129
+ //hook
130
+ js: ${JSON.stringify(jsPath || serverUrl)},
131
+ css: ${JSON.stringify(cssPath || serverUrl)},
132
+ i18n: ${JSON.stringify(i18nJsPath || serverUrl)}
133
+ };
134
+
135
+ window.desk_urls={}
136
+ window.desk_urls.staticDomain = 'https:' + assetURLs.js + '/';
137
+ if (prod && cdnVariableName) {
138
+ window["${cdnVariableName}"] = 'https:' + assetURLs.css + '/';
139
+ }
140
+
141
+ let initalI18nAssets = ${initalI18nAssets}.map(urlpath => "${i18nJsPath}/"+ urlpath);
142
+ let initialAssets = initalI18nAssets.concat(${JSON.stringify(enableRTLSplit ? filteredInitialFiles.map(filePath => (0, _replaceCssDirTemplate.replaceCssDirTemplate)(filePath, cssDirTemplate)) : filteredInitialFiles)});
143
+
144
+ let loadAsset = (id, type, url) => {
145
+ return new Promise((res, rej) => {
146
+ let el = document.createElement(type);
147
+ // el.id = id;
148
+ el.onload = res;
149
+ el.error = rej;
150
+ switch(type) {
151
+ case 'script':
152
+ case 'i18n':
153
+ el.src = (type === 'i18n'? assetURLs.i18n : assetURLs.js)+'/'+url
154
+ el.defer = 'defer';
155
+ document.body.appendChild(el);
156
+ break;
157
+ case 'link':
158
+ el.href = assetURLs.css+'/'+url${enableRTLSplit ? `.replace(${JSON.stringify(cssDirTemplate)}, cssDir)` : ''}
159
+ el.rel = 'stylesheet';
160
+ document.head.appendChild(el);
161
+ break;
162
+ }
163
+ });
164
+ };
165
+
166
+ let memorizedPromise = null;
167
+ ${nameScope}.onload = (cb, err) => {
168
+ if(!memorizedPromise) {
169
+ memorizedPromise = Promise.all(
170
+ initialAssets.map(
171
+ (url, index) => loadAsset(
172
+ "${nameScope}-" + (url.endsWith("js") ? "js" : "css") +"-"+index,
173
+ url.endsWith("js") ? url.endsWith(".i18n.js") ? "i18n" : 'script' : 'link',
174
+ url
175
+ )
176
+ )
177
+ ).then(() => ${nameScope}.onBasicLoad(cb));
178
+ }
179
+ return memorizedPromise;
180
+ };
181
+
182
+ })();
183
+ `;
184
+ }
185
+
186
+ apply(compiler) {
187
+ if (!createSDkFile) {
188
+ return;
189
+ }
190
+
191
+ compiler.hooks.emit.tap('EFCPlugin', compilation => {
192
+ const {
193
+ entryPointName,
194
+ outputFile
195
+ } = this.options;
196
+ const entryPoint = compilation.entrypoints.get(entryPointName);
197
+
198
+ if (!entryPoint) {
199
+ return;
200
+ }
201
+
202
+ const source = new _webpackSources.RawSource(this.createFileContent(compilation));
203
+ compilation.assets[outputFile] = source; // eslint-disable-next-line no-console
204
+
205
+ console.log('The EFC embedded code was created successfully..!!!');
206
+ });
207
+ }
208
+
209
+ }
210
+
211
+ exports.default = EFCPlugin;
@@ -0,0 +1,6 @@
1
+ # EFC Plugin
2
+
3
+ In EFC plugin we are create sdk file for efc related purpose
4
+
5
+
6
+ # document will be soon
@@ -0,0 +1,141 @@
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 _utils = require("../utils");
11
+
12
+ var _urlConcat = require("../utils/urlConcat");
13
+
14
+ var _path = _interopRequireDefault(require("path"));
15
+
16
+ var _webpackSources = require("webpack-sources");
17
+
18
+ var _hashUtils = require("./I18nSplitPlugin/utils/hashUtils");
19
+
20
+ var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ let i18nObj = null;
25
+ let options = (0, _utils.getOptions)();
26
+
27
+ function newAssign(target, data) {
28
+ return Object.assign({}, target, data);
29
+ }
30
+
31
+ const {
32
+ i18n
33
+ } = options;
34
+
35
+ class I18NInjectIntoIndexPlugin {
36
+ constructor(options) {
37
+ this.isDevelopment = options.isDevelopment;
38
+ this.i18nFileNameTemplate = options.i18nFileNameTemplate;
39
+ this.publicPath = options.publicPath;
40
+ this.templateLabel = options.templateLabel || '{{--user-locale}}';
41
+ this.i18nManifestFileName = options.i18nManifestFileName;
42
+ this.entryPointName = options.mainChunkName;
43
+ }
44
+
45
+ getI18nFileUrlPath(chunk, compilation) {
46
+ let urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
47
+ return (0, _urlConcat.urlConcat)(this.publicPath, urlpath);
48
+ }
49
+
50
+ getI18nManifest(compilation) {
51
+ const i18nManifestFile = compilation.assets[this.i18nManifestFileName];
52
+
53
+ if (!i18nManifestFile) {
54
+ return {};
55
+ }
56
+
57
+ const manifest = JSON.parse(i18nManifestFile.source());
58
+ return manifest;
59
+ }
60
+
61
+ injectI18nURLsToHTML(compilation) {
62
+ _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
63
+ const {
64
+ assets
65
+ } = data; // Manipulate the content
66
+
67
+ const i18nManifest = this.getI18nManifest(compilation);
68
+ const entryPoint = compilation.entrypoints.get(this.entryPointName);
69
+ const i18nScriptURLs = entryPoint.chunks.filter(c => !!i18nManifest[c.id]).map(c => this.getI18nFileUrlPath(c, compilation)); // .map(url => getI18nScriptTagObj(url));
70
+ // .join('');
71
+ // Tell webpack to move on
72
+
73
+ cb(null, newAssign(data, {
74
+ assets: newAssign(assets, {
75
+ js: i18nScriptURLs.concat(assets.js)
76
+ })
77
+ }));
78
+ });
79
+ }
80
+
81
+ withI18nSpitHandling(compiler) {
82
+ compiler.hooks.make.tap('I18NInjectIntoIndexPlugin', compilation => {
83
+ // let cdns = Object.keys(this.publicPaths);
84
+ // console.log('compilation.assets', Object.keys(compilation.assets).filter(a => a.includes('i18n')));
85
+ if (!(0, _hashUtils.hasContentHash)(this.i18nFileNameTemplate)) {
86
+ this.injectI18nURLsToHTML(compilation);
87
+ return;
88
+ }
89
+
90
+ _htmlWebpackPlugin.default.getHooks(compilation).beforeEmit.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
91
+ // Manipulate the content
92
+ const i18nManifest = this.getI18nManifest(compilation);
93
+ const entryPoint = compilation.entrypoints.get(this.entryPointName);
94
+ let i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
95
+ data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets))); // Tell webpack to move on
96
+
97
+ cb(null, data);
98
+ });
99
+ });
100
+ }
101
+
102
+ apply(compiler) {
103
+ if (i18n.chunkSplitEnable) {
104
+ this.withI18nSpitHandling(compiler);
105
+ } else {
106
+ this.withoutI18nSpitHandling(compiler);
107
+ }
108
+ }
109
+
110
+ withoutI18nSpitHandling(compiler) {
111
+ compiler.hooks.emit.tap('I18NInjectIntoIndexPlugin', compilation => {
112
+ // let cdns = Object.keys(this.publicPaths);
113
+ if (i18nObj === null) {
114
+ let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
115
+
116
+ i18nObj = i18nFiles.reduce((res, next) => {
117
+ let fileName = next.replace(`i18n${_path.default.sep}`, '');
118
+ let splittedFileName = fileName.split('.');
119
+ /* if (this.isDevelopment) {
120
+ res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
121
+ } else {
122
+ res[splittedFileName[0]] = fileName;
123
+ } */
124
+
125
+ res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
126
+ return res;
127
+ }, {});
128
+ }
129
+
130
+ let [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
131
+
132
+ if (indexFile) {
133
+ let source = compilation.assets[indexFile].source();
134
+ compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nObj))));
135
+ }
136
+ });
137
+ }
138
+
139
+ }
140
+
141
+ exports.default = I18NInjectIntoIndexPlugin;
@@ -0,0 +1,60 @@
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
+ const pluginName = 'I18nDebugPlugin'; // this plugin only for debug related purpose
11
+
12
+ class I18nDebugPlugin {
13
+ constructor(jsResourceI18nKeys) {
14
+ this.jsResourceI18nKeys = jsResourceI18nKeys;
15
+ this.warnings = [];
16
+ }
17
+
18
+ apply(compiler) {
19
+ compiler.hooks.thisCompilation.tap(pluginName, (compilation, compilationParams) => {
20
+ // TEMP : only for debugging purpose
21
+ this.compilation1 = compilation;
22
+ this.compilationParams = compilationParams.normalModuleFactory;
23
+ });
24
+ compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
25
+ if (!this.compilationParams || this.compilationParams.normalModuleFactory === factory) {
26
+ return;
27
+ } // console.log('skiped');
28
+
29
+
30
+ let handler = parser => {
31
+ parser.hooks.program.tap(pluginName, (ast, commmets) => {
32
+ const {
33
+ module
34
+ } = parser.state; //
35
+
36
+ if (!(module && /\.jsx?$/.test(module.resource))) {
37
+ return;
38
+ } // i18n grep proper contract regex
39
+
40
+
41
+ let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
42
+ i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
43
+ (0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
44
+ i18nKeys.length && this.warnings.push({
45
+ message: 'skiped i18n keys',
46
+ reason: 'may be some child compiler',
47
+ fileName: module.resource,
48
+ i18nKeys
49
+ });
50
+ });
51
+ };
52
+
53
+ factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
54
+ factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler); // factory.hooks.parser.for('javascript/esm').tap(pluginName, handler);
55
+ });
56
+ }
57
+
58
+ }
59
+
60
+ exports.default = I18nDebugPlugin;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.I18nDependencyTemplate = exports.I18nDependency = void 0;
7
+
8
+ var _webpack = require("webpack");
9
+
10
+ // const webpack = require('webpack');
11
+ class I18nDependency extends _webpack.Dependency {
12
+ constructor({
13
+ identifier,
14
+ i18nKeys
15
+ }, context, identifierIndex) {
16
+ super();
17
+ this.identifier = identifier;
18
+ this.identifierIndex = identifierIndex;
19
+ this.i18nKeys = i18nKeys;
20
+ this.context = context;
21
+ }
22
+
23
+ getResourceIdentifier() {
24
+ return `i18n-module-${this.identifier}-${this.identifierIndex}`;
25
+ }
26
+
27
+ }
28
+
29
+ exports.I18nDependency = I18nDependency;
30
+
31
+ class I18nDependencyTemplate {
32
+ //eslint-disable-next-line no-empty-function
33
+ apply() {} // apply(dep, source) {
34
+ // if (typeof dep.range === "number") {
35
+ // source.insert(0, `/* comment by I18nSplitPlugin , i18n keys = ${JSON.stringify(dep.i18nKeys)} */`);
36
+ // return;
37
+ // }
38
+ // source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
39
+ // }
40
+
41
+
42
+ }
43
+
44
+ exports.I18nDependencyTemplate = I18nDependencyTemplate;