td-octopus 0.1.9 → 0.1.10
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/cmds/check.js +9 -0
- package/package.json +2 -2
- package/src/check/index.js +77 -0
- package/src/reduce/index.js +2 -2
package/cmds/check.js
ADDED
package/package.json
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Descripttion: 校验项目中缺少的翻译项
|
|
3
|
+
* @Author: 郑泳健
|
|
4
|
+
* @Date: 2024-12-12 15:00:24
|
|
5
|
+
* @LastEditors: 郑泳健
|
|
6
|
+
* @LastEditTime: 2025-09-09 15:36:13
|
|
7
|
+
*/
|
|
8
|
+
const path = require('path')
|
|
9
|
+
const fs = require('fs')
|
|
10
|
+
const shell = require('shelljs');
|
|
11
|
+
const { getSpecifiedFiles, isFile } = require('../utils/file')
|
|
12
|
+
const syncLang = require('../utils/syncLang')
|
|
13
|
+
const { flatObject, rewriteFiles, getFileKeyValueList, getAdjustLangObjAndAddList } = require('../utils/translate');
|
|
14
|
+
const { failInfo, highlightText } = require('../utils/colors');
|
|
15
|
+
const { getProjectConfig } = require('../utils/index')
|
|
16
|
+
const ora = require('ora');
|
|
17
|
+
|
|
18
|
+
const CONFIG = getProjectConfig();
|
|
19
|
+
|
|
20
|
+
const spinner = ora('开始check');
|
|
21
|
+
|
|
22
|
+
function extractThreeLevelI18NKeys(code) {
|
|
23
|
+
// 匹配恰好三级的I18N键值(I18N.xxx.xxx.xxx)
|
|
24
|
+
// 使用正则表达式确保前面不是点,后面也不是点或字母数字下划线
|
|
25
|
+
const pattern = /(?<!\.)I18N\.[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(?![a-zA-Z0-9_\.])/g;
|
|
26
|
+
|
|
27
|
+
const matches = code.match(pattern) || [];
|
|
28
|
+
|
|
29
|
+
// 去重并返回
|
|
30
|
+
return [...new Set(matches)];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 递归读取文件夹中所有 .js 文件内容
|
|
34
|
+
function readJsFiles(folderPath) {
|
|
35
|
+
let jsContent = '';
|
|
36
|
+
|
|
37
|
+
const files = fs.readdirSync(folderPath); // 读取文件夹内容
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
const fullPath = path.join(folderPath, file);
|
|
40
|
+
const stats = fs.statSync(fullPath); // 获取文件或文件夹状态
|
|
41
|
+
|
|
42
|
+
if (stats.isDirectory()) {
|
|
43
|
+
// 如果是文件夹,递归处理
|
|
44
|
+
jsContent += readJsFiles(fullPath);
|
|
45
|
+
} else if (path.extname(fullPath) === '.js') {
|
|
46
|
+
// 如果是 .js 文件,读取文件内容
|
|
47
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
48
|
+
jsContent += `\n/* File: ${fullPath} */\n${content}\n`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return jsContent;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 同步不同的语言包
|
|
56
|
+
function main() {
|
|
57
|
+
(async () => {
|
|
58
|
+
const distLang = Array.isArray(CONFIG.distLangs) ? CONFIG.distLangs : []
|
|
59
|
+
|
|
60
|
+
// 删除中文下多余的key
|
|
61
|
+
const zhCN = syncLang('zh-CN');
|
|
62
|
+
const zhCNFlat = flatObject(zhCN);
|
|
63
|
+
// 当前项目所有的key
|
|
64
|
+
const keys = Object.keys(zhCNFlat)
|
|
65
|
+
const totalText = readJsFiles(path.resolve(process.cwd(), 'src'))
|
|
66
|
+
const totalTranslateList = extractThreeLevelI18NKeys(totalText);
|
|
67
|
+
const zhCnKey = Object.keys(zhCNFlat)
|
|
68
|
+
let result = {}
|
|
69
|
+
const lostKey = totalTranslateList.filter(item => !zhCnKey.includes(item.replace('I18N.', '')))
|
|
70
|
+
fs.writeFileSync(path.resolve(process.cwd(), 'lostI18N.js'), JSON.stringify(lostKey, null, 4), 'utf-8')
|
|
71
|
+
spinner.succeed(`查询完毕,共计丢失${lostKey.length}个,请在lostI18N.js中查看`)
|
|
72
|
+
})()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
main
|
|
77
|
+
}
|
package/src/reduce/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @Author: 郑泳健
|
|
4
4
|
* @Date: 2024-12-12 15:00:24
|
|
5
5
|
* @LastEditors: 郑泳健
|
|
6
|
-
* @LastEditTime:
|
|
6
|
+
* @LastEditTime: 2025-09-09 15:06:47
|
|
7
7
|
*/
|
|
8
8
|
const path = require('path')
|
|
9
9
|
const fs = require('fs')
|
|
@@ -46,7 +46,7 @@ function main() {
|
|
|
46
46
|
(async () => {
|
|
47
47
|
const distLang = Array.isArray(CONFIG.distLangs) ? CONFIG.distLangs : []
|
|
48
48
|
|
|
49
|
-
//
|
|
49
|
+
// 删除中文下多余的key
|
|
50
50
|
const zhCN = syncLang('zh-CN');
|
|
51
51
|
const zhCNFlat = flatObject(zhCN);
|
|
52
52
|
// 当前项目所有的key
|