b28-cli 1.7.1 → 1.7.2

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.
Files changed (74) hide show
  1. package/.babelrc +13 -13
  2. package/README.MD +470 -466
  3. package/TestFile/output/lang/BRPT.json +24 -0
  4. package/TestFile/output/lang/CN.json +24 -0
  5. package/TestFile/output/lang/CS.json +24 -0
  6. package/TestFile/output/lang/DE.json +24 -0
  7. package/TestFile/output/lang/EN.json +24 -0
  8. package/TestFile/output/lang/ES.json +24 -0
  9. package/TestFile/output/lang/FR.json +24 -0
  10. package/TestFile/output/lang/HU.json +24 -0
  11. package/TestFile/output/lang/IT.json +24 -0
  12. package/TestFile/output/lang/KO.json +24 -0
  13. package/TestFile/output/lang/LAES.json +24 -0
  14. package/TestFile/output/lang/NL.json +24 -0
  15. package/TestFile/output/lang/PL.json +24 -0
  16. package/TestFile/output/lang/PT.json +24 -0
  17. package/TestFile/output/lang/RO.json +24 -0
  18. package/TestFile/output/lang/RU.json +24 -0
  19. package/TestFile/output/lang/TR.json +24 -0
  20. package/TestFile/output/lang/UK.json +24 -0
  21. package/TestFile/output/lang/ZH.json +24 -0
  22. package/TestFile/output/lang/brpt/translate.json +23 -0
  23. package/TestFile/output/lang/cn/translate.json +23 -0
  24. package/TestFile/output/lang/cs/translate.json +23 -0
  25. package/TestFile/output/lang/de/translate.json +23 -0
  26. package/TestFile/output/lang/es/translate.json +23 -0
  27. package/TestFile/output/lang/fr/translate.json +23 -0
  28. package/TestFile/output/lang/hu/translate.json +23 -0
  29. package/TestFile/output/lang/it/translate.json +23 -0
  30. package/TestFile/output/lang/ko/translate.json +23 -0
  31. package/TestFile/output/lang/laes/translate.json +23 -0
  32. package/TestFile/output/lang/nl/translate.json +23 -0
  33. package/TestFile/output/lang/pl/translate.json +23 -0
  34. package/TestFile/output/lang/pt/translate.json +23 -0
  35. package/TestFile/output/lang/ro/translate.json +23 -0
  36. package/TestFile/output/lang/ru/translate.json +23 -0
  37. package/TestFile/output/lang/tr/translate.json +23 -0
  38. package/TestFile/output/lang/uk/translate.json +23 -0
  39. package/TestFile/output/lang/zh/translate.json +23 -0
  40. package/TestFile/output/lang.json +25 -0
  41. package/b28n.js +739 -739
  42. package/b28nPigeonhole/11ac_ecos_b28n.js +677 -677
  43. package/b28nPigeonhole/11ac_linux_b28n_async.js +709 -709
  44. package/b28nPigeonhole/4G03_b28n_async.js +708 -708
  45. package/b28nPigeonhole/G5310P_b28n.js +650 -650
  46. package/b28nPigeonhole/es5b28n.js +711 -711
  47. package/b28nPigeonhole/es6b28n.js +857 -857
  48. package/b28nPigeonhole/readMe.md +20 -20
  49. package/b28nPigeonhole//345/276/256/344/274/201/350/267/257/347/224/261b28n.js +916 -916
  50. package/dist/ExtractLangExcel.js +138 -45
  51. package/dist/cmd.js +14 -9
  52. package/dist/excel2json.js +215 -54
  53. package/dist/extract/extract-html.js +2 -2
  54. package/dist/extract/extract-js.js +2 -2
  55. package/dist/extract/extract-regexp.js +2 -2
  56. package/dist/extract/extract-vue.js +9 -9
  57. package/dist/extract/extract.js +4 -4
  58. package/dist/extract/extractRegexp/index.js +6 -6
  59. package/dist/extract/vue/html-parser.js +16 -16
  60. package/dist/extract/vue/util.js +2 -2
  61. package/dist/extract/vue/vue-compiler.js +2 -2
  62. package/dist/extractOrigin/extract.js +2 -2
  63. package/dist/extractOrigin/extract_html_ori.js +2 -2
  64. package/dist/extractOrigin/extract_js_ori.js +2 -2
  65. package/dist/handle.js +57 -7
  66. package/dist/index.js +36 -7
  67. package/dist/mergeExcel.js +407 -0
  68. package/dist/mergeJson.js +423 -2
  69. package/dist/util/config.js +90 -32
  70. package/dist/util/index.js +48 -41
  71. package/index.js +5 -5
  72. package/package.json +63 -62
  73. package/result.txt +53 -53
  74. package/test.js +182 -182
@@ -0,0 +1,407 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _regenerator = require("babel-runtime/regenerator");
6
+
7
+ var _regenerator2 = _interopRequireDefault(_regenerator);
8
+
9
+ var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
10
+
11
+ var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
12
+
13
+ /**
14
+ * 合并两个Excel文件中的语种词条,去重后生成对应的语种JSON文件
15
+ * @param {Object} option 配置选项
16
+ * @param {String} option.excelPath1 第一个Excel文件路径
17
+ * @param {String} option.excelPath2 第二个Excel文件路径
18
+ * @param {String} option.sheetName1 第一个Excel的sheet名称
19
+ * @param {String} option.sheetName2 第二个Excel的sheet名称
20
+ * @param {String} option.keyName key列名称,默认为"EN"
21
+ * @param {String} option.valueName value列名称,默认为"ALL"(表示所有语种列)
22
+ * @param {String} option.outPath 输出JSON文件的目录
23
+ */
24
+ var mergeExcel = function () {
25
+ var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(option) {
26
+ var data1, data2, result1, result2, mergedData, langNameMap, outPath, promiseList, lang, langDirName, langDirPath, langFilePath;
27
+ return _regenerator2.default.wrap(function _callee$(_context) {
28
+ while (1) {
29
+ switch (_context.prev = _context.next) {
30
+ case 0:
31
+ _context.prev = 0;
32
+
33
+ // 读取两个Excel文件
34
+ data1 = (0, _index.loadExcel)(option.excelPath1, option.sheetName1);
35
+ data2 = (0, _index.loadExcel)(option.excelPath2, option.sheetName2);
36
+
37
+ if (!(data1.length === 0)) {
38
+ _context.next = 6;
39
+ break;
40
+ }
41
+
42
+ (0, _index.log)("\u7B2C\u4E00\u4E2AExcel\u6587\u4EF6\u6570\u636E\u4E3A\u7A7A", _index.LOG_TYPE.WARNING);
43
+ return _context.abrupt("return", Promise.resolve({}));
44
+
45
+ case 6:
46
+ if (!(data2.length === 0)) {
47
+ _context.next = 9;
48
+ break;
49
+ }
50
+
51
+ (0, _index.log)("\u7B2C\u4E8C\u4E2AExcel\u6587\u4EF6\u6570\u636E\u4E3A\u7A7A", _index.LOG_TYPE.WARNING);
52
+ return _context.abrupt("return", Promise.resolve({}));
53
+
54
+ case 9:
55
+
56
+ // 处理第一个Excel文件
57
+ result1 = transferData(data1, {
58
+ key: option.keyName || "EN",
59
+ value: option.valueName || "ALL",
60
+ excelPath: option.excelPath1,
61
+ sheetName: option.sheetName1
62
+ });
63
+
64
+ if (!(result1 === -1)) {
65
+ _context.next = 12;
66
+ break;
67
+ }
68
+
69
+ return _context.abrupt("return", Promise.resolve({}));
70
+
71
+ case 12:
72
+
73
+ // 处理第二个Excel文件
74
+ result2 = transferData(data2, {
75
+ key: option.keyName || "EN",
76
+ value: option.valueName || "ALL",
77
+ excelPath: option.excelPath2,
78
+ sheetName: option.sheetName2
79
+ });
80
+
81
+ if (!(result2 === -1)) {
82
+ _context.next = 15;
83
+ break;
84
+ }
85
+
86
+ return _context.abrupt("return", Promise.resolve({}));
87
+
88
+ case 15:
89
+
90
+ // 合并两个结果,去重(以key为准,如果key相同,保留第一个的值)
91
+ mergedData = {};
92
+
93
+ // 创建语种名称映射表(原始名称 -> 标准化名称)
94
+
95
+ langNameMap = new Map();
96
+
97
+ // 处理第一个Excel的语种
98
+
99
+ Object.keys(result1).forEach(function (originalLang) {
100
+ var normalizedLang = normalizeLangName(originalLang);
101
+ if (normalizedLang && !langNameMap.has(normalizedLang)) {
102
+ langNameMap.set(normalizedLang, originalLang);
103
+ }
104
+ });
105
+
106
+ // 处理第二个Excel的语种
107
+ Object.keys(result2).forEach(function (originalLang) {
108
+ var normalizedLang = normalizeLangName(originalLang);
109
+ if (normalizedLang && !langNameMap.has(normalizedLang)) {
110
+ langNameMap.set(normalizedLang, originalLang);
111
+ }
112
+ });
113
+
114
+ // 使用标准化的语种名称进行合并
115
+ langNameMap.forEach(function (originalLang, normalizedLang) {
116
+ mergedData[normalizedLang] = {};
117
+
118
+ // 查找第一个Excel中所有可能匹配的语种(考虑大小写和空格差异)
119
+ Object.keys(result1).forEach(function (lang) {
120
+ if (normalizeLangName(lang) === normalizedLang) {
121
+ Object.assign(mergedData[normalizedLang], result1[lang]);
122
+ }
123
+ });
124
+
125
+ // 查找第二个Excel中所有可能匹配的语种(考虑大小写和空格差异)
126
+ Object.keys(result2).forEach(function (lang) {
127
+ if (normalizeLangName(lang) === normalizedLang) {
128
+ Object.keys(result2[lang]).forEach(function (key) {
129
+ if (!mergedData[normalizedLang][key]) {
130
+ mergedData[normalizedLang][key] = result2[lang][key];
131
+ }
132
+ });
133
+ }
134
+ });
135
+ });
136
+
137
+ // 生成JSON文件
138
+
139
+ if (!option.outPath) {
140
+ _context.next = 39;
141
+ break;
142
+ }
143
+
144
+ outPath = _path2.default.join(option.outPath, "lang");
145
+
146
+ // 确保lang目录存在
147
+
148
+ _context.next = 24;
149
+ return _fsExtra2.default.ensureDir(outPath);
150
+
151
+ case 24:
152
+ promiseList = [];
153
+ _context.t0 = _regenerator2.default.keys(mergedData);
154
+
155
+ case 26:
156
+ if ((_context.t1 = _context.t0()).done) {
157
+ _context.next = 36;
158
+ break;
159
+ }
160
+
161
+ lang = _context.t1.value;
162
+
163
+ // 使用 langArr 中的键作为目录名
164
+ langDirName = getLangDirName(lang);
165
+ langDirPath = _path2.default.join(outPath, langDirName);
166
+ _context.next = 32;
167
+ return _fsExtra2.default.ensureDir(langDirPath);
168
+
169
+ case 32:
170
+
171
+ // 固定文件名为 translate.json
172
+ langFilePath = _path2.default.join(langDirPath, "translate.json");
173
+
174
+ promiseList.push((0, _index.writeJson)(mergedData[lang], langFilePath));
175
+ _context.next = 26;
176
+ break;
177
+
178
+ case 36:
179
+ return _context.abrupt("return", Promise.all(promiseList).then(function () {
180
+ (0, _index.log)("\u5408\u5E76Excel\u6587\u4EF6\u5E76\u751F\u6210JSON\u6587\u4EF6\u5DF2\u5199\u5165\u6587\u4EF6\u5939-" + outPath + "\u4E0B", _index.LOG_TYPE.DONE);
181
+ return mergedData;
182
+ }).catch(function (error) {
183
+ (0, _index.log)("\u5408\u5E76Excel\u6587\u4EF6\u5931\u8D25\uFF0C" + error, _index.LOG_TYPE.ERROR);
184
+ return {};
185
+ }));
186
+
187
+ case 39:
188
+ (0, _index.log)("\u5408\u5E76Excel\u6587\u4EF6\u6210\u529F\uFF0C\u65E0\u9700\u4FDD\u5B58\u5230\u672C\u5730");
189
+ return _context.abrupt("return", Promise.resolve(mergedData));
190
+
191
+ case 41:
192
+ _context.next = 47;
193
+ break;
194
+
195
+ case 43:
196
+ _context.prev = 43;
197
+ _context.t2 = _context["catch"](0);
198
+
199
+ (0, _index.log)("\u5408\u5E76Excel\u6587\u4EF6\u51FA\u9519\uFF0C" + _context.t2, _index.LOG_TYPE.ERROR);
200
+ return _context.abrupt("return", Promise.resolve({}));
201
+
202
+ case 47:
203
+ case "end":
204
+ return _context.stop();
205
+ }
206
+ }
207
+ }, _callee, this, [[0, 43]]);
208
+ }));
209
+
210
+ return function mergeExcel(_x) {
211
+ return _ref.apply(this, arguments);
212
+ };
213
+ }();
214
+
215
+ /**
216
+ * 转换Excel数据为对象格式
217
+ * @param {Array} data Excel数据
218
+ * @param {Object} option 配置选项
219
+ */
220
+
221
+
222
+ var _index = require("./util/index");
223
+
224
+ var _path = require("path");
225
+
226
+ var _path2 = _interopRequireDefault(_path);
227
+
228
+ var _fsExtra = require("fs-extra");
229
+
230
+ var _fsExtra2 = _interopRequireDefault(_fsExtra);
231
+
232
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
233
+
234
+ // 语种映射表,与 ExtractLangExcel.js 中的 langArr 保持一致
235
+ var langArr = {
236
+ en: "英语",
237
+ cn: "简体中文",
238
+ zh: "台湾繁体",
239
+ de: "德语",
240
+ es: "欧洲西语",
241
+ fr: "法语",
242
+ hu: "匈牙利语",
243
+ it: "意大利语",
244
+ pl: "波兰语",
245
+ ro: "罗马尼亚语",
246
+ sa: "阿拉伯语",
247
+ tr: "土耳其语",
248
+ ru: "俄语",
249
+ pt: "葡萄牙语",
250
+ uk: "乌克兰语",
251
+ br: "巴西葡语",
252
+ nl: "荷兰语",
253
+ cs: "捷克语",
254
+ mx: "拉美西语",
255
+ kk: "哈萨克语",
256
+ ko: "韩语",
257
+ bg: "保加利亚语",
258
+ laes: "美西",
259
+ brpt: "巴葡"
260
+ };
261
+
262
+ /**
263
+ * 安全的 trim 函数,处理 undefined 和 null
264
+ */
265
+ function safeTrim(str) {
266
+ if (str == null) {
267
+ return "";
268
+ }
269
+ return (0, _index.trim)(String(str));
270
+ }
271
+
272
+ /**
273
+ * 标准化语种名称,去除空格并统一为大写
274
+ * 用于合并时统一语种名称
275
+ */
276
+ function normalizeLangName(langName) {
277
+ if (!langName || typeof langName !== 'string') {
278
+ return '';
279
+ }
280
+ return langName.replace(/\s+/g, '').toUpperCase();
281
+ }
282
+
283
+ /**
284
+ * 根据语种名称查找 langArr 中对应的键
285
+ * @param {String} langName 语种名称(可能是大写、小写或带空格)
286
+ * @returns {String} langArr 中的键,如果找不到则返回标准化后的小写名称
287
+ */
288
+ function getLangDirName(langName) {
289
+ if (!langName || typeof langName !== 'string') {
290
+ return '';
291
+ }
292
+
293
+ // 标准化语种名称(去除空格,转小写)
294
+ var normalized = langName.replace(/\s+/g, '').toLowerCase();
295
+
296
+ // 直接在 langArr 中查找
297
+ if (langArr[normalized]) {
298
+ return normalized;
299
+ }
300
+
301
+ // 如果找不到,尝试匹配 langArr 的值
302
+ for (var key in langArr) {
303
+ if (langArr[key] === langName || langArr[key].toLowerCase() === normalized) {
304
+ return key;
305
+ }
306
+ }
307
+
308
+ // 如果都找不到,返回标准化后的小写名称
309
+ return normalized;
310
+ }function transferData(data, option) {
311
+ var keyValueRow = data.shift(),
312
+ key = option.key,
313
+ value = option.value || "",
314
+ outData = {};
315
+
316
+ if (!key) {
317
+ key = "EN";
318
+ }
319
+
320
+ // 处理可能包含 undefined 的 keyValueRow
321
+ if (!keyValueRow || !Array.isArray(keyValueRow)) {
322
+ (0, _index.log)("Excel\u6587\u4EF6\u683C\u5F0F\u9519\u8BEF\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u8868\u5934", _index.LOG_TYPE.ERROR);
323
+ return -1;
324
+ }
325
+
326
+ // 过滤掉 undefined 和 null,并转换为字符串
327
+ keyValueRow = keyValueRow.map(function (item) {
328
+ return item != null ? String(item) : "";
329
+ }).join(",").toUpperCase().split(",");
330
+
331
+ var keyIndex = keyValueRow.indexOf(key.toUpperCase());
332
+
333
+ if (keyIndex === -1) {
334
+ (0, _index.log)("Excel\u4E2D\u4E0D\u5B58\u5728keyName\u5217: " + key, _index.LOG_TYPE.ERROR);
335
+ return -1;
336
+ }
337
+
338
+ if (data.length === 0) {
339
+ return outData;
340
+ }
341
+
342
+ // 多列解析
343
+ value = value ? value.toUpperCase().split(",") : [];
344
+
345
+ if (value.length === 0 || value.length === 1 && value[0] === "ALL") {
346
+ value = keyValueRow.filter(function (item) {
347
+ if (!item || typeof item !== 'string') {
348
+ return false;
349
+ }
350
+ return !!item.replace(/\s/g, "") && item !== key.toUpperCase();
351
+ });
352
+ }
353
+
354
+ var valueIndex = {};
355
+ // 获取每个值字段对应的excel的列索引
356
+ value.forEach(function (item) {
357
+ valueIndex[item] = keyValueRow.indexOf(item);
358
+ });
359
+
360
+ value.forEach(function (valItem) {
361
+ var valIndex = valueIndex[valItem],
362
+ transData = {};
363
+
364
+ if (valIndex === -1) {
365
+ (0, _index.log)("Excel\u4E2D\u4E0D\u5B58\u5728" + valItem + "\u5217", _index.LOG_TYPE.WARNING);
366
+ } else {
367
+ data.forEach(function (dataItem) {
368
+ // 确保 dataItem 存在且是数组
369
+ if (!dataItem || !Array.isArray(dataItem)) {
370
+ return;
371
+ }
372
+
373
+ // 安全地获取值,处理 undefined 情况
374
+ var keyWorld = safeTrim(dataItem[keyIndex]);
375
+ var valueWorld = safeTrim(dataItem[valIndex]);
376
+
377
+ if (!keyWorld) {
378
+ return; // 跳过key为空的行
379
+ }
380
+
381
+ if (!valueWorld) {
382
+ valueWorld = keyWorld; // 如果value为空,使用key作为value
383
+ }
384
+
385
+ // 如果key已存在,跳过(去重)
386
+ if (!transData[keyWorld]) {
387
+ transData[keyWorld] = valueWorld;
388
+ }
389
+ });
390
+ }
391
+
392
+ // 过滤掉 key 为 undefined 或 "" 的项
393
+ Object.keys(transData).forEach(function (k) {
394
+ if (k === undefined || k === "") {
395
+ delete transData[k];
396
+ }
397
+ });
398
+
399
+ if (Object.keys(transData).length > 0) {
400
+ outData[valItem] = transData;
401
+ }
402
+ });
403
+
404
+ return outData;
405
+ }
406
+
407
+ exports.default = mergeExcel;