@zohodesk/react-cli 0.0.1-test.148.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintignore +7 -7
- package/.eslintrc.js +180 -183
- package/.prettierrc +6 -0
- package/{CHANGELOG.md → CHANGELOG-fz.md} +0 -0
- package/Changelog.md +1019 -0
- package/README.md +1152 -678
- package/bin/cli.js +483 -392
- package/docs/CustomChunks.md +26 -0
- package/docs/DevServerPort.md +39 -0
- package/docs/DevStart.md +18 -0
- package/docs/HoverActive.md +12 -0
- package/docs/InstallNode.md +28 -0
- package/docs/SelectorWeight.md +6 -0
- package/docs/TODOS.md +10 -0
- package/docs/ValueReplacer.md +60 -0
- package/docs/VariableConversion.md +724 -0
- package/docs/warnings_while_install.txt +35 -0
- package/files/eslintrc.js +62 -62
- package/files/prettierrc.js +3 -3
- package/lib/common/index.js +6 -6
- package/lib/common/splitChunks.js +60 -12
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/testPattern.js +69 -0
- package/lib/common/valueReplacer.js +55 -0
- package/lib/configs/jest.config.js +18 -8
- package/lib/configs/libAlias.js +38 -0
- package/lib/configs/resolvers.js +40 -0
- package/lib/configs/webpack.css.umd.config.js +4 -4
- package/lib/configs/webpack.dev.config.js +59 -54
- package/lib/configs/webpack.docs.config.js +56 -53
- package/lib/configs/webpack.impact.config.js +54 -50
- package/lib/configs/webpack.prod.config.js +72 -47
- package/lib/constants.js +31 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -7
- package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
- package/lib/loaderUtils/getCSSLoaders.js +89 -21
- package/lib/loaderUtils/index.js +4 -4
- package/lib/loaderUtils/windowsModification.js +11 -0
- package/lib/loaders/fileBountryLoader.js +17 -0
- package/lib/loaders/scriptInstrumentLoader.js +2 -2
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +9 -9
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +59 -0
- package/lib/pluginUtils/getDevPlugins.js +68 -45
- package/lib/pluginUtils/getDocsPlugins.js +6 -8
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getProdPlugins.js +72 -58
- package/lib/pluginUtils/index.js +12 -12
- package/lib/plugins/CdnChangePlugin.js +16 -2
- package/lib/plugins/EFCPlugin.js +52 -20
- package/lib/plugins/EFCPlugin.md +6 -0
- package/lib/plugins/EFCTemplatePlugin.js +151 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +4 -4
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +38 -38
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +30 -30
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +8 -8
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -86
- package/lib/plugins/I18nSplitPlugin/README.md +25 -25
- package/lib/plugins/I18nSplitPlugin/index.js +57 -57
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +2 -2
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +1 -1
- package/lib/plugins/ManifestPlugin.js +8 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +17 -17
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +6 -6
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
- package/lib/plugins/SelectorPlugin.js +97 -0
- package/lib/plugins/ServiceWorkerPlugin.js +13 -9
- package/lib/plugins/SourceMapHookPlugin.js +9 -3
- package/lib/plugins/TPHashMappingPlugin.js +4 -4
- package/lib/plugins/VariableConversionCollector.js +352 -0
- package/lib/plugins/composeCommonPlugin.js +30 -0
- package/lib/plugins/index.js +36 -36
- package/lib/plugins/libraryImpactPlugin.js +14 -2
- package/lib/postcss-plugins/{ExcludeRTLPlugin.js → ExcludePlugin.js} +1 -1
- package/lib/postcss-plugins/RTLSplitPlugin.js +13 -13
- package/lib/postcss-plugins/ValueReplacer.js +46 -0
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +22 -0
- package/lib/postcss-plugins/__test__/test1Input.css +39 -0
- package/lib/postcss-plugins/__test__/test1Output.css +39 -0
- package/lib/postcss-plugins/hoverActivePlugin.js +389 -0
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +60 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +307 -0
- package/lib/postcss-plugins/variableModifier.js +244 -0
- package/lib/schemas/index.js +165 -11
- package/lib/servers/devBuild.js +102 -0
- package/lib/servers/docsServerCore.js +16 -18
- package/lib/servers/getCliPath.js +28 -0
- package/lib/servers/httpsOptions.js +49 -0
- package/lib/servers/nowatchserver.js +206 -0
- package/lib/servers/server.js +114 -82
- package/lib/sh/pre-commit.sh +34 -34
- package/lib/sh/reportPublish.sh +45 -45
- package/lib/templates/linterConstant.js +1 -1
- package/lib/utils/buildstats.html +148 -148
- package/lib/utils/cssClassNameGenerate.js +9 -2
- package/lib/utils/cssURLReplacer.js +30 -43
- package/lib/utils/getCurrentBranch.js +1 -1
- package/lib/utils/getDependenciesImpactList.js +14 -12
- package/lib/utils/getFileType.js +49 -0
- package/lib/utils/getOptions.js +118 -10
- package/lib/utils/index.js +44 -20
- package/lib/utils/jsonHelper.js +12 -3
- package/lib/utils/reinstallDependencies.js +1 -1
- package/lib/utils/repoClone.js +16 -4
- package/lib/utils/resultSchema.json +73 -73
- package/lib/utils/rtl.js +19 -2
- package/lib/utils/useExitCleanup.js +55 -0
- package/npm8.md +9 -0
- package/package.json +121 -142
- package/postpublish.js +8 -0
- package/result.json +1 -0
- package/templates/app/.eslintrc.js +140 -140
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -24
- package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
- package/templates/app/app/properties/i18nkeys.json +3 -3
- package/templates/app/docs/all.html +69 -69
- package/templates/app/mockapi/index.js +18 -18
- package/templates/app/package.json +37 -37
- package/templates/app/src/actions/SampleActions/index.js +37 -37
- package/templates/app/src/actions/index.js +65 -65
- package/templates/app/src/appUrls.js +19 -19
- package/templates/app/src/components/Alert/Alert.js +134 -134
- package/templates/app/src/components/Alert/Alert.module.css +79 -79
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -37
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -84
- package/templates/app/src/components/Sample/Sample.module.css +11 -11
- package/templates/app/src/components/Sample/SampleList.js +61 -61
- package/templates/app/src/components/Slider/Slider.css +41 -41
- package/templates/app/src/components/Slider/Slider.js +55 -55
- package/templates/app/src/containers/AlertContainer/index.js +15 -15
- package/templates/app/src/containers/AppContainer/index.js +96 -96
- package/templates/app/src/containers/AppContainer/index.module.css +27 -27
- package/templates/app/src/containers/CustomMatch/index.js +65 -65
- package/templates/app/src/containers/DevTools/index.js +10 -10
- package/templates/app/src/containers/Header/index.js +67 -67
- package/templates/app/src/containers/Header/index.module.css +43 -43
- package/templates/app/src/containers/Redirect/index.js +63 -63
- package/templates/app/src/containers/Redirector/index.js +47 -47
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -42
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -3
- package/templates/app/src/historyChange.js +5 -5
- package/templates/app/src/index.html +10 -10
- package/templates/app/src/index.js +24 -24
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -59
- package/templates/app/src/reducers/alertData.js +11 -11
- package/templates/app/src/reducers/index.js +6 -6
- package/templates/app/src/reducers/samples.js +19 -19
- package/templates/app/src/store/configureStore.dev.js +51 -51
- package/templates/app/src/store/configureStore.js +5 -5
- package/templates/app/src/store/configureStore.prod.js +26 -26
- package/templates/app/src/util/Common.js +5 -5
- package/templates/app/src/util/RequestAPI.js +132 -132
- package/templates/docs/all.html +249 -249
- package/templates/docs/component.html +178 -178
- package/templates/docs/components.html +221 -221
- package/templates/docs/css/b.min.css +6 -6
- package/templates/docs/css/component.css +42 -42
- package/templates/docs/css/componentTest.css +6 -6
- package/templates/docs/css/hopscotch.css +585 -585
- package/templates/docs/css/style.css +1022 -1022
- package/templates/docs/impactReportTemplate.html +154 -154
- package/templates/docs/index.html +1501 -1493
- package/templates/docs/js/active-line.js +72 -72
- package/templates/docs/js/b.min.js +7 -7
- package/templates/docs/js/codemirror.js +9680 -9680
- package/templates/docs/js/designTokens.js +334 -334
- package/templates/docs/js/j.min.js +4 -4
- package/templates/docs/js/javascript.js +874 -874
- package/templates/docs/js/matchbrackets.js +145 -145
- package/unittest/index.html +37 -0
- package/cert/cert.pem +0 -105
- package/cert/key.pem +0 -30
package/lib/pluginUtils/index.js
CHANGED
@@ -9,34 +9,28 @@ Object.defineProperty(exports, "getDevPlugins", {
|
|
9
9
|
return _getDevPlugins.default;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
Object.defineProperty(exports, "getProdPlugins", {
|
13
|
-
enumerable: true,
|
14
|
-
get: function () {
|
15
|
-
return _getProdPlugins.default;
|
16
|
-
}
|
17
|
-
});
|
18
12
|
Object.defineProperty(exports, "getDocsPlugins", {
|
19
13
|
enumerable: true,
|
20
14
|
get: function () {
|
21
15
|
return _getDocsPlugins.default;
|
22
16
|
}
|
23
17
|
});
|
24
|
-
Object.defineProperty(exports, "
|
18
|
+
Object.defineProperty(exports, "getLibraryPlugins", {
|
25
19
|
enumerable: true,
|
26
20
|
get: function () {
|
27
|
-
return
|
21
|
+
return _getLibraryPlugins.default;
|
28
22
|
}
|
29
23
|
});
|
30
|
-
Object.defineProperty(exports, "
|
24
|
+
Object.defineProperty(exports, "getProdPlugins", {
|
31
25
|
enumerable: true,
|
32
26
|
get: function () {
|
33
|
-
return
|
27
|
+
return _getProdPlugins.default;
|
34
28
|
}
|
35
29
|
});
|
36
|
-
Object.defineProperty(exports, "
|
30
|
+
Object.defineProperty(exports, "getServerPlugins", {
|
37
31
|
enumerable: true,
|
38
32
|
get: function () {
|
39
|
-
return
|
33
|
+
return _getServerPlugins.default;
|
40
34
|
}
|
41
35
|
});
|
42
36
|
Object.defineProperty(exports, "getUMDCSSPlugins", {
|
@@ -45,6 +39,12 @@ Object.defineProperty(exports, "getUMDCSSPlugins", {
|
|
45
39
|
return _getUMDCSSPlugins.default;
|
46
40
|
}
|
47
41
|
});
|
42
|
+
Object.defineProperty(exports, "getUMDComponentPlugins", {
|
43
|
+
enumerable: true,
|
44
|
+
get: function () {
|
45
|
+
return _getUMDComponentPlugins.default;
|
46
|
+
}
|
47
|
+
});
|
48
48
|
|
49
49
|
var _getDevPlugins = _interopRequireDefault(require("./getDevPlugins"));
|
50
50
|
|
@@ -7,11 +7,19 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
9
9
|
|
10
|
+
var _utils = require("../utils");
|
11
|
+
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
13
|
|
12
14
|
const MODULE_TYPE = 'css/mini-extract';
|
13
15
|
|
14
|
-
const isI18nFile = url => url.endsWith(
|
16
|
+
const isI18nFile = url => url.endsWith('.i18n.js');
|
17
|
+
|
18
|
+
const {
|
19
|
+
app: {
|
20
|
+
enableSMap
|
21
|
+
}
|
22
|
+
} = (0, _utils.getOptions)();
|
15
23
|
|
16
24
|
class CdnChangePlugin {
|
17
25
|
constructor(options) {
|
@@ -50,7 +58,13 @@ class CdnChangePlugin {
|
|
50
58
|
_htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync('CdnChangePlugin', (data, cb) => {
|
51
59
|
data.assets = Object.assign({}, data.assets, {
|
52
60
|
css: data.assets.css.map(css => `${this.cssTemplate}${css}`),
|
53
|
-
js: data.assets.js.map(js =>
|
61
|
+
js: data.assets.js.map(js => {
|
62
|
+
if (enableSMap && !isI18nFile(js)) {
|
63
|
+
js = js.replace('js/', `{{--js-smap}}js/`); //eslint-disable-line
|
64
|
+
}
|
65
|
+
|
66
|
+
return `${isI18nFile(js) ? this.i18nTemplate : this.jsTemplate}${js}`;
|
67
|
+
})
|
54
68
|
});
|
55
69
|
cb(null, data);
|
56
70
|
});
|
package/lib/plugins/EFCPlugin.js
CHANGED
@@ -17,6 +17,8 @@ var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nK
|
|
17
17
|
|
18
18
|
var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
|
19
19
|
|
20
|
+
var _EFCTemplatePlugin = _interopRequireDefault(require("./EFCTemplatePlugin"));
|
21
|
+
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
23
|
|
22
24
|
// import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
|
@@ -34,24 +36,28 @@ const {
|
|
34
36
|
efc: efcOptios
|
35
37
|
} = cliOptions;
|
36
38
|
const {
|
37
|
-
createSDkFile
|
39
|
+
createSDkFile,
|
40
|
+
cdnStatement
|
38
41
|
} = efcOptios;
|
39
42
|
|
40
43
|
class EFCPlugin {
|
41
44
|
constructor(options = {}) {
|
42
45
|
this.isDevelopment = options.isDevelopment;
|
46
|
+
this.templateFilePath = options.templateFilePath;
|
43
47
|
this.serverUrl = options.serverUrl;
|
44
|
-
this.i18nFileNameTemplate = options.i18nFileNameTemplate; // this
|
45
|
-
|
46
|
-
|
48
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
49
|
+
// this.i18nManifestFileName = options.i18nManifestFileName;
|
50
|
+
// IMPORTANT: here we mergeing optionds from pacakge.json and options via constructor
|
51
|
+
// So when debugging consider this as well
|
47
52
|
|
53
|
+
this.options = Object.assign({}, efcOptios, options);
|
48
54
|
this.options.entryPointName = options.entryPointName || 'efc';
|
49
55
|
this.options.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
|
50
56
|
this.options.nameScope = options.nameScope || 'EFComponents';
|
51
|
-
const localeAttr = this.options.localeAttr || 'efc-locale';
|
52
|
-
const cssDirAttr = this.options.cssDirAttr || 'efc-
|
53
|
-
const localeDefaultValue = this.options.
|
54
|
-
const cssDirDefaultValue = this.options.
|
57
|
+
const localeAttr = this.options.localeAttr || 'data-efc-locale';
|
58
|
+
const cssDirAttr = this.options.cssDirAttr || 'data-efc-dir';
|
59
|
+
const localeDefaultValue = this.options.localeDefaultValue || 'en_US';
|
60
|
+
const cssDirDefaultValue = this.options.cssDirDefaultValue || 'ltr';
|
55
61
|
this.options.localeStatement = options.localeStatement || // Statment 1: return langEle && langEle.getAttribute('${localeAttr}') || 'en_US';
|
56
62
|
// Statment 2: return langEle ? langEle.getAttribute('${localeAttr}') : 'en_US';
|
57
63
|
// We are using statement1 not statment2,
|
@@ -64,7 +70,7 @@ class EFCPlugin {
|
|
64
70
|
let dirEle = document.querySelector('[${cssDirAttr}]');
|
65
71
|
return dirEle && dirEle.getAttribute('${cssDirAttr}') || '${cssDirDefaultValue}';
|
66
72
|
})();`;
|
67
|
-
} // NOTE: this logic may be needed for contenthash cases
|
73
|
+
} // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
68
74
|
// getI18nManifest(compilation) {
|
69
75
|
// const i18nManifestFile =
|
70
76
|
// compilation.assets[this.options.i18nManifestFileName];
|
@@ -123,20 +129,35 @@ class EFCPlugin {
|
|
123
129
|
${enableRTLSplit ? `const cssDir = ${cssDirStatement};` : ''}
|
124
130
|
const prod = !${this.isDevelopment};
|
125
131
|
let cdnVariableName = "${cdnVariableName}";
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
+
|
133
|
+
function getAssetUrl(ext) {
|
134
|
+
${cdnStatement ? `
|
135
|
+
return (() => {
|
136
|
+
let fu = (${cdnStatement});
|
137
|
+
return typeof fu === "function" ? fu(ext) : fu;
|
138
|
+
})();` : ''}
|
139
|
+
|
140
|
+
${publicPaths.callback ? `return (${publicPaths.callback})(ext)` : ''}
|
141
|
+
|
142
|
+
let assetURLs = {
|
143
|
+
//hook
|
144
|
+
js: ${JSON.stringify(jsPath || serverUrl)},
|
145
|
+
css: ${JSON.stringify(cssPath || serverUrl)},
|
146
|
+
i18n: ${JSON.stringify(i18nJsPath || serverUrl)}
|
147
|
+
};
|
148
|
+
|
149
|
+
return assetURLs[ext];
|
150
|
+
|
151
|
+
}
|
152
|
+
|
132
153
|
|
133
154
|
window.desk_urls={}
|
134
|
-
window.desk_urls.staticDomain = 'https:' +
|
155
|
+
window.desk_urls.staticDomain = 'https:' + getAssetUrl('js') + '/';
|
135
156
|
if (prod && cdnVariableName) {
|
136
|
-
window["${cdnVariableName}"] = 'https:' +
|
157
|
+
window["${cdnVariableName}"] = 'https:' + getAssetUrl('css') + '/';
|
137
158
|
}
|
138
159
|
|
139
|
-
let initalI18nAssets = ${initalI18nAssets}
|
160
|
+
let initalI18nAssets = ${initalI18nAssets};
|
140
161
|
let initialAssets = initalI18nAssets.concat(${JSON.stringify(enableRTLSplit ? filteredInitialFiles.map(filePath => (0, _replaceCssDirTemplate.replaceCssDirTemplate)(filePath, cssDirTemplate)) : filteredInitialFiles)});
|
141
162
|
|
142
163
|
let loadAsset = (id, type, url) => {
|
@@ -148,12 +169,12 @@ class EFCPlugin {
|
|
148
169
|
switch(type) {
|
149
170
|
case 'script':
|
150
171
|
case 'i18n':
|
151
|
-
el.src = (type === 'i18n'?
|
172
|
+
el.src = (type === 'i18n'? getAssetUrl('i18n') : getAssetUrl('js'))+'/'+url
|
152
173
|
el.defer = 'defer';
|
153
174
|
document.body.appendChild(el);
|
154
175
|
break;
|
155
176
|
case 'link':
|
156
|
-
el.href =
|
177
|
+
el.href = getAssetUrl('css')+'/'+url${enableRTLSplit ? `.replace(${JSON.stringify(cssDirTemplate)}, cssDir)` : ''}
|
157
178
|
el.rel = 'stylesheet';
|
158
179
|
document.head.appendChild(el);
|
159
180
|
break;
|
@@ -184,6 +205,17 @@ class EFCPlugin {
|
|
184
205
|
apply(compiler) {
|
185
206
|
if (!createSDkFile) {
|
186
207
|
return;
|
208
|
+
} //console.log('this.templateFilePath', this.templateFilePath, this.options);
|
209
|
+
|
210
|
+
|
211
|
+
if (this.templateFilePath) {
|
212
|
+
new _EFCTemplatePlugin.default({
|
213
|
+
templateFilePath: this.templateFilePath,
|
214
|
+
publicPath: this.serverUrl,
|
215
|
+
i18nFileNameTemplate: this.i18nFileNameTemplate,
|
216
|
+
entryPointName: this.options.entryPointName
|
217
|
+
}).apply(compiler);
|
218
|
+
return;
|
187
219
|
}
|
188
220
|
|
189
221
|
compiler.hooks.emit.tap('EFCPlugin', compilation => {
|
@@ -0,0 +1,151 @@
|
|
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 _fs = require("fs");
|
15
|
+
|
16
|
+
var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
|
17
|
+
|
18
|
+
var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nKeysIdentifer"));
|
19
|
+
|
20
|
+
var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
|
21
|
+
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
+
|
24
|
+
// import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
|
25
|
+
const cliOptions = (0, _utils.getOptions)();
|
26
|
+
const {
|
27
|
+
i18n: {
|
28
|
+
chunkSplitEnable
|
29
|
+
},
|
30
|
+
css: {
|
31
|
+
enableRTLSplit
|
32
|
+
},
|
33
|
+
efc: efcOptios
|
34
|
+
} = cliOptions;
|
35
|
+
const {
|
36
|
+
createSDkFile
|
37
|
+
} = efcOptios; // for smap relate changes
|
38
|
+
// CdnChangePlugin
|
39
|
+
// SourceMapHookPlugin
|
40
|
+
|
41
|
+
class EFCTemplatePlugin {
|
42
|
+
constructor(options = {}) {
|
43
|
+
// console.log(' templateFilePath ', process.cwd(), options.templateFilePath, templateFilePath);
|
44
|
+
this.templateFilePath = _path.default.join(process.cwd(), options.templateFilePath); // console.log(' templateFilePath ', this.templateFilePath);
|
45
|
+
|
46
|
+
this.i18nFileNameTemplate = options.i18nFileNameTemplate;
|
47
|
+
this.publicPath = options.publicPath; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
48
|
+
// this.i18nManifestFileName = options.i18nManifestFileName;
|
49
|
+
// IMPORTANT: here we mergeing optionds from pacakge.json and options via constructor
|
50
|
+
// So when debugging consider this as well
|
51
|
+
// this.options = Object.assign({}, efcOptios, options);
|
52
|
+
|
53
|
+
this.entryPointName = options.entryPointName || 'efc';
|
54
|
+
this.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
|
55
|
+
} // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
56
|
+
// getI18nManifest(compilation) {
|
57
|
+
// const i18nManifestFile =
|
58
|
+
// compilation.assets[this.options.i18nManifestFileName];
|
59
|
+
// if (i18nManifestFile) {
|
60
|
+
// const manifest = JSON.parse(i18nManifestFile.source());
|
61
|
+
// return manifest;
|
62
|
+
// }
|
63
|
+
// return {};
|
64
|
+
// }
|
65
|
+
|
66
|
+
|
67
|
+
getI18nAssetsStr(entryPoint, compilation) {
|
68
|
+
// NOTE: we have used lang variable inside
|
69
|
+
if (!chunkSplitEnable) {
|
70
|
+
let i18nAsstes = {};
|
71
|
+
let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
72
|
+
|
73
|
+
i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
|
74
|
+
let fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
|
75
|
+
let splittedFileName = fileName.split('.');
|
76
|
+
res[splittedFileName[0]] = i18nFilePath;
|
77
|
+
return res;
|
78
|
+
}, {});
|
79
|
+
return `[${JSON.stringify(i18nAsstes)}[lang]]`;
|
80
|
+
}
|
81
|
+
|
82
|
+
let initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
|
83
|
+
return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
|
84
|
+
}
|
85
|
+
|
86
|
+
templateReplacer(entryPoint, compilation) {
|
87
|
+
const cssDirTemplate = '@dir@'; // const i18nManifest = this.getI18nManifest(compilation);
|
88
|
+
|
89
|
+
const initialFiles = entryPoint.getFiles();
|
90
|
+
const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file));
|
91
|
+
const initialJsFiles = filteredInitialFiles.filter(file => /\.js$/.test(file));
|
92
|
+
let initialCssFiles = filteredInitialFiles.filter(file => /\.css$/.test(file));
|
93
|
+
|
94
|
+
if (enableRTLSplit) {
|
95
|
+
initialCssFiles = initialCssFiles.map(filePath => (0, _replaceCssDirTemplate.replaceCssDirTemplate)(filePath, cssDirTemplate));
|
96
|
+
} // const i18nAssets = getShortI18nAssets(
|
97
|
+
// entryPoint.chunks,
|
98
|
+
// i18nManifest,
|
99
|
+
// '' // i18nJsPath
|
100
|
+
// );
|
101
|
+
|
102
|
+
|
103
|
+
const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, '' // i18nJsPath
|
104
|
+
);
|
105
|
+
let templateStr = (0, _fs.readFileSync)(this.templateFilePath).toString();
|
106
|
+
return templateStr.replace('((\'getInitalAssets\'))', `function getInitalAssets(assetsType, lang) {
|
107
|
+
if (assetsType === "js") {
|
108
|
+
return ${JSON.stringify(initialJsFiles)}
|
109
|
+
}
|
110
|
+
if (assetsType === "css") {
|
111
|
+
return ${JSON.stringify(initialCssFiles)}
|
112
|
+
}
|
113
|
+
if (assetsType === "i18n") {
|
114
|
+
return ${initalI18nAssets};
|
115
|
+
}
|
116
|
+
return [];
|
117
|
+
}`).replace('((\'@dir@\'))', '\'@dir@\'').replace('((\'publicPath\'))', this.publicPath).replace('((\'@locale@\'))', '\'@locale@\'');
|
118
|
+
}
|
119
|
+
|
120
|
+
apply(compiler) {
|
121
|
+
if (!createSDkFile) {
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
|
125
|
+
compiler.hooks.emit.tap('EFCTemplatePlugin', compilation => {
|
126
|
+
const {
|
127
|
+
entryPointName,
|
128
|
+
outputFile
|
129
|
+
} = this;
|
130
|
+
const entryPoint = compilation.entrypoints.get(entryPointName);
|
131
|
+
|
132
|
+
if (!entryPoint) {
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
|
136
|
+
if (!(0, _fs.existsSync)(this.templateFilePath)) {
|
137
|
+
console.error(`EFC Template file not exists ${this.templateFilePath}`);
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
|
141
|
+
const source = new _webpackSources.RawSource(this.templateReplacer(entryPoint, compilation));
|
142
|
+
compilation.assets[outputFile] = source; // console.log('EFCTemplatePlugin working');
|
143
|
+
// eslint-disable-next-line no-console
|
144
|
+
|
145
|
+
console.log('The EFC embedded code was created successfully..!!!');
|
146
|
+
});
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
exports.default = EFCTemplatePlugin;
|
@@ -116,10 +116,10 @@ class I18NInjectIntoIndexPlugin {
|
|
116
116
|
i18nObj = i18nFiles.reduce((res, next) => {
|
117
117
|
let fileName = next.replace(`i18n${_path.default.sep}`, '');
|
118
118
|
let splittedFileName = fileName.split('.');
|
119
|
-
/* if (this.isDevelopment) {
|
120
|
-
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
121
|
-
} else {
|
122
|
-
res[splittedFileName[0]] = fileName;
|
119
|
+
/* if (this.isDevelopment) {
|
120
|
+
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
121
|
+
} else {
|
122
|
+
res[splittedFileName[0]] = fileName;
|
123
123
|
} */
|
124
124
|
|
125
125
|
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
@@ -13,23 +13,23 @@ var _hashUtils = require("./utils/hashUtils");
|
|
13
13
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
15
|
|
16
|
-
/**
|
17
|
-
* this plugin for the download i18n files
|
18
|
-
* So, if need to downoad i18n in browser this plugin handle that
|
19
|
-
*
|
20
|
-
*
|
21
|
-
* this plugin works
|
22
|
-
* how it works?
|
23
|
-
* this plugin hook the requireEnsure method and we write logic for current compiled file download logic
|
24
|
-
*
|
25
|
-
* hinds:-
|
26
|
-
* requireEnsure method was loader for all js chunk's ,
|
27
|
-
* which means if we use dynamic import then this function will create script tag for that dynamic resource
|
28
|
-
* so every dynamic js chunk will load by this function,
|
29
|
-
* So we update this function with when dynamic jschunk call the nour code also execute
|
30
|
-
*
|
31
|
-
* some thing missing in this definetion
|
32
|
-
*
|
16
|
+
/**
|
17
|
+
* this plugin for the download i18n files
|
18
|
+
* So, if need to downoad i18n in browser this plugin handle that
|
19
|
+
*
|
20
|
+
*
|
21
|
+
* this plugin works
|
22
|
+
* how it works?
|
23
|
+
* this plugin hook the requireEnsure method and we write logic for current compiled file download logic
|
24
|
+
*
|
25
|
+
* hinds:-
|
26
|
+
* requireEnsure method was loader for all js chunk's ,
|
27
|
+
* which means if we use dynamic import then this function will create script tag for that dynamic resource
|
28
|
+
* so every dynamic js chunk will load by this function,
|
29
|
+
* So we update this function with when dynamic jschunk call the nour code also execute
|
30
|
+
*
|
31
|
+
* some thing missing in this definetion
|
32
|
+
*
|
33
33
|
*/
|
34
34
|
// import { REGEXP_HASH, REGEXP_CHUNKHASH } from './utils/hashUtils';
|
35
35
|
const pluginName = 'DownloadLogicOfI18n'; // const pluginName = 'i18n-plugin';
|
@@ -126,20 +126,20 @@ class I18nDownlodLogic {
|
|
126
126
|
return _webpack.Template.asString([source, '', '// object to store loaded I18N chunks', 'var installedI18nChunks = {', _webpack.Template.indent(mainChunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};']);
|
127
127
|
});
|
128
128
|
mainTemplate.hooks.requireEnsure.tap(pluginName, (source, mainChunk, hash) => {
|
129
|
-
/**
|
130
|
-
* for Information this is tapped in mainTemplate ,
|
131
|
-
* So this hooks argument chunk is main chunk means entry chunk mostly.
|
132
|
-
* if any chunk has i18n then we must write our download i18n logic,
|
129
|
+
/**
|
130
|
+
* for Information this is tapped in mainTemplate ,
|
131
|
+
* So this hooks argument chunk is main chunk means entry chunk mostly.
|
132
|
+
* if any chunk has i18n then we must write our download i18n logic,
|
133
133
|
*/
|
134
134
|
const chunkMap = this.getI18nChunkObject(mainChunk);
|
135
135
|
|
136
136
|
if (!Object.keys(chunkMap).length) {
|
137
137
|
return source;
|
138
138
|
}
|
139
|
-
/**
|
140
|
-
* chunkMaps has
|
141
|
-
* @property {Object} hash [it has key as chunk id and value as chunkHash ]
|
142
|
-
* @property {Object} name [it has key as chunk id and value as chunk name ]
|
139
|
+
/**
|
140
|
+
* chunkMaps has
|
141
|
+
* @property {Object} hash [it has key as chunk id and value as chunkHash ]
|
142
|
+
* @property {Object} name [it has key as chunk id and value as chunk name ]
|
143
143
|
*/
|
144
144
|
|
145
145
|
|
@@ -176,22 +176,22 @@ class I18nDownlodLogic {
|
|
176
176
|
},
|
177
177
|
contentHashType: MODULE_TYPE
|
178
178
|
});
|
179
|
-
/** IDEA:
|
180
|
-
* as my suggestion ignore this `jsop` approch,
|
181
|
-
* Because json parse is faster then js parse.
|
182
|
-
* my suggestion is make ajax or fetch request
|
179
|
+
/** IDEA:
|
180
|
+
* as my suggestion ignore this `jsop` approch,
|
181
|
+
* Because json parse is faster then js parse.
|
182
|
+
* my suggestion is make ajax or fetch request
|
183
183
|
*/
|
184
184
|
|
185
185
|
const buf = [];
|
186
|
-
/*
|
187
|
-
if (REGEXP_HASH.test(filenameTemplate)) {
|
188
|
-
buf.push(
|
189
|
-
`var hash = ${mainTemplate.renderCurrentHashCode(hash)};`
|
190
|
-
);
|
191
|
-
}
|
192
|
-
if (REGEXP_CHUNKHASH.test(filenameTemplate)) {
|
193
|
-
buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
|
194
|
-
}
|
186
|
+
/*
|
187
|
+
if (REGEXP_HASH.test(filenameTemplate)) {
|
188
|
+
buf.push(
|
189
|
+
`var hash = ${mainTemplate.renderCurrentHashCode(hash)};`
|
190
|
+
);
|
191
|
+
}
|
192
|
+
if (REGEXP_CHUNKHASH.test(filenameTemplate)) {
|
193
|
+
buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
|
194
|
+
}
|
195
195
|
*/
|
196
196
|
|
197
197
|
if ((0, _hashUtils.hasContentHash)(filenameTemplate)) {
|
@@ -13,8 +13,8 @@ var _getI18nKeysFormModules = _interopRequireDefault(require("./utils/getI18nKey
|
|
13
13
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
15
|
|
16
|
-
/**
|
17
|
-
* this plugin was creating the chunk specific i18n chunk's.
|
16
|
+
/**
|
17
|
+
* this plugin was creating the chunk specific i18n chunk's.
|
18
18
|
*/
|
19
19
|
// this plugin's kick starter is apply method
|
20
20
|
const pluginName = 'I18nFilesEmitter';
|
@@ -141,40 +141,40 @@ class I18nFilesEmitter {
|
|
141
141
|
}
|
142
142
|
|
143
143
|
apply(compiler) {
|
144
|
-
/*
|
145
|
-
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
146
|
-
compilation.mainTemplate.hooks.renderManifest.tap(
|
147
|
-
pluginName,
|
148
|
-
(result, { chunk }) => {
|
149
|
-
this.renderChunk(result, compilation, chunk);
|
150
|
-
}
|
151
|
-
);
|
152
|
-
|
153
|
-
pluginName,
|
154
|
-
(result, { chunk }) => {
|
155
|
-
this.renderChunk(result, compilation, chunk);
|
156
|
-
}
|
157
|
-
);
|
158
|
-
});
|
144
|
+
/*
|
145
|
+
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
146
|
+
compilation.mainTemplate.hooks.renderManifest.tap(
|
147
|
+
pluginName,
|
148
|
+
(result, { chunk }) => {
|
149
|
+
this.renderChunk(result, compilation, chunk);
|
150
|
+
}
|
151
|
+
);
|
152
|
+
compilation.chunkTemplate.hooks.renderManifest.tap(
|
153
|
+
pluginName,
|
154
|
+
(result, { chunk }) => {
|
155
|
+
this.renderChunk(result, compilation, chunk);
|
156
|
+
}
|
157
|
+
);
|
158
|
+
});
|
159
159
|
*/
|
160
160
|
// this below hook was tapped for create asssets(file) for chunk specific i18nChunk Files
|
161
161
|
compiler.hooks.emit.tap(pluginName, compilation => {
|
162
162
|
this.emitI18nAssert(compilation);
|
163
163
|
});
|
164
164
|
}
|
165
|
-
/*
|
166
|
-
renderChunk(result, compilation, chunk) {
|
167
|
-
const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
|
168
|
-
// TODO: need to discuss with vimal ji can we chose this place for add i18n locale files ????
|
169
|
-
// IDEA: we chose this place for add i18n locale files ????
|
170
|
-
if (i18nKeys.length > 0) {
|
171
|
-
Object.keys(this.allI18nObject).forEach(locale => {
|
172
|
-
result.push(
|
173
|
-
this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation)
|
174
|
-
);
|
175
|
-
});
|
176
|
-
}
|
177
|
-
}
|
165
|
+
/*
|
166
|
+
renderChunk(result, compilation, chunk) {
|
167
|
+
const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
|
168
|
+
// TODO: need to discuss with vimal ji can we chose this place for add i18n locale files ????
|
169
|
+
// IDEA: we chose this place for add i18n locale files ????
|
170
|
+
if (i18nKeys.length > 0) {
|
171
|
+
Object.keys(this.allI18nObject).forEach(locale => {
|
172
|
+
result.push(
|
173
|
+
this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation)
|
174
|
+
);
|
175
|
+
});
|
176
|
+
}
|
177
|
+
}
|
178
178
|
*/
|
179
179
|
|
180
180
|
|
@@ -14,14 +14,14 @@ var _NullFactory = _interopRequireDefault(require("webpack/lib/NullFactory"));
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
15
|
|
16
16
|
const pluginName = 'I18nKeysIdentifer';
|
17
|
-
/**
|
18
|
-
* this plugin search the i18 keys and make it as I18nDependency.
|
19
|
-
* how it works?
|
20
|
-
* this plugin get jsResourceI18nKeys in constructor.
|
21
|
-
* we walk throught the js files AST
|
22
|
-
* if any string literal in that AST is in jsResourceI18nKeys then we consider that string as I18n key
|
23
|
-
* after the walk of AST we get some I18n keys
|
24
|
-
* then we make it as I18nDependency.
|
17
|
+
/**
|
18
|
+
* this plugin search the i18 keys and make it as I18nDependency.
|
19
|
+
* how it works?
|
20
|
+
* this plugin get jsResourceI18nKeys in constructor.
|
21
|
+
* we walk throught the js files AST
|
22
|
+
* if any string literal in that AST is in jsResourceI18nKeys then we consider that string as I18n key
|
23
|
+
* after the walk of AST we get some I18n keys
|
24
|
+
* then we make it as I18nDependency.
|
25
25
|
*/
|
26
26
|
|
27
27
|
class I18nKeysIdentifer {
|