@zohodesk/client_build_tool 0.0.11-exp.15.1 → 0.0.11-exp.15.4
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/README.md +0 -204
- package/docs/I18N_NUMERIC_INDEXING_PLUGIN.md +225 -0
- package/lib/schemas/defaultConfigValues.js +9 -12
- package/lib/schemas/defaultConfigValuesOnly.js +1 -18
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +124 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +210 -143
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +47 -12
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +19 -1
- package/lib/shared/bundler/webpack/jsLoaders.js +9 -4
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +12 -3
- package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +28 -14
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +42 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +92 -0
- package/lib/shared/bundler/webpack/plugins.js +6 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/README_backup.md +0 -202
- package/init/README.md +0 -170
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +0 -49
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectAstKeys.js +0 -96
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +0 -84
- package/lib/shared/bundler/webpack/utils/propertiesParser.js +0 -81
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
4
|
-
|
|
5
|
-
const pluginName = 'I18nNumericIndexHtmlInjectorPlugin';
|
|
6
|
-
|
|
7
|
-
class I18nNumericIndexHtmlInjectorPlugin {
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.options = options;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
apply(compiler) {
|
|
13
|
-
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
14
|
-
HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync(pluginName, (hookData, cb) => {
|
|
15
|
-
const {
|
|
16
|
-
assets
|
|
17
|
-
} = hookData;
|
|
18
|
-
const {
|
|
19
|
-
numericFilenameTemplate,
|
|
20
|
-
dynamicFilenameTemplate,
|
|
21
|
-
htmlTemplateLabel,
|
|
22
|
-
i18nAssetsPublicPathPrefix = ''
|
|
23
|
-
} = this.options;
|
|
24
|
-
const newI18nAssetUrlsToAdd = [];
|
|
25
|
-
|
|
26
|
-
if (numericFilenameTemplate) {
|
|
27
|
-
const numericFilename = numericFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel);
|
|
28
|
-
newI18nAssetUrlsToAdd.push(numericFilename);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (dynamicFilenameTemplate) {
|
|
32
|
-
const dynamicFilename = dynamicFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel);
|
|
33
|
-
newI18nAssetUrlsToAdd.push(dynamicFilename);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (newI18nAssetUrlsToAdd.length > 0) {
|
|
37
|
-
assets.js = [...assets.js, ...newI18nAssetUrlsToAdd];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
cb(null, hookData);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = {
|
|
48
|
-
I18nNumericIndexHtmlInjectorPlugin
|
|
49
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
walk
|
|
5
|
-
} = require('estree-walker');
|
|
6
|
-
|
|
7
|
-
const PREFIX_I18N_COMMENT = 'I18N';
|
|
8
|
-
const PREFIX_I18N_COMMENT_DYNAMIC = 'dynamic-i18n-key';
|
|
9
|
-
|
|
10
|
-
function getI18nKeysFromSingleComment(commentNode, validKeysSet) {
|
|
11
|
-
const foundKeysInComment = [];
|
|
12
|
-
|
|
13
|
-
if (!commentNode || typeof commentNode.value !== 'string') {
|
|
14
|
-
return foundKeysInComment;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const commentString = commentNode.value.trim();
|
|
18
|
-
let i18nKeyStr;
|
|
19
|
-
|
|
20
|
-
if (commentString.startsWith(PREFIX_I18N_COMMENT)) {
|
|
21
|
-
i18nKeyStr = commentString.slice(PREFIX_I18N_COMMENT.length).trim();
|
|
22
|
-
} else if (commentString.startsWith(PREFIX_I18N_COMMENT_DYNAMIC)) {
|
|
23
|
-
i18nKeyStr = commentString.slice(PREFIX_I18N_COMMENT_DYNAMIC.length).trim();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!i18nKeyStr) {
|
|
27
|
-
return foundKeysInComment;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const potentialKeys = i18nKeyStr.split(',').map(key => key.trim()).filter(key => key);
|
|
31
|
-
potentialKeys.forEach(key => {
|
|
32
|
-
if (validKeysSet.has(key)) {
|
|
33
|
-
foundKeysInComment.push(key);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return foundKeysInComment;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Traverses an AST and its comments to collect and categorize i18n keys.
|
|
40
|
-
*
|
|
41
|
-
* @param {object} astProgramNode - The Program node of the AST.
|
|
42
|
-
* @param {object[]} commentsArray - An array of comment nodes from the AST.
|
|
43
|
-
* @param {object} allI18nKeysMasterMap - Object map of all valid i18n keys (from JSResources).
|
|
44
|
-
* @param {boolean} [isDebug=false] - Flag for verbose logging.
|
|
45
|
-
* @returns {{literalKeys: Set<string>, commentKeys: Set<string>}}
|
|
46
|
-
* literalKeys: Set of valid i18n keys found as string literals.
|
|
47
|
-
* commentKeys: Set of valid i18n keys found in comments.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
function collectAndCategorizeUsedI18nKeys(astProgramNode, commentsArray, allI18nKeysMasterMap, isDebug = false) {
|
|
52
|
-
const foundLiteralKeys = new Set();
|
|
53
|
-
const foundCommentKeys = new Set();
|
|
54
|
-
const validKeysSet = new Set(Object.keys(allI18nKeysMasterMap || {}));
|
|
55
|
-
|
|
56
|
-
if (validKeysSet.size === 0 && isDebug) {
|
|
57
|
-
console.warn('[collectAndCategorizeUsedI18nKeys] allI18nKeysMasterMap is empty. No keys can be collected.');
|
|
58
|
-
} // 1. Collect keys from AST string literals
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (astProgramNode) {
|
|
62
|
-
try {
|
|
63
|
-
walk(astProgramNode, {
|
|
64
|
-
enter(node) {
|
|
65
|
-
if ((node.type === 'Literal' || node.type === 'StringLiteral') && typeof node.value === 'string') {
|
|
66
|
-
if (validKeysSet.has(node.value)) {
|
|
67
|
-
foundLiteralKeys.add(node.value);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error('[collectAndCategorizeUsedI18nKeys] Error during AST walk:', error);
|
|
75
|
-
}
|
|
76
|
-
} // 2. Collect keys from comments
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (commentsArray && Array.isArray(commentsArray)) {
|
|
80
|
-
commentsArray.forEach(commentNode => {
|
|
81
|
-
const keysFromComment = getI18nKeysFromSingleComment(commentNode, validKeysSet);
|
|
82
|
-
keysFromComment.forEach(key => {
|
|
83
|
-
foundCommentKeys.add(key);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
literalKeys: foundLiteralKeys,
|
|
90
|
-
commentKeys: foundCommentKeys
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
module.exports = {
|
|
95
|
-
collectAndCategorizeUsedI18nKeys: collectAndCategorizeUsedI18nKeys
|
|
96
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.configI18nNumericIndexPlugin = configI18nNumericIndexPlugin;
|
|
7
|
-
|
|
8
|
-
var _I18nNumericIndexPlugin = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin");
|
|
9
|
-
|
|
10
|
-
var _I18nNumericIndexHtmlInjectorPlugin = require("../custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin");
|
|
11
|
-
|
|
12
|
-
var _readI18nValues = require("../custom_plugins/I18nSplitPlugin/readI18nValues");
|
|
13
|
-
|
|
14
|
-
function configI18nNumericIndexPlugin(options) {
|
|
15
|
-
if (!(options.i18nIndexing && options.i18nIndexing.enable)) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const i18nOpts = options.i18nIndexing; // Check for required options based on singleFile mode
|
|
20
|
-
|
|
21
|
-
const baseRequiredOptions = ['jsResourcePath', 'propertiesFolderPath', 'numericMapPath', 'jsonpFunc', 'htmlTemplateLabel', 'localeVarName']; // Add template requirements based on mode
|
|
22
|
-
|
|
23
|
-
const requiredOptions = i18nOpts.singleFile ? [...baseRequiredOptions, 'singleFileTemplate'] : [...baseRequiredOptions, 'numericFilenameTemplate', 'dynamicFilenameTemplate'];
|
|
24
|
-
const missingOptions = requiredOptions.filter(opt => !i18nOpts[opt]);
|
|
25
|
-
|
|
26
|
-
if (missingOptions.length > 0) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
locales,
|
|
32
|
-
allI18nObject
|
|
33
|
-
} = (0, _readI18nValues.readI18nValues)({
|
|
34
|
-
jsResource: i18nOpts.jsResourcePath,
|
|
35
|
-
propertiesFolder: i18nOpts.propertiesFolderPath,
|
|
36
|
-
disableDefault: false
|
|
37
|
-
}); // Validate template patterns based on mode
|
|
38
|
-
|
|
39
|
-
if (i18nOpts.singleFile) {
|
|
40
|
-
if (i18nOpts.singleFileTemplate && !i18nOpts.singleFileTemplate.includes('[locale]')) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
if (!i18nOpts.numericFilenameTemplate?.includes('[locale]')) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!i18nOpts.dynamicFilenameTemplate?.includes('[locale]')) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const i18nAssetsPublicPathPrefix = '';
|
|
54
|
-
const hasContentHashInNumeric = i18nOpts.numericFilenameTemplate.includes('[contenthash]');
|
|
55
|
-
const hasContentHashInDynamic = i18nOpts.dynamicFilenameTemplate.includes('[contenthash]');
|
|
56
|
-
const hasContentHashInSingle = i18nOpts.singleFileTemplate?.includes('[contenthash]');
|
|
57
|
-
const shouldIncludeContentHash = i18nOpts.singleFile ? hasContentHashInSingle : hasContentHashInNumeric || hasContentHashInDynamic;
|
|
58
|
-
const finalIncludeContentHash = i18nOpts.includeContentHash !== undefined ? i18nOpts.includeContentHash : shouldIncludeContentHash;
|
|
59
|
-
const numericIndexPluginOptions = {
|
|
60
|
-
enable: i18nOpts.enable,
|
|
61
|
-
jsResourcePath: i18nOpts.jsResourcePath,
|
|
62
|
-
propertiesFolderPath: i18nOpts.propertiesFolderPath,
|
|
63
|
-
numericMapPath: i18nOpts.numericMapPath,
|
|
64
|
-
locales,
|
|
65
|
-
allI18nObject,
|
|
66
|
-
numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
|
|
67
|
-
dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
|
|
68
|
-
singleFileTemplate: i18nOpts.singleFileTemplate,
|
|
69
|
-
jsonpFunc: i18nOpts.jsonpFunc,
|
|
70
|
-
singleFile: i18nOpts.singleFile || false,
|
|
71
|
-
includeContentHash: finalIncludeContentHash,
|
|
72
|
-
generateManifest: i18nOpts.generateManifest || false,
|
|
73
|
-
manifestPath: i18nOpts.manifestPath
|
|
74
|
-
};
|
|
75
|
-
const htmlInjectorOptions = {
|
|
76
|
-
numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
|
|
77
|
-
dynamicFilenameTemplate: i18nOpts.dynamicFilenameTemplate,
|
|
78
|
-
htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
|
|
79
|
-
i18nAssetsPublicPathPrefix
|
|
80
|
-
};
|
|
81
|
-
const i18nNumericPluginInstance = new _I18nNumericIndexPlugin.I18nNumericIndexPlugin(numericIndexPluginOptions);
|
|
82
|
-
const htmlInjectorPluginInstance = new _I18nNumericIndexHtmlInjectorPlugin.I18nNumericIndexHtmlInjectorPlugin(htmlInjectorOptions);
|
|
83
|
-
return [i18nNumericPluginInstance, htmlInjectorPluginInstance];
|
|
84
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function decodeUnicodeEscapes(str) {
|
|
4
|
-
if (typeof str !== 'string') {
|
|
5
|
-
return str;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return str.replace(/\\u([0-9a-fA-F]{4})/g, (match, hex) => {
|
|
9
|
-
return String.fromCharCode(parseInt(hex, 16));
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function parseProperties(content) {
|
|
14
|
-
const lines = content.split(/\r?\n/);
|
|
15
|
-
const data = {};
|
|
16
|
-
lines.forEach(line => {
|
|
17
|
-
const trimmedLine = line.trim();
|
|
18
|
-
|
|
19
|
-
if (trimmedLine.startsWith('#') || trimmedLine.startsWith('!') || trimmedLine === '') {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let separatorIndex = -1;
|
|
24
|
-
|
|
25
|
-
for (let i = 0; i < trimmedLine.length; i++) {
|
|
26
|
-
if ((trimmedLine[i] === '=' || trimmedLine[i] === ':') && (i === 0 || trimmedLine[i - 1] !== '\\')) {
|
|
27
|
-
separatorIndex = i;
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (separatorIndex > 0) {
|
|
33
|
-
let key = trimmedLine.substring(0, separatorIndex).trim();
|
|
34
|
-
let value = trimmedLine.substring(separatorIndex + 1).trim();
|
|
35
|
-
|
|
36
|
-
if (key) {
|
|
37
|
-
key = key.replace(/\\ /g, ' ');
|
|
38
|
-
value = decodeUnicodeEscapes(value);
|
|
39
|
-
data[key] = value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return data;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function parsePropertiesToKeySet(content) {
|
|
47
|
-
const lines = content.split(/\r?\n/);
|
|
48
|
-
const keys = new Set();
|
|
49
|
-
lines.forEach(line => {
|
|
50
|
-
const trimmedLine = line.trim();
|
|
51
|
-
|
|
52
|
-
if (trimmedLine.startsWith('#') || trimmedLine.startsWith('!') || trimmedLine === '') {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let separatorIndex = -1;
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i < trimmedLine.length; i++) {
|
|
59
|
-
if ((trimmedLine[i] === '=' || trimmedLine[i] === ':') && (i === 0 || trimmedLine[i - 1] !== '\\')) {
|
|
60
|
-
separatorIndex = i;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (separatorIndex > 0) {
|
|
66
|
-
let key = trimmedLine.substring(0, separatorIndex).trim();
|
|
67
|
-
|
|
68
|
-
if (key) {
|
|
69
|
-
key = key.replace(/\\ /g, ' ');
|
|
70
|
-
keys.add(key);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return keys;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = {
|
|
78
|
-
parseProperties,
|
|
79
|
-
parsePropertiesToKeySet,
|
|
80
|
-
decodeUnicodeEscapes
|
|
81
|
-
};
|