@zohodesk/react-cli 0.0.1-beta.98 → 0.0.1-betaa.138.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +149 -0
- package/bin/cli.js +34 -29
- package/files/eslintrc.js +57 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +16 -9
- package/lib/babel/es-plugins-presets.js +26 -14
- package/lib/common/getEntries.js +31 -22
- package/lib/common/getPublicPathConfig.js +27 -13
- package/lib/common/index.js +21 -25
- package/lib/common/splitChunks.js +62 -53
- package/lib/common/templateParameters.js +10 -8
- package/lib/configs/jest.config.js +15 -25
- package/lib/configs/webpack.component.umd.config.js +31 -37
- package/lib/configs/webpack.css.umd.config.js +44 -47
- package/lib/configs/webpack.dev.config.js +70 -52
- package/lib/configs/webpack.docs.config.js +106 -106
- package/lib/configs/webpack.prod.config.js +95 -75
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +103 -74
- package/lib/jest/coverageCollector.js +41 -21
- package/lib/jest/jsonMaker.js +15 -16
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +90 -45
- package/lib/jest/run.js +43 -43
- package/lib/jest/setup.js +102 -95
- package/lib/loaderUtils/getCSSLoaders.js +21 -22
- package/lib/loaderUtils/getDevJsLoaders.js +25 -23
- package/lib/loaderUtils/index.js +11 -13
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileLoader.js +33 -35
- package/lib/loaders/scriptInstrumentLoader.js +21 -20
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +54 -45
- package/lib/middlewares/SSTMiddleware.js +8 -5
- package/lib/pluginUtils/getDevPlugins.js +114 -52
- package/lib/pluginUtils/getDocsPlugins.js +25 -29
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +163 -74
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
- package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
- package/lib/pluginUtils/index.js +36 -43
- package/lib/plugins/CdnChangePlugin.js +63 -0
- package/lib/plugins/CleanupStatsPlugin.js +18 -32
- package/lib/plugins/CustomAttributePlugin.js +79 -0
- package/lib/plugins/CustomAttributePlugin.md +35 -0
- package/lib/plugins/EFCPlugin.js +185 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
- package/lib/plugins/I18nSplitPlugin/README.md +25 -0
- package/lib/plugins/I18nSplitPlugin/index.js +185 -0
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
- package/lib/plugins/ManifestPlugin.js +52 -63
- package/lib/plugins/ModuleStatsPlugin.js +83 -173
- package/lib/plugins/OptimizeJSPlugin.js +24 -41
- package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
- package/lib/plugins/PublicPathChangePlugin.js +175 -284
- package/lib/plugins/ReportGeneratePlugin.js +150 -151
- package/lib/plugins/ResourceHintsPlugin.js +53 -35
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +81 -57
- package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
- package/lib/plugins/SourceMapHookPlugin.js +21 -33
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +23 -30
- package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
- package/lib/plugins/index.js +100 -91
- package/lib/plugins/webpackwatchrunplugin.js +18 -30
- package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
- package/lib/schemas/index.js +336 -81
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +84 -91
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/impactServer.js +99 -92
- package/lib/servers/mockserver.js +24 -24
- package/lib/servers/scrServer.js +78 -98
- package/lib/servers/server.js +101 -122
- package/lib/servers/ssServer.js +63 -61
- package/lib/sh/reportPublish.sh +1 -2
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +6 -4
- package/lib/utils/babelPresets.js +12 -5
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +12 -34
- package/lib/utils/copyTimezones.js +9 -16
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +44 -73
- package/lib/utils/cssURLReplacer.js +62 -56
- package/lib/utils/dependencyPostPublish.js +20 -19
- package/lib/utils/fileUtils.js +66 -54
- package/lib/utils/folderIterator.js +20 -21
- package/lib/utils/getComponents.js +70 -27
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +114 -187
- package/lib/utils/getHash.js +9 -13
- package/lib/utils/getIp.js +9 -9
- package/lib/utils/getOptions.js +26 -29
- package/lib/utils/getServerURL.js +19 -10
- package/lib/utils/index.js +147 -126
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +40 -32
- package/lib/utils/jsonHelper.js +37 -21
- package/lib/utils/lint/addScripts.js +27 -0
- package/lib/utils/lint/checkExistingConfig.js +67 -0
- package/lib/utils/lint/copyConfigs.js +24 -0
- package/lib/utils/lint/index.js +54 -0
- package/lib/utils/lint/lintScripts.js +11 -0
- package/lib/utils/lint/lintSetup.js +31 -0
- package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
- package/lib/utils/lint/question.js +30 -0
- package/lib/utils/lintReporter.js +70 -56
- package/lib/utils/mailSender.js +12 -27
- package/lib/utils/pullOrigin.js +21 -18
- package/lib/utils/reinstallDependencies.js +76 -85
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +47 -45
- package/lib/utils/request.js +64 -77
- package/lib/utils/rtl.js +22 -29
- package/lib/utils/setEnvVariables.js +5 -6
- package/lib/utils/ssTestHack.js +21 -19
- package/lib/utils/switchBranch.js +21 -20
- package/lib/utils/urlConcat.js +22 -0
- package/package.json +72 -67
|
@@ -1,42 +1,28 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var CleanUpStatsPlugin = function () {
|
|
12
|
-
function CleanUpStatsPlugin() {
|
|
13
|
-
_classCallCheck(this, CleanUpStatsPlugin);
|
|
8
|
+
class CleanUpStatsPlugin {
|
|
9
|
+
shouldPickStatChild(child) {
|
|
10
|
+
return child.name.indexOf('mini-css-extract-plugin') !== 0;
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (Array.isArray(children)) {
|
|
30
|
-
// eslint-disable-next-line no-param-reassign
|
|
31
|
-
stats.compilation.children = children.filter(function (child) {
|
|
32
|
-
return _this.shouldPickStatChild(child);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}]);
|
|
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
|
+
}
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
}();
|
|
26
|
+
}
|
|
41
27
|
|
|
42
28
|
exports.default = CleanUpStatsPlugin;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CustomAttributePlugin = void 0;
|
|
7
|
+
|
|
8
|
+
var _Template = _interopRequireDefault(require("webpack/lib/Template"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-use-before-define */
|
|
13
|
+
class CustomAttributePlugin {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = {
|
|
16
|
+
jsAttributes: options.jsAttributes || options.attributes || {},
|
|
17
|
+
cssAttributes: options.cssAttributes || options.attributes || {},
|
|
18
|
+
i18nAttributes: options.i18nAttributes || options.attributes || {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
addCustomAttributeToDynamicScriptTags(mainTemplate) {
|
|
23
|
+
const {
|
|
24
|
+
jsAttributes,
|
|
25
|
+
cssAttributes,
|
|
26
|
+
i18nAttributes
|
|
27
|
+
} = this.options; // NOTE: To add custom Attributes to js Script tags
|
|
28
|
+
|
|
29
|
+
mainTemplate.hooks.jsonpScript.tap('CustomAttributePlugin', source => {
|
|
30
|
+
const str = attributeSetTemplate(jsAttributes, 'script');
|
|
31
|
+
return _Template.default.asString([source, ...str]);
|
|
32
|
+
}); // NOTE: To add custom Attributes to css link tags
|
|
33
|
+
|
|
34
|
+
mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
|
|
35
|
+
const str = attributeSetTemplate(cssAttributes, 'linkTag');
|
|
36
|
+
const replacedStr = source.replace('head.appendChild(linkTag);', `${str.join('')}head.appendChild(linkTag);`);
|
|
37
|
+
console.log({
|
|
38
|
+
s: source,
|
|
39
|
+
r: replacedStr
|
|
40
|
+
});
|
|
41
|
+
return replacedStr;
|
|
42
|
+
}); // NOTE: To add custom Attributes to i18n split js Script tags
|
|
43
|
+
|
|
44
|
+
mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
|
|
45
|
+
const str = attributeSetTemplate(i18nAttributes, 'scriptTag');
|
|
46
|
+
const replacedStr = source.replace('document.body.appendChild(scriptTag);', `${str.join('')}document.body.appendChild(scriptTag);`);
|
|
47
|
+
console.log({
|
|
48
|
+
s: source,
|
|
49
|
+
r: replacedStr
|
|
50
|
+
});
|
|
51
|
+
return replacedStr;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
apply(compiler) {
|
|
56
|
+
compiler.hooks.thisCompilation.tap({
|
|
57
|
+
name: 'CustomAttributePlugin',
|
|
58
|
+
stage: 1,
|
|
59
|
+
fn: compilation => {
|
|
60
|
+
this.addCustomAttributeToDynamicScriptTags(compilation.mainTemplate);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.CustomAttributePlugin = CustomAttributePlugin;
|
|
68
|
+
|
|
69
|
+
function attributeSetTemplate(jsAttributes, variableName) {
|
|
70
|
+
let str = [];
|
|
71
|
+
Object.keys(jsAttributes).forEach(key => {
|
|
72
|
+
const val = jsAttributes[key];
|
|
73
|
+
str.push(`${variableName}.setAttribute(${JSON.stringify(key)}, ${JSON.stringify(val)});`);
|
|
74
|
+
});
|
|
75
|
+
console.log({
|
|
76
|
+
str
|
|
77
|
+
});
|
|
78
|
+
return str;
|
|
79
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# CustomAttributePlugin
|
|
2
|
+
In this plugin we added all dynamic chunks tags (like js script tags , css script tags, i18n split script tags) to extra custom attribute
|
|
3
|
+
|
|
4
|
+
## Options
|
|
5
|
+
|
|
6
|
+
```json
|
|
7
|
+
{
|
|
8
|
+
"name": "some",
|
|
9
|
+
"react-cli": {
|
|
10
|
+
"app": {
|
|
11
|
+
"customAttributes": {// this is the all options
|
|
12
|
+
"enable": false,
|
|
13
|
+
"attributes": null,
|
|
14
|
+
"jsAttributes": null,
|
|
15
|
+
"cssAttributes": null,
|
|
16
|
+
"i18nAttributes": null
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### enable [Boolean]
|
|
23
|
+
this decides is this plugin or feature needs to be enabled of not.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### attributes [Object]
|
|
27
|
+
It was object of key value pairs Example Given Option {"data-app-name":"myapp"}
|
|
28
|
+
Then all dynamically (js script tags , css script tags, i18n split script tags) added tags via webpack
|
|
29
|
+
|
|
30
|
+
### jsAttributes [Object]
|
|
31
|
+
same as [attributes] but only for js script tags
|
|
32
|
+
### cssAttributes [Object]
|
|
33
|
+
same as [attributes] but only for css script tags
|
|
34
|
+
### i18nAttributes [Object]
|
|
35
|
+
same as [attributes] but only for i18n split script tags
|
|
@@ -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 _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
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
// import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
|
|
19
|
+
const cliOptions = (0, _utils.getOptions)();
|
|
20
|
+
const {
|
|
21
|
+
app: {
|
|
22
|
+
publicPaths
|
|
23
|
+
},
|
|
24
|
+
i18n: {
|
|
25
|
+
chunkSplitEnable
|
|
26
|
+
},
|
|
27
|
+
efc: efcOptios
|
|
28
|
+
} = cliOptions;
|
|
29
|
+
const {
|
|
30
|
+
createSDkFile
|
|
31
|
+
} = efcOptios;
|
|
32
|
+
|
|
33
|
+
class EFCPlugin {
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
this.isDevelopment = options.isDevelopment;
|
|
36
|
+
this.serverUrl = options.serverUrl;
|
|
37
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate; // this.i18nManifestFileName = options.i18nManifestFileName;
|
|
38
|
+
|
|
39
|
+
this.options = Object.assign({}, options); // this.options.i18nManifestFileName = options.i18nManifestFileName;
|
|
40
|
+
|
|
41
|
+
this.options.entryPointName = options.entryPointName || 'efc';
|
|
42
|
+
this.options.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
|
|
43
|
+
this.options.nameScope = options.nameScope || 'EFComponents';
|
|
44
|
+
this.options.localeAttr = options.localeAttr || 'efc-locale';
|
|
45
|
+
} // NOTE: this logic may be needed for contenthash cases
|
|
46
|
+
// getI18nManifest(compilation) {
|
|
47
|
+
// const i18nManifestFile =
|
|
48
|
+
// compilation.assets[this.options.i18nManifestFileName];
|
|
49
|
+
// if (i18nManifestFile) {
|
|
50
|
+
// const manifest = JSON.parse(i18nManifestFile.source());
|
|
51
|
+
// return manifest;
|
|
52
|
+
// }
|
|
53
|
+
// return {};
|
|
54
|
+
// }
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
getI18nAssetsStr(entryPoint, compilation) {
|
|
58
|
+
if (!chunkSplitEnable) {
|
|
59
|
+
let i18nAsstes = {};
|
|
60
|
+
let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
|
61
|
+
|
|
62
|
+
i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
|
|
63
|
+
let fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
|
|
64
|
+
let splittedFileName = fileName.split('.');
|
|
65
|
+
res[splittedFileName[0]] = i18nFilePath;
|
|
66
|
+
return res;
|
|
67
|
+
}, {});
|
|
68
|
+
return `[${JSON.stringify(i18nAsstes)}[lang]]`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let initalI18nAssets = entryPoint.chunks.map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
|
|
72
|
+
return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
createFileContent(compilation) {
|
|
76
|
+
const {
|
|
77
|
+
entryPointName,
|
|
78
|
+
localeAttr,
|
|
79
|
+
nameScope,
|
|
80
|
+
cdnVariableName = null
|
|
81
|
+
} = this.options;
|
|
82
|
+
const {
|
|
83
|
+
serverUrl
|
|
84
|
+
} = this; // const i18nManifest = this.getI18nManifest(compilation);
|
|
85
|
+
|
|
86
|
+
const entryPoint = compilation.entrypoints.get(entryPointName); // const chunk = compilation.namedChunks.get(entryPointName);
|
|
87
|
+
|
|
88
|
+
const [jsPath, cssPath,,, i18nJsPath] = !this.isDevelopment ? publicPaths : [];
|
|
89
|
+
const initialFiles = entryPoint.getFiles();
|
|
90
|
+
const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file)); // const i18nAssets = getShortI18nAssets(
|
|
91
|
+
// entryPoint.chunks,
|
|
92
|
+
// i18nManifest,
|
|
93
|
+
// i18nJsPath
|
|
94
|
+
// );
|
|
95
|
+
|
|
96
|
+
const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, i18nJsPath);
|
|
97
|
+
return `(() => {
|
|
98
|
+
let langEle = document.querySelector("[${localeAttr}]");
|
|
99
|
+
let lang = langEle ? langEle.getAttribute('${localeAttr}') : 'en_US';
|
|
100
|
+
let prod = !${this.isDevelopment};
|
|
101
|
+
let cdnVariableName = "${cdnVariableName}";
|
|
102
|
+
let assetURLs = {
|
|
103
|
+
//hook
|
|
104
|
+
js: ${JSON.stringify(jsPath || serverUrl)},
|
|
105
|
+
css: ${JSON.stringify(cssPath || serverUrl)},
|
|
106
|
+
i18n: ${JSON.stringify(i18nJsPath || serverUrl)}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
window.desk_urls={}
|
|
110
|
+
window.desk_urls.staticDomain = 'https:' + assetURLs.js + '/';
|
|
111
|
+
if (prod && cdnVariableName) {
|
|
112
|
+
window["${cdnVariableName}"] = 'https:' + assetURLs.css + '/';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let initalI18nAssets = ${initalI18nAssets}.map(urlpath => "${i18nJsPath}/"+ urlpath);
|
|
116
|
+
let initialAssets = initalI18nAssets.concat(${JSON.stringify(filteredInitialFiles)});
|
|
117
|
+
|
|
118
|
+
let loadAsset = (id, type, url) => {
|
|
119
|
+
return new Promise((res, rej) => {
|
|
120
|
+
let el = document.createElement(type);
|
|
121
|
+
// el.id = id;
|
|
122
|
+
el.onload = res;
|
|
123
|
+
el.error = rej;
|
|
124
|
+
switch(type) {
|
|
125
|
+
case 'script':
|
|
126
|
+
case 'i18n':
|
|
127
|
+
el.src = (type === 'i18n'? assetURLs.i18n : assetURLs.js)+'/'+url
|
|
128
|
+
el.defer = 'defer';
|
|
129
|
+
document.body.appendChild(el);
|
|
130
|
+
break;
|
|
131
|
+
case 'link':
|
|
132
|
+
el.href = assetURLs.css+'/'+url
|
|
133
|
+
el.rel = 'stylesheet';
|
|
134
|
+
document.head.appendChild(el);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
let memorizedPromise = null;
|
|
141
|
+
${nameScope}.onload = (cb, err) => {
|
|
142
|
+
if(!memorizedPromise) {
|
|
143
|
+
memorizedPromise = Promise.all(
|
|
144
|
+
initialAssets.map(
|
|
145
|
+
(url, index) => loadAsset(
|
|
146
|
+
"${nameScope}-" + (url.endsWith("js") ? "js" : "css") +"-"+index,
|
|
147
|
+
url.endsWith("js") ? url.endsWith(".i18n.js") ? "i18n" : 'script' : 'link',
|
|
148
|
+
url
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
).then(() => ${nameScope}.onBasicLoad(cb));
|
|
152
|
+
}
|
|
153
|
+
return memorizedPromise;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
})();
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
apply(compiler) {
|
|
161
|
+
if (!createSDkFile) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
compiler.hooks.emit.tap('EFCPlugin', compilation => {
|
|
166
|
+
const {
|
|
167
|
+
entryPointName,
|
|
168
|
+
outputFile
|
|
169
|
+
} = this.options;
|
|
170
|
+
const entryPoint = compilation.entrypoints.get(entryPointName);
|
|
171
|
+
|
|
172
|
+
if (!entryPoint) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const source = new _webpackSources.RawSource(this.createFileContent(compilation));
|
|
177
|
+
compilation.assets[outputFile] = source; // eslint-disable-next-line no-console
|
|
178
|
+
|
|
179
|
+
console.log('The EFC embedded code was created successfully..!!!');
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
exports.default = EFCPlugin;
|
|
@@ -1,75 +1,141 @@
|
|
|
1
|
-
|
|
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
|
|
8
|
+
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _utils = require("../utils");
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _urlConcat = require("../utils/urlConcat");
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
15
|
|
|
15
|
-
var _webpackSources = require(
|
|
16
|
+
var _webpackSources = require("webpack-sources");
|
|
17
|
+
|
|
18
|
+
var _hashUtils = require("./I18nSplitPlugin/utils/hashUtils");
|
|
19
|
+
|
|
20
|
+
var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
|
|
16
21
|
|
|
17
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
let i18nObj = null;
|
|
25
|
+
let options = (0, _utils.getOptions)();
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
function newAssign(target, data) {
|
|
28
|
+
return Object.assign({}, target, data);
|
|
29
|
+
}
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
const {
|
|
32
|
+
i18n
|
|
33
|
+
} = options;
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
class I18NInjectIntoIndexPlugin {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.isDevelopment = options.isDevelopment;
|
|
38
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate;
|
|
28
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
|
+
});
|
|
29
79
|
}
|
|
30
80
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
res[splittedFileName[0]] = fileName;
|
|
50
|
-
}
|
|
51
|
-
return res;
|
|
52
|
-
}, {});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var _Object$keys$filter = Object.keys(compilation.assets).filter(function (filename) {
|
|
56
|
-
return (/\.html$/g.test(filename)
|
|
57
|
-
);
|
|
58
|
-
}),
|
|
59
|
-
_Object$keys$filter2 = _slicedToArray(_Object$keys$filter, 1),
|
|
60
|
-
indexFile = _Object$keys$filter2[0];
|
|
61
|
-
|
|
62
|
-
if (indexFile) {
|
|
63
|
-
var source = compilation.assets[indexFile].source();
|
|
64
|
-
compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), function (match, arg) {
|
|
65
|
-
return match.replace(arg, JSON.stringify(i18nObj));
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
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);
|
|
68
98
|
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
apply(compiler) {
|
|
103
|
+
if (i18n.chunkSplitEnable) {
|
|
104
|
+
this.withI18nSpitHandling(compiler);
|
|
105
|
+
} else {
|
|
106
|
+
this.withoutI18nSpitHandling(compiler);
|
|
69
107
|
}
|
|
70
|
-
}
|
|
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
|
+
}
|
|
71
138
|
|
|
72
|
-
|
|
73
|
-
}();
|
|
139
|
+
}
|
|
74
140
|
|
|
75
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;
|