@zohodesk/react-cli 1.0.2 → 1.0.3-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +24 -0
- package/bin/cli.js +1 -1
- package/lib/common/testPattern.js +0 -2
- package/lib/common/valueReplacer.js +1 -3
- package/lib/configs/resolvers.js +14 -3
- package/lib/loaderUtils/getCSSLoaders.js +2 -7
- package/lib/loaders/selectorMappingLoader.js +9 -9
- package/lib/logger.js +20 -0
- package/lib/pluginUtils/getDevPlugins.js +5 -0
- package/lib/pluginUtils/getProdPlugins.js +4 -0
- package/lib/plugins/CustomAttributePlugin.js +82 -0
- package/lib/plugins/CustomAttributePlugin.md +35 -0
- package/lib/plugins/EFCPlugin.js +9 -9
- package/lib/plugins/EFCTemplatePlugin.js +10 -12
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +8 -9
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +2 -3
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +2 -7
- package/lib/plugins/I18nSplitPlugin/index.js +1 -1
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +8 -8
- package/lib/plugins/SelectorPlugin.js +4 -10
- package/lib/plugins/VariableConversionCollector.js +0 -4
- package/lib/postcss-plugins/IncludePlugin.js +0 -1
- package/lib/postcss-plugins/RTLSplitPlugin.js +4 -10
- package/lib/postcss-plugins/ValueReplacer.js +2 -4
- package/lib/postcss-plugins/hoverActivePlugin.js +0 -6
- package/lib/postcss-plugins/variableModificationPlugin/index.js +1 -2
- package/lib/postcss-plugins/variableModifier.js +24 -58
- package/lib/schemas/index.js +8 -1
- package/lib/servers/devBuild.js +13 -11
- package/lib/servers/httpsOptions.js +12 -13
- package/lib/servers/nowatchserver.js +5 -3
- package/lib/servers/requireLocalOrGlobal.js +61 -0
- package/lib/servers/server.js +1 -3
- package/lib/utils/cssClassNameGenerate.js +11 -12
- package/npm-shrinkwrap.json +14407 -0
- package/package.json +3 -2
- package/result.json +0 -1
- package/unittest/index.html +0 -37
package/README.md
CHANGED
@@ -44,6 +44,21 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.0.3-beta.1
|
48
|
+
|
49
|
+
**Issue Fix**
|
50
|
+
- nock api not working issue fixed. This error throwing in @zohodesk/react-cli@1.0.2 version. but working in older versions ( 0.0.1-beta.178 )
|
51
|
+
|
52
|
+
# 1.0.3
|
53
|
+
|
54
|
+
**Feature Update**
|
55
|
+
- Support for global httpsCerts usage
|
56
|
+
- Support for global client_packages_group usage
|
57
|
+
- custom attribute for dynamically loading chunks, In this version we merged changes from [0.0.1-beta.167.1](#0.0.1-beta.167.1).
|
58
|
+
**Package Update**
|
59
|
+
- @zohodesk/client_packages_group@**1.0.1** ==> @zohodesk/client_packages_group@**1.0.2**
|
60
|
+
|
61
|
+
|
47
62
|
# 1.0.2
|
48
63
|
|
49
64
|
**Feature Update**
|
@@ -264,6 +279,10 @@ Features:-
|
|
264
279
|
|
265
280
|
- In docs we have added `Description` for Component Props- check out it in `PropTypes` tab
|
266
281
|
|
282
|
+
# 0.0.1-beta.167.1
|
283
|
+
In this version we merged changes from [0.0.1-betaa.138.1](#0.0.1-betaa.138.1).
|
284
|
+
and with [0.0.1-beta.167](#0.0.1-beta.167) version changes.
|
285
|
+
|
267
286
|
# 0.0.1-beta.167
|
268
287
|
|
269
288
|
SSL certificate update
|
@@ -525,6 +544,11 @@ impact servise related changes:-
|
|
525
544
|
- babel runtime plugin issue fix in prod config
|
526
545
|
- few enhancements
|
527
546
|
|
547
|
+
# 0.0.1-betaa.138.1
|
548
|
+
- new feature added for custom extra attribute for dynamically added tags by webpack.
|
549
|
+
- To enable this feature you need to enable "react-cli" => "app" => "customAttributes" => "enable"
|
550
|
+
- For more [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/9eea8df14e55584b2114b5e484ca8b751a4ba191/src/plugins/CustomAttributePlugin.md)
|
551
|
+
|
528
552
|
# 0.0.1-beta.138
|
529
553
|
|
530
554
|
- sstest library version updated
|
package/bin/cli.js
CHANGED
@@ -50,7 +50,7 @@ if (preprocesserPath && existsSync(preprocesserPath)) {
|
|
50
50
|
case 'docs':
|
51
51
|
spawn(preprocessCli, [preprocesserPath], {
|
52
52
|
stdio: 'inherit',
|
53
|
-
cwd:
|
53
|
+
cwd: path.parse(preprocesserPath).dir
|
54
54
|
});
|
55
55
|
// NOTE: it's ok if we not close this here
|
56
56
|
// Because when node server stops this program willbe closed So this nodemon will be killed as well
|
@@ -62,8 +62,6 @@ const isRelatedPackage = (req, item) => isRelated(req, `node_modules${_path.sep}
|
|
62
62
|
exports.isRelatedPackage = isRelatedPackage;
|
63
63
|
|
64
64
|
function isDependency(m, excludeList) {
|
65
|
-
// let reasons = m.reasons.map(r => r.module.userRequest);
|
66
|
-
// m.reasons.some(r => !r.module || !r.module.userRequest) && console.log(m.reasons);
|
67
65
|
return m.reasons.some(r => excludeList.some(item => r.module && isRelated(r.module.userRequest, item)));
|
68
66
|
} // export function queryHandler(conditions, pattern) {
|
69
67
|
// }
|
@@ -32,11 +32,9 @@ if (!_fs.default.existsSync(dist)) {
|
|
32
32
|
}
|
33
33
|
|
34
34
|
(0, _folderIterator.default)(src, dist, docopy ? false : ['.css'], false, (fromPath, toPath) => {
|
35
|
-
|
36
|
-
let css = _fs.default.readFileSync(fromPath);
|
35
|
+
const css = _fs.default.readFileSync(fromPath);
|
37
36
|
|
38
37
|
if (docopy && !fromPath.endsWith('.css')) {
|
39
|
-
//console.log(toPath,'....');
|
40
38
|
_fs.default.writeFileSync(toPath, css);
|
41
39
|
|
42
40
|
return;
|
package/lib/configs/resolvers.js
CHANGED
@@ -8,6 +8,10 @@ exports.moduleResolver = moduleResolver;
|
|
8
8
|
|
9
9
|
var _constants = require("../constants");
|
10
10
|
|
11
|
+
var _logger = require("../logger");
|
12
|
+
|
13
|
+
var _requireLocalOrGlobal = require("../servers/requireLocalOrGlobal");
|
14
|
+
|
11
15
|
var _libAlias = require("./libAlias");
|
12
16
|
|
13
17
|
var _client_packages_group = require("@zohodesk/client_packages_group");
|
@@ -17,10 +21,17 @@ function moduleResolver(options) {
|
|
17
21
|
moduleResolvePath,
|
18
22
|
disableES5Transpile
|
19
23
|
} = options.app;
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
let required = moduleResolvePath && (0, _requireLocalOrGlobal.requireLocal)(moduleResolvePath);
|
25
|
+
|
26
|
+
if (!required) {
|
27
|
+
required = (0, _requireLocalOrGlobal.requireGlobal)('@zohodesk/client_packages_group');
|
28
|
+
|
29
|
+
if (required) {
|
30
|
+
(0, _logger.messageLogger)('global `@zohodesk/client_packages_group` package taken as client_packages_group');
|
31
|
+
}
|
32
|
+
}
|
23
33
|
|
34
|
+
const nodeModulesPath = required ? required.nodeModulesPath : _client_packages_group.nodeModulesPath;
|
24
35
|
return {
|
25
36
|
modules: [nodeModulesPath, _constants.cliNodemodulesPath, 'node_modules'].filter(Boolean),
|
26
37
|
alias: disableES5Transpile ? _libAlias.libAlias : {} // alias: { ...libAlias, ...clientDependenies }
|
@@ -41,11 +41,7 @@ const getCSSLoaders = optionsObj => {
|
|
41
41
|
selectorReplace,
|
42
42
|
cssHashSelectors,
|
43
43
|
classNamePrefix
|
44
|
-
} = optionsObj;
|
45
|
-
// console.log(plugins)
|
46
|
-
// console.log('exclude:')
|
47
|
-
// console.log(exclude)
|
48
|
-
|
44
|
+
} = optionsObj;
|
49
45
|
const {
|
50
46
|
devCssFileBountry
|
51
47
|
} = options.app;
|
@@ -70,8 +66,7 @@ const getCSSLoaders = optionsObj => {
|
|
70
66
|
cssLoaderOptions.modules.localIdentName = classNameBlob;
|
71
67
|
} else {
|
72
68
|
cssLoaderOptions.modules.getLocalIdent = (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix);
|
73
|
-
}
|
74
|
-
|
69
|
+
}
|
75
70
|
|
76
71
|
const postcssPlugins = [valueReplacer && require('../postcss-plugins/ValueReplacer')(valueReplacer), selectorReplace && require('../postcss-plugins/SelectorReplace')(selectorReplace), ...excludeEmptyCheckPlugin({
|
77
72
|
enable: plugins.hasRTL,
|
@@ -6,25 +6,25 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
6
6
|
|
7
7
|
var _utils = require("../utils");
|
8
8
|
|
9
|
+
var _logger = require("../logger");
|
10
|
+
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
12
|
|
11
|
-
|
13
|
+
const options = (0, _utils.getOptions)();
|
12
14
|
const {
|
13
15
|
cssSelectorZipPath
|
14
16
|
} = options.impactService;
|
15
17
|
|
16
|
-
const zipname = _path.default.parse(cssSelectorZipPath).name; //
|
17
|
-
// TODO:NOTE: need to check about .. path related files creation
|
18
|
+
const zipname = _path.default.parse(cssSelectorZipPath).name; // TODO:NOTE: need to check about .. path related files creation
|
18
19
|
// for now no css files have given form react-cli need to make sure about it.
|
19
20
|
|
20
21
|
|
21
|
-
|
22
|
+
const zippath = _path.default.join(process.cwd(), cssSelectorZipPath);
|
22
23
|
|
23
24
|
if (_fs.default.existsSync(_path.default.join(process.cwd(), cssSelectorZipPath))) {
|
24
25
|
_fs.default.rmSync(zippath);
|
25
26
|
|
26
|
-
|
27
|
-
// console.log('created folder ==> ', dpath);
|
27
|
+
(0, _logger.messageLogger)('zip file deleted', zippath); // fs.rmSync(zippath, {force:true})
|
28
28
|
} // const minicssComment =
|
29
29
|
// '// extracted by mini-css-extract-plugin\n';
|
30
30
|
|
@@ -39,15 +39,15 @@ module.exports = function (source) {
|
|
39
39
|
|
40
40
|
const relativePath = _path.default.relative(rootContext, resourcePath);
|
41
41
|
|
42
|
-
|
42
|
+
const fpath = _path.default.join(rootContext, zipname, relativePath);
|
43
43
|
|
44
|
-
|
44
|
+
const originalpath = _path.default.join(rootContext, relativePath);
|
45
45
|
|
46
46
|
if (relativePath.startsWith('..')) {
|
47
47
|
throw `unexpected path ${relativePath}`;
|
48
48
|
}
|
49
49
|
|
50
|
-
|
50
|
+
const dpath = fpath.slice(0, fpath.lastIndexOf(_path.default.sep));
|
51
51
|
|
52
52
|
if (!_fs.default.existsSync(originalpath)) {
|
53
53
|
throw `originalpath not exixt ${originalpath}`;
|
package/lib/logger.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.errorLogger = errorLogger;
|
7
|
+
exports.messageLogger = messageLogger;
|
8
|
+
exports.warnLogger = warnLogger;
|
9
|
+
|
10
|
+
function messageLogger(...args) {
|
11
|
+
console.log(...args);
|
12
|
+
}
|
13
|
+
|
14
|
+
function errorLogger(...args) {
|
15
|
+
console.error(...args);
|
16
|
+
}
|
17
|
+
|
18
|
+
function warnLogger(...args) {
|
19
|
+
console.warn(...args);
|
20
|
+
}
|
@@ -25,6 +25,8 @@ var _webpack = _interopRequireDefault(require("webpack"));
|
|
25
25
|
|
26
26
|
var _plugins = require("../plugins");
|
27
27
|
|
28
|
+
var _CustomAttributePlugin = require("../plugins/CustomAttributePlugin");
|
29
|
+
|
28
30
|
var _RtlCssPlugin = require("../plugins/RtlSplitPlugin/RtlCssPlugin");
|
29
31
|
|
30
32
|
var _VariableConversionCollector = _interopRequireDefault(require("../plugins/VariableConversionCollector"));
|
@@ -42,6 +44,7 @@ const getDevPlugins = (options, publicPath) => {
|
|
42
44
|
tpFolder,
|
43
45
|
folder,
|
44
46
|
instrumentScript,
|
47
|
+
customAttributes,
|
45
48
|
devCssFileBountry,
|
46
49
|
context,
|
47
50
|
hasEFC: prevOptionForEnableEFC,
|
@@ -86,6 +89,7 @@ const getDevPlugins = (options, publicPath) => {
|
|
86
89
|
NODE_ENV: JSON.stringify(mode === 'dev-no-warn' ? 'production' : 'development')
|
87
90
|
}
|
88
91
|
}), new _miniCssExtractPlugin.default({
|
92
|
+
attributes: customAttributes.cssAttributes,
|
89
93
|
filename: cssLTRFileNameTempalte,
|
90
94
|
// ignoreOrder: true,
|
91
95
|
chunkFilename: cssLTRFileNameTempalte
|
@@ -184,6 +188,7 @@ const getDevPlugins = (options, publicPath) => {
|
|
184
188
|
mainChunkName: 'main'
|
185
189
|
}));
|
186
190
|
instrumentScript && pluginsArr.push(new _plugins.ScriptInstrumentPlugin());
|
191
|
+
customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
|
187
192
|
hasShadowDOM && pluginsArr.push(new _plugins.ShadowDOMSupportPlugin());
|
188
193
|
|
189
194
|
if (devCssFileBountry) {
|
@@ -29,6 +29,8 @@ var _SelectorPlugin = _interopRequireDefault(require("../plugins/SelectorPlugin"
|
|
29
29
|
|
30
30
|
var _plugins = require("../plugins");
|
31
31
|
|
32
|
+
var _CustomAttributePlugin = require("../plugins/CustomAttributePlugin");
|
33
|
+
|
32
34
|
var _RtlCssPlugin = require("../plugins/RtlSplitPlugin/RtlCssPlugin");
|
33
35
|
|
34
36
|
var _configHtmlWebpackPlugins = require("./configHtmlWebpackPlugins");
|
@@ -63,6 +65,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
63
65
|
resourceHints,
|
64
66
|
serviceWorker,
|
65
67
|
htmlTemplate,
|
68
|
+
customAttributes,
|
66
69
|
tpHashMapping,
|
67
70
|
cdnMapping,
|
68
71
|
crossorigin
|
@@ -279,6 +282,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
279
282
|
} // plugins.push(new VariableConversionCollector({}));
|
280
283
|
|
281
284
|
|
285
|
+
customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
|
282
286
|
return pluginsArr;
|
283
287
|
};
|
284
288
|
|
@@ -0,0 +1,82 @@
|
|
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
|
+
var _htmlWebpackInjectAttributesPlugin = _interopRequireDefault(require("html-webpack-inject-attributes-plugin"));
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
/* eslint-disable no-use-before-define */
|
15
|
+
class CustomAttributePlugin {
|
16
|
+
constructor(options) {
|
17
|
+
this.options = {
|
18
|
+
attributes: options.attributes,
|
19
|
+
useHTMLAttribute: options.attributes && !options.jsAttributes && !options.cssAttributes && !options.i18nAttributes,
|
20
|
+
jsAttributes: options.jsAttributes || options.attributes || {},
|
21
|
+
cssAttributes: options.cssAttributes || options.attributes || {},
|
22
|
+
i18nAttributes: options.i18nAttributes || options.attributes || {}
|
23
|
+
};
|
24
|
+
}
|
25
|
+
|
26
|
+
addCustomAttributeToDynamicScriptTags(mainTemplate) {
|
27
|
+
const {
|
28
|
+
jsAttributes,
|
29
|
+
cssAttributes,
|
30
|
+
i18nAttributes
|
31
|
+
} = this.options; // NOTE: To add custom Attributes to js Script tags
|
32
|
+
|
33
|
+
mainTemplate.hooks.jsonpScript.tap('CustomAttributePlugin', source => {
|
34
|
+
const str = attributeSetTemplate(jsAttributes, 'script');
|
35
|
+
return _Template.default.asString([source, ...str]);
|
36
|
+
}); // NOTE: To add custom Attributes to css link tags
|
37
|
+
|
38
|
+
mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
|
39
|
+
const str = attributeSetTemplate(cssAttributes, 'linkTag');
|
40
|
+
const replacedStr = source.replace('head.appendChild(linkTag);', `${str.join('')}head.appendChild(linkTag);`); // console.log({ s: source, r: replacedStr });
|
41
|
+
|
42
|
+
return replacedStr;
|
43
|
+
}); // NOTE: To add custom Attributes to i18n split js Script tags
|
44
|
+
|
45
|
+
mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
|
46
|
+
const str = attributeSetTemplate(i18nAttributes, 'scriptTag');
|
47
|
+
const replacedStr = source.replace('document.body.appendChild(scriptTag);', `${str.join('')}document.body.appendChild(scriptTag);`); // console.log({ s: source, r: replacedStr });
|
48
|
+
|
49
|
+
return replacedStr;
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
apply(compiler) {
|
54
|
+
// NOTE: we not using this, Reason currently this option is only need for EFC,
|
55
|
+
// So it do not needed.
|
56
|
+
const {
|
57
|
+
attributes,
|
58
|
+
useHTMLAttribute
|
59
|
+
} = this.options;
|
60
|
+
useHTMLAttribute && new _htmlWebpackInjectAttributesPlugin.default(attributes).apply(compiler);
|
61
|
+
compiler.hooks.thisCompilation.tap({
|
62
|
+
name: 'CustomAttributePlugin',
|
63
|
+
stage: 1,
|
64
|
+
fn: compilation => {
|
65
|
+
this.addCustomAttributeToDynamicScriptTags(compilation.mainTemplate);
|
66
|
+
}
|
67
|
+
});
|
68
|
+
}
|
69
|
+
|
70
|
+
}
|
71
|
+
|
72
|
+
exports.CustomAttributePlugin = CustomAttributePlugin;
|
73
|
+
|
74
|
+
function attributeSetTemplate(jsAttributes, variableName) {
|
75
|
+
let str = [];
|
76
|
+
Object.keys(jsAttributes).forEach(key => {
|
77
|
+
const val = jsAttributes[key];
|
78
|
+
str.push(`${variableName}.setAttribute(${JSON.stringify(key)}, ${JSON.stringify(val)});`);
|
79
|
+
}); // console.log({ str });
|
80
|
+
|
81
|
+
return str;
|
82
|
+
}
|
@@ -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
|
package/lib/plugins/EFCPlugin.js
CHANGED
@@ -19,6 +19,8 @@ var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
|
|
19
19
|
|
20
20
|
var _EFCTemplatePlugin = _interopRequireDefault(require("./EFCTemplatePlugin"));
|
21
21
|
|
22
|
+
var _logger = require("../logger");
|
23
|
+
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
25
|
|
24
26
|
// import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
|
@@ -85,18 +87,18 @@ class EFCPlugin {
|
|
85
87
|
getI18nAssetsStr(entryPoint, compilation) {
|
86
88
|
if (!chunkSplitEnable) {
|
87
89
|
let i18nAsstes = {};
|
88
|
-
|
90
|
+
const i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
89
91
|
|
90
92
|
i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
|
91
|
-
|
92
|
-
|
93
|
+
const fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
|
94
|
+
const splittedFileName = fileName.split('.');
|
93
95
|
res[splittedFileName[0]] = i18nFilePath;
|
94
96
|
return res;
|
95
97
|
}, {});
|
96
98
|
return `[${JSON.stringify(i18nAsstes)}[lang]]`;
|
97
99
|
}
|
98
100
|
|
99
|
-
|
101
|
+
const initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
|
100
102
|
return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
|
101
103
|
}
|
102
104
|
|
@@ -205,8 +207,7 @@ class EFCPlugin {
|
|
205
207
|
apply(compiler) {
|
206
208
|
if (!createSDkFile) {
|
207
209
|
return;
|
208
|
-
}
|
209
|
-
|
210
|
+
}
|
210
211
|
|
211
212
|
if (this.templateFilePath) {
|
212
213
|
new _EFCTemplatePlugin.default({
|
@@ -230,9 +231,8 @@ class EFCPlugin {
|
|
230
231
|
}
|
231
232
|
|
232
233
|
const source = new _webpackSources.RawSource(this.createFileContent(compilation));
|
233
|
-
compilation.assets[outputFile] = source;
|
234
|
-
|
235
|
-
console.log('The EFC embedded code was created successfully..!!!');
|
234
|
+
compilation.assets[outputFile] = source;
|
235
|
+
(0, _logger.messageLogger)('The EFC embedded code was created successfully..!!!');
|
236
236
|
});
|
237
237
|
}
|
238
238
|
|
@@ -19,6 +19,8 @@ var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nK
|
|
19
19
|
|
20
20
|
var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
|
21
21
|
|
22
|
+
var _logger = require("../logger");
|
23
|
+
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
25
|
|
24
26
|
// import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
|
@@ -40,9 +42,7 @@ const {
|
|
40
42
|
|
41
43
|
class EFCTemplatePlugin {
|
42
44
|
constructor(options = {}) {
|
43
|
-
|
44
|
-
this.templateFilePath = _path.default.join(process.cwd(), options.templateFilePath); // console.log(' templateFilePath ', this.templateFilePath);
|
45
|
-
|
45
|
+
this.templateFilePath = _path.default.join(process.cwd(), options.templateFilePath);
|
46
46
|
this.i18nFileNameTemplate = options.i18nFileNameTemplate;
|
47
47
|
this.publicPath = options.publicPath; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
|
48
48
|
// this.i18nManifestFileName = options.i18nManifestFileName;
|
@@ -68,18 +68,18 @@ class EFCTemplatePlugin {
|
|
68
68
|
// NOTE: we have used lang variable inside
|
69
69
|
if (!chunkSplitEnable) {
|
70
70
|
let i18nAsstes = {};
|
71
|
-
|
71
|
+
const i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
72
72
|
|
73
73
|
i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
|
74
|
-
|
75
|
-
|
74
|
+
const fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
|
75
|
+
const splittedFileName = fileName.split('.');
|
76
76
|
res[splittedFileName[0]] = i18nFilePath;
|
77
77
|
return res;
|
78
78
|
}, {});
|
79
79
|
return `[${JSON.stringify(i18nAsstes)}[lang]]`;
|
80
80
|
}
|
81
81
|
|
82
|
-
|
82
|
+
const initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
|
83
83
|
return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
|
84
84
|
}
|
85
85
|
|
@@ -102,7 +102,7 @@ class EFCTemplatePlugin {
|
|
102
102
|
|
103
103
|
const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, '' // i18nJsPath
|
104
104
|
);
|
105
|
-
|
105
|
+
const templateStr = (0, _fs.readFileSync)(this.templateFilePath).toString();
|
106
106
|
return templateStr.replace('((\'getInitalAssets\'))', `function getInitalAssets(assetsType, lang) {
|
107
107
|
if (assetsType === "js") {
|
108
108
|
return ${JSON.stringify(initialJsFiles)}
|
@@ -139,10 +139,8 @@ class EFCTemplatePlugin {
|
|
139
139
|
}
|
140
140
|
|
141
141
|
const source = new _webpackSources.RawSource(this.templateReplacer(entryPoint, compilation));
|
142
|
-
compilation.assets[outputFile] = source;
|
143
|
-
|
144
|
-
|
145
|
-
console.log('The EFC embedded code was created successfully..!!!');
|
142
|
+
compilation.assets[outputFile] = source;
|
143
|
+
(0, _logger.messageLogger)('The EFC embedded code was created successfully..!!!');
|
146
144
|
});
|
147
145
|
}
|
148
146
|
|
@@ -22,7 +22,7 @@ var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUr
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
23
|
|
24
24
|
let i18nObj = null;
|
25
|
-
|
25
|
+
const options = (0, _utils.getOptions)();
|
26
26
|
|
27
27
|
function newAssign(target, data) {
|
28
28
|
return Object.assign({}, target, data);
|
@@ -43,7 +43,7 @@ class I18NInjectIntoIndexPlugin {
|
|
43
43
|
}
|
44
44
|
|
45
45
|
getI18nFileUrlPath(chunk, compilation) {
|
46
|
-
|
46
|
+
const urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
|
47
47
|
return (0, _urlConcat.urlConcat)(this.publicPath, urlpath);
|
48
48
|
}
|
49
49
|
|
@@ -81,7 +81,6 @@ class I18NInjectIntoIndexPlugin {
|
|
81
81
|
withI18nSpitHandling(compiler) {
|
82
82
|
compiler.hooks.make.tap('I18NInjectIntoIndexPlugin', compilation => {
|
83
83
|
// let cdns = Object.keys(this.publicPaths);
|
84
|
-
// console.log('compilation.assets', Object.keys(compilation.assets).filter(a => a.includes('i18n')));
|
85
84
|
if (!(0, _hashUtils.hasContentHash)(this.i18nFileNameTemplate)) {
|
86
85
|
this.injectI18nURLsToHTML(compilation);
|
87
86
|
return;
|
@@ -91,7 +90,7 @@ class I18NInjectIntoIndexPlugin {
|
|
91
90
|
// Manipulate the content
|
92
91
|
const i18nManifest = this.getI18nManifest(compilation);
|
93
92
|
const entryPoint = compilation.entrypoints.get(this.entryPointName);
|
94
|
-
|
93
|
+
const i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
|
95
94
|
data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets))); // Tell webpack to move on
|
96
95
|
|
97
96
|
cb(null, data);
|
@@ -111,11 +110,11 @@ class I18NInjectIntoIndexPlugin {
|
|
111
110
|
compiler.hooks.emit.tap('I18NInjectIntoIndexPlugin', compilation => {
|
112
111
|
// let cdns = Object.keys(this.publicPaths);
|
113
112
|
if (i18nObj === null) {
|
114
|
-
|
113
|
+
const i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
|
115
114
|
|
116
115
|
i18nObj = i18nFiles.reduce((res, next) => {
|
117
|
-
|
118
|
-
|
116
|
+
const fileName = next.replace(`i18n${_path.default.sep}`, '');
|
117
|
+
const splittedFileName = fileName.split('.');
|
119
118
|
/* if (this.isDevelopment) {
|
120
119
|
res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
|
121
120
|
} else {
|
@@ -127,10 +126,10 @@ class I18NInjectIntoIndexPlugin {
|
|
127
126
|
}, {});
|
128
127
|
}
|
129
128
|
|
130
|
-
|
129
|
+
const [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
|
131
130
|
|
132
131
|
if (indexFile) {
|
133
|
-
|
132
|
+
const source = compilation.assets[indexFile].source();
|
134
133
|
compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nObj))));
|
135
134
|
}
|
136
135
|
});
|
@@ -24,10 +24,9 @@ class I18nDebugPlugin {
|
|
24
24
|
compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
|
25
25
|
if (!this.compilationParams || this.compilationParams.normalModuleFactory === factory) {
|
26
26
|
return;
|
27
|
-
}
|
27
|
+
}
|
28
28
|
|
29
|
-
|
30
|
-
let handler = parser => {
|
29
|
+
const handler = parser => {
|
31
30
|
parser.hooks.program.tap(pluginName, (ast, commmets) => {
|
32
31
|
const {
|
33
32
|
module
|
@@ -40,7 +40,7 @@ class I18nKeysIdentifer {
|
|
40
40
|
identifier,
|
41
41
|
i18nKeys
|
42
42
|
}, module.context, 0);
|
43
|
-
module.addDependency(dep);
|
43
|
+
module.addDependency(dep);
|
44
44
|
}
|
45
45
|
|
46
46
|
apply(compiler) {
|
@@ -50,7 +50,7 @@ class I18nKeysIdentifer {
|
|
50
50
|
// and we must define how it import statement look like I18nDependencyTemplate
|
51
51
|
this.defineConfigarationForI18nDependency(compilation); // handler for parser
|
52
52
|
|
53
|
-
|
53
|
+
const handler = parser => {
|
54
54
|
parser.hooks.program.tap(pluginName, (ast, commmets) => {
|
55
55
|
const {
|
56
56
|
module
|
@@ -66,11 +66,6 @@ class I18nKeysIdentifer {
|
|
66
66
|
(0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
|
67
67
|
|
68
68
|
if (i18nKeys.length) {
|
69
|
-
// console.log(
|
70
|
-
// 'i18nKeys.length',
|
71
|
-
// module.resource,
|
72
|
-
// i18nKeys.length < 5 ? i18nKeys : i18nKeys.length
|
73
|
-
// );
|
74
69
|
this.addI18nDependency(module, i18nKeys);
|
75
70
|
}
|
76
71
|
});
|