@zohodesk/react-cli 0.0.1-beta.98 → 0.0.1-betaa.138.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +149 -0
  3. package/bin/cli.js +34 -29
  4. package/files/eslintrc.js +57 -0
  5. package/files/prettierrc.js +3 -0
  6. package/lib/babel/cmjs-plugins-presets.js +16 -9
  7. package/lib/babel/es-plugins-presets.js +26 -14
  8. package/lib/common/getEntries.js +31 -22
  9. package/lib/common/getPublicPathConfig.js +27 -13
  10. package/lib/common/index.js +21 -25
  11. package/lib/common/splitChunks.js +62 -53
  12. package/lib/common/templateParameters.js +10 -8
  13. package/lib/configs/jest.config.js +15 -25
  14. package/lib/configs/webpack.component.umd.config.js +31 -37
  15. package/lib/configs/webpack.css.umd.config.js +44 -47
  16. package/lib/configs/webpack.dev.config.js +70 -52
  17. package/lib/configs/webpack.docs.config.js +106 -106
  18. package/lib/configs/webpack.prod.config.js +95 -75
  19. package/lib/hooks/docsProptypeHook.js +32 -38
  20. package/lib/jest/commitedFilesResult.js +103 -74
  21. package/lib/jest/coverageCollector.js +41 -21
  22. package/lib/jest/jsonMaker.js +15 -16
  23. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  24. package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
  25. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  26. package/lib/jest/result.js +90 -45
  27. package/lib/jest/run.js +43 -43
  28. package/lib/jest/setup.js +102 -95
  29. package/lib/loaderUtils/getCSSLoaders.js +21 -22
  30. package/lib/loaderUtils/getDevJsLoaders.js +25 -23
  31. package/lib/loaderUtils/index.js +11 -13
  32. package/lib/loaders/docsLoader.js +15 -15
  33. package/lib/loaders/docsPropsLoader.js +14 -17
  34. package/lib/loaders/fileLoader.js +33 -35
  35. package/lib/loaders/scriptInstrumentLoader.js +21 -20
  36. package/lib/loaders/workerLoader.js +136 -0
  37. package/lib/middlewares/HMRMiddleware.js +54 -45
  38. package/lib/middlewares/SSTMiddleware.js +8 -5
  39. package/lib/pluginUtils/getDevPlugins.js +114 -52
  40. package/lib/pluginUtils/getDocsPlugins.js +25 -29
  41. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  42. package/lib/pluginUtils/getProdPlugins.js +163 -74
  43. package/lib/pluginUtils/getServerPlugins.js +8 -11
  44. package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
  45. package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
  46. package/lib/pluginUtils/index.js +36 -43
  47. package/lib/plugins/CdnChangePlugin.js +63 -0
  48. package/lib/plugins/CleanupStatsPlugin.js +18 -32
  49. package/lib/plugins/CustomAttributePlugin.js +79 -0
  50. package/lib/plugins/CustomAttributePlugin.md +35 -0
  51. package/lib/plugins/EFCPlugin.js +185 -0
  52. package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
  53. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  54. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  55. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  56. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  57. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  58. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
  59. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  60. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  61. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  62. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  63. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  64. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  65. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  66. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  67. package/lib/plugins/ManifestPlugin.js +52 -63
  68. package/lib/plugins/ModuleStatsPlugin.js +83 -173
  69. package/lib/plugins/OptimizeJSPlugin.js +24 -41
  70. package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
  71. package/lib/plugins/PublicPathChangePlugin.js +175 -284
  72. package/lib/plugins/ReportGeneratePlugin.js +150 -151
  73. package/lib/plugins/ResourceHintsPlugin.js +53 -35
  74. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  75. package/lib/plugins/ServiceWorkerPlugin.js +81 -57
  76. package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
  77. package/lib/plugins/SourceMapHookPlugin.js +21 -33
  78. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  79. package/lib/plugins/UglifyCSSPlugin.js +23 -30
  80. package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
  81. package/lib/plugins/index.js +100 -91
  82. package/lib/plugins/webpackwatchrunplugin.js +18 -30
  83. package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
  84. package/lib/schemas/index.js +336 -81
  85. package/lib/servers/clusterHubServer.js +22 -26
  86. package/lib/servers/docsServer.js +3 -5
  87. package/lib/servers/docsServerCore.js +84 -91
  88. package/lib/servers/helpServer.js +19 -21
  89. package/lib/servers/impactServer.js +99 -92
  90. package/lib/servers/mockserver.js +24 -24
  91. package/lib/servers/scrServer.js +78 -98
  92. package/lib/servers/server.js +101 -122
  93. package/lib/servers/ssServer.js +63 -61
  94. package/lib/sh/reportPublish.sh +1 -2
  95. package/lib/templates/CoverageScriptTemplate.js +45 -18
  96. package/lib/templates/WMSTemplate.js +17 -18
  97. package/lib/templates/linterConstant.js +6 -4
  98. package/lib/utils/babelPresets.js +12 -5
  99. package/lib/utils/clean.js +12 -11
  100. package/lib/utils/copy.js +12 -34
  101. package/lib/utils/copyTimezones.js +9 -16
  102. package/lib/utils/createEventStream.js +24 -19
  103. package/lib/utils/cssClassNameGenerate.js +44 -73
  104. package/lib/utils/cssURLReplacer.js +62 -56
  105. package/lib/utils/dependencyPostPublish.js +20 -19
  106. package/lib/utils/fileUtils.js +66 -54
  107. package/lib/utils/folderIterator.js +20 -21
  108. package/lib/utils/getComponents.js +70 -27
  109. package/lib/utils/getCurrentBranch.js +11 -17
  110. package/lib/utils/getDependenciesImpactList.js +114 -187
  111. package/lib/utils/getHash.js +9 -13
  112. package/lib/utils/getIp.js +9 -9
  113. package/lib/utils/getOptions.js +26 -29
  114. package/lib/utils/getServerURL.js +19 -10
  115. package/lib/utils/index.js +147 -126
  116. package/lib/utils/init.js +2 -2
  117. package/lib/utils/initPreCommitHook.js +40 -32
  118. package/lib/utils/jsonHelper.js +37 -21
  119. package/lib/utils/lint/addScripts.js +27 -0
  120. package/lib/utils/lint/checkExistingConfig.js +67 -0
  121. package/lib/utils/lint/copyConfigs.js +24 -0
  122. package/lib/utils/lint/index.js +54 -0
  123. package/lib/utils/lint/lintScripts.js +11 -0
  124. package/lib/utils/lint/lintSetup.js +31 -0
  125. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  126. package/lib/utils/lint/question.js +30 -0
  127. package/lib/utils/lintReporter.js +70 -56
  128. package/lib/utils/mailSender.js +12 -27
  129. package/lib/utils/pullOrigin.js +21 -18
  130. package/lib/utils/reinstallDependencies.js +76 -85
  131. package/lib/utils/removeAttributes.js +25 -23
  132. package/lib/utils/repoClone.js +47 -45
  133. package/lib/utils/request.js +64 -77
  134. package/lib/utils/rtl.js +22 -29
  135. package/lib/utils/setEnvVariables.js +5 -6
  136. package/lib/utils/ssTestHack.js +21 -19
  137. package/lib/utils/switchBranch.js +21 -20
  138. package/lib/utils/urlConcat.js +22 -0
  139. package/package.json +72 -67
@@ -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
+ }
@@ -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;