@zohodesk/client_build_tool 0.0.11-exp.6 → 0.0.11-exp.8
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 -148
- package/README_backup.md +0 -148
- package/lib/schemas/defaultConfigValues.js +1 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +18 -5
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +11 -2
- package/npm-shrinkwrap.json +7884 -7
- package/package.json +1 -1
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin_simplified.js +0 -129
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/i18nDataLoader.js +0 -134
- package/lib/shared/bundler/webpack/utils/i18n/collectAstKeys.js +0 -96
package/package.json
CHANGED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
sources,
|
|
7
|
-
Compilation
|
|
8
|
-
} = require('webpack');
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
decodeUnicodeEscapes
|
|
12
|
-
} = require('../../utils/propertiesParser');
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
loadNumericMap,
|
|
16
|
-
loadI18nData
|
|
17
|
-
} = require('./utils/i18nDataLoader');
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
RawSource
|
|
21
|
-
} = sources;
|
|
22
|
-
const pluginName = 'I18nNumericIndexPlugin';
|
|
23
|
-
|
|
24
|
-
class I18nNumericIndexPlugin {
|
|
25
|
-
constructor(options = {}) {
|
|
26
|
-
this.options = options;
|
|
27
|
-
this.numericMap = null;
|
|
28
|
-
this.i18nData = null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getNumericMap(compilation) {
|
|
32
|
-
if (!this.numericMap) {
|
|
33
|
-
const mapPath = path.resolve(compilation.compiler.context, this.options.numericMapPath);
|
|
34
|
-
this.numericMap = loadNumericMap(mapPath, compilation);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return this.numericMap;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getI18nData(compilation) {
|
|
41
|
-
if (!this.i18nData) {
|
|
42
|
-
this.i18nData = loadI18nData(this.options, compilation);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return this.i18nData;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
emitChunk(compilation, filename, locale, data) {
|
|
49
|
-
const content = decodeUnicodeEscapes(JSON.stringify(data));
|
|
50
|
-
const fileContent = `${this.options.jsonpFunc}(${content});`;
|
|
51
|
-
const outputPath = filename.replace(/\[locale\]/g, locale);
|
|
52
|
-
compilation.emitAsset(outputPath, new RawSource(fileContent));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
apply(compiler) {
|
|
56
|
-
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
57
|
-
compilation.hooks.processAssets.tapAsync({
|
|
58
|
-
name: pluginName,
|
|
59
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
60
|
-
}, (assets, callback) => {
|
|
61
|
-
if (!this.options.enable) return callback();
|
|
62
|
-
const {
|
|
63
|
-
sortedKeys,
|
|
64
|
-
totalKeys
|
|
65
|
-
} = this.getNumericMap(compilation);
|
|
66
|
-
const {
|
|
67
|
-
jsResourceBase,
|
|
68
|
-
allI18n,
|
|
69
|
-
locales
|
|
70
|
-
} = this.getI18nData(compilation);
|
|
71
|
-
if (!locales.length) return callback(); // Collect dynamic keys used in comments
|
|
72
|
-
|
|
73
|
-
const dynamicKeys = new Set();
|
|
74
|
-
|
|
75
|
-
for (const module of compilation.modules) {
|
|
76
|
-
if (module.buildInfo?.loaderIdentifiedCommentI18nKeys) {
|
|
77
|
-
module.buildInfo.loaderIdentifiedCommentI18nKeys.forEach(key => dynamicKeys.add(key));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const numericKeysSet = new Set(sortedKeys);
|
|
82
|
-
const englishData = allI18n.en || jsResourceBase; // Process each locale
|
|
83
|
-
|
|
84
|
-
locales.forEach(locale => {
|
|
85
|
-
const localeData = allI18n[locale] || {}; // Build numeric data
|
|
86
|
-
|
|
87
|
-
const numericData = {};
|
|
88
|
-
|
|
89
|
-
for (let i = 0; i < totalKeys; i++) {
|
|
90
|
-
const key = sortedKeys[i];
|
|
91
|
-
|
|
92
|
-
if (key && jsResourceBase[key] !== undefined) {
|
|
93
|
-
numericData[i] = localeData[key] ?? englishData[key];
|
|
94
|
-
}
|
|
95
|
-
} // Build dynamic data
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const dynamicData = {}; // Add comment keys
|
|
99
|
-
|
|
100
|
-
dynamicKeys.forEach(key => {
|
|
101
|
-
if (!numericKeysSet.has(key) && jsResourceBase[key] !== undefined) {
|
|
102
|
-
dynamicData[key] = localeData[key] ?? englishData[key];
|
|
103
|
-
}
|
|
104
|
-
}); // Add remaining keys
|
|
105
|
-
|
|
106
|
-
Object.keys(jsResourceBase).forEach(key => {
|
|
107
|
-
if (!numericKeysSet.has(key) && !dynamicData[key]) {
|
|
108
|
-
dynamicData[key] = localeData[key] ?? englishData[key];
|
|
109
|
-
}
|
|
110
|
-
}); // Emit chunks
|
|
111
|
-
|
|
112
|
-
if (Object.keys(numericData).length > 0) {
|
|
113
|
-
this.emitChunk(compilation, this.options.numericFilenameTemplate, locale, numericData);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (Object.keys(dynamicData).length > 0) {
|
|
117
|
-
this.emitChunk(compilation, this.options.dynamicFilenameTemplate, locale, dynamicData);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
callback();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
module.exports = {
|
|
128
|
-
I18nNumericIndexPlugin
|
|
129
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
parseProperties
|
|
9
|
-
} = require('../../utils/propertiesParser');
|
|
10
|
-
/**
|
|
11
|
-
* Loads and parses a properties file
|
|
12
|
-
* @param {string} filePath - Path to the properties file
|
|
13
|
-
* @param {Object} compilation - Webpack compilation object for error reporting
|
|
14
|
-
* @param {string} description - Description for error messages
|
|
15
|
-
* @returns {Object} Parsed properties object
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function loadPropertiesFile(filePath, compilation, description) {
|
|
20
|
-
try {
|
|
21
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
22
|
-
return parseProperties(content);
|
|
23
|
-
} catch (err) {
|
|
24
|
-
if (compilation) {
|
|
25
|
-
compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading ${description}: ${err.message}`));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Loads numeric mapping from JSON file
|
|
33
|
-
* @param {string} numericMapPath - Path to numeric map JSON file
|
|
34
|
-
* @param {Object} compilation - Webpack compilation object
|
|
35
|
-
* @returns {Object} Object with sortedKeys array and totalKeys count
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function loadNumericMap(numericMapPath, compilation) {
|
|
40
|
-
try {
|
|
41
|
-
const fileContent = fs.readFileSync(numericMapPath, 'utf-8');
|
|
42
|
-
const parsedData = JSON.parse(fileContent);
|
|
43
|
-
const sortedKeys = new Array(parsedData.totalKeysInMap);
|
|
44
|
-
Object.entries(parsedData.originalKeyToNumericId).forEach(([key, id]) => {
|
|
45
|
-
sortedKeys[id] = key;
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
sortedKeys,
|
|
49
|
-
totalKeys: parsedData.totalKeysInMap
|
|
50
|
-
};
|
|
51
|
-
} catch (err) {
|
|
52
|
-
if (compilation) {
|
|
53
|
-
compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading numeric map: ${err.message}`));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
sortedKeys: [],
|
|
58
|
-
totalKeys: 0
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Loads all locale-specific properties files
|
|
64
|
-
* @param {string} propertiesPath - Path to properties folder
|
|
65
|
-
* @param {string} baseFileName - Base filename (e.g., 'JSResources')
|
|
66
|
-
* @param {Object} compilation - Webpack compilation object
|
|
67
|
-
* @returns {Object} Object with allI18n translations and locales array
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
function loadAllLocaleFiles(propertiesPath, baseFileName, compilation) {
|
|
72
|
-
const allI18n = {};
|
|
73
|
-
const locales = [];
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const files = fs.readdirSync(propertiesPath);
|
|
77
|
-
files.forEach(file => {
|
|
78
|
-
if (!file.endsWith('.properties')) return;
|
|
79
|
-
const name = path.basename(file, '.properties');
|
|
80
|
-
let locale = null;
|
|
81
|
-
|
|
82
|
-
if (name === baseFileName) {
|
|
83
|
-
locale = 'en';
|
|
84
|
-
} else if (name.startsWith(baseFileName + '_')) {
|
|
85
|
-
locale = name.substring(baseFileName.length + 1);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (locale) {
|
|
89
|
-
const filePath = path.join(propertiesPath, file);
|
|
90
|
-
allI18n[locale] = loadPropertiesFile(filePath, compilation, `locale ${locale}`);
|
|
91
|
-
locales.push(locale);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
} catch (err) {
|
|
95
|
-
if (compilation) {
|
|
96
|
-
compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error reading properties folder: ${err.message}`));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
allI18n,
|
|
102
|
-
locales
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Loads all i18n data including base resources and locale-specific translations
|
|
107
|
-
* @param {Object} options - Plugin options
|
|
108
|
-
* @param {Object} compilation - Webpack compilation object
|
|
109
|
-
* @returns {Object} Object with jsResourceBase, allI18n, and locales
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
function loadI18nData(options, compilation) {
|
|
114
|
-
const jsResourcePath = path.resolve(compilation.compiler.context, options.jsResourcePath);
|
|
115
|
-
const propertiesPath = path.resolve(compilation.compiler.context, options.propertiesFolderPath);
|
|
116
|
-
const baseFileName = path.basename(options.jsResourcePath, '.properties');
|
|
117
|
-
const jsResourceBase = loadPropertiesFile(jsResourcePath, compilation, 'JS resources');
|
|
118
|
-
const {
|
|
119
|
-
allI18n,
|
|
120
|
-
locales
|
|
121
|
-
} = loadAllLocaleFiles(propertiesPath, baseFileName, compilation);
|
|
122
|
-
return {
|
|
123
|
-
jsResourceBase,
|
|
124
|
-
allI18n,
|
|
125
|
-
locales
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
module.exports = {
|
|
130
|
-
loadPropertiesFile,
|
|
131
|
-
loadNumericMap,
|
|
132
|
-
loadAllLocaleFiles,
|
|
133
|
-
loadI18nData
|
|
134
|
-
};
|
|
@@ -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
|
-
};
|