td-octopus 0.2.7 → 0.2.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/package.json +1 -1
- package/src/pop/index.js +29 -29
- package/src/stash/index.js +10 -9
package/package.json
CHANGED
package/src/pop/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @Author: 郑泳健
|
|
4
4
|
* @Date: 2024-12-12 15:00:24
|
|
5
5
|
* @LastEditors: 郑泳健
|
|
6
|
-
* @LastEditTime: 2026-
|
|
6
|
+
* @LastEditTime: 2026-04-20 15:29:52
|
|
7
7
|
*/
|
|
8
8
|
const path = require('path');
|
|
9
9
|
const fs = require('fs');
|
|
@@ -11,7 +11,7 @@ const { parse } = require('@babel/parser');
|
|
|
11
11
|
const generate = require('@babel/generator').default;
|
|
12
12
|
const syncLang = require('../utils/syncLang');
|
|
13
13
|
const { flatObject, rewriteFiles, getFileKeyValueList } = require('../utils/translate');
|
|
14
|
-
const { autoImportJSFiles } = require('../utils/index');
|
|
14
|
+
const { autoImportJSFiles, getProjectConfig } = require('../utils/index');
|
|
15
15
|
|
|
16
16
|
const { ESLint } = require('eslint');
|
|
17
17
|
|
|
@@ -58,6 +58,8 @@ function readJsFiles(folderPath) {
|
|
|
58
58
|
// 同步不同的语言包
|
|
59
59
|
function main() {
|
|
60
60
|
(async () => {
|
|
61
|
+
const config = getProjectConfig();
|
|
62
|
+
const distLangs = config.distLangs || ['en-US'];
|
|
61
63
|
const zhCN = syncLang('zh-CN');
|
|
62
64
|
const zhCNFlat = flatObject(zhCN);
|
|
63
65
|
const totalText = readJsFiles(path.resolve(process.cwd(), 'src'));
|
|
@@ -77,33 +79,31 @@ function main() {
|
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
79
81
|
spinner.start(`查询完毕,共计丢失${lostKey.length}个,开始同步开始`);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
autoImportJSFiles(path.resolve(process.cwd(), '.octopus/zh-CN'), cnJSON);
|
|
106
|
-
autoImportJSFiles(path.resolve(process.cwd(), '.octopus/en-US'), enJSON);
|
|
82
|
+
|
|
83
|
+
// 所有需要同步的语言,包含 zh-CN 和 distLangs
|
|
84
|
+
const allLangs = ['zh-CN', ...distLangs];
|
|
85
|
+
const langDataMap = { 'zh-CN': { data: zhCN, flat: zhCNFlat } };
|
|
86
|
+
|
|
87
|
+
// 遍历所有语言进行同步
|
|
88
|
+
for (const lang of allLangs) {
|
|
89
|
+
const langFromFlat = JSON.parse(fs.readFileSync(path.resolve(__dirname, `../octopus/${lang}.js`), 'utf-8'));
|
|
90
|
+
const { data: langData, flat: langFlat } = langDataMap[lang] || (langDataMap[lang] = {
|
|
91
|
+
data: syncLang(lang),
|
|
92
|
+
flat: flatObject(syncLang(lang))
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const langResult = lostKey.reduce((total, item) => {
|
|
96
|
+
if (langFromFlat[item.replace('I18N.', '')]) {
|
|
97
|
+
total[item.replace('I18N.', '')] = langFromFlat[item.replace('I18N.', '')];
|
|
98
|
+
}
|
|
99
|
+
return total;
|
|
100
|
+
}, langFlat);
|
|
101
|
+
|
|
102
|
+
rewriteFiles(getFileKeyValueList(langResult), lang);
|
|
103
|
+
const langJSON = fs.readFileSync(path.resolve(process.cwd(), `.octopus/${lang}/index.js`), 'utf-8');
|
|
104
|
+
autoImportJSFiles(path.resolve(process.cwd(), `.octopus/${lang}`), langJSON);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
107
|
fs.rmSync(path.resolve(__dirname, '../octopus'), { recursive: true, force: true });
|
|
108
108
|
spinner.succeed('同步完成,如果需要重新check,请先执行otp stash');
|
|
109
109
|
})();
|
package/src/stash/index.js
CHANGED
|
@@ -3,29 +3,30 @@
|
|
|
3
3
|
* @Author: 郑泳健
|
|
4
4
|
* @Date: 2024-12-12 15:00:24
|
|
5
5
|
* @LastEditors: 郑泳健
|
|
6
|
-
* @LastEditTime:
|
|
6
|
+
* @LastEditTime: 2026-04-20 15:34:33
|
|
7
7
|
*/
|
|
8
8
|
const path = require('path');
|
|
9
9
|
const fs = require('fs');
|
|
10
10
|
const syncLang = require('../utils/syncLang');
|
|
11
11
|
const { flatObject } = require('../utils/translate');
|
|
12
12
|
const ora = require('ora');
|
|
13
|
-
|
|
13
|
+
const { getProjectConfig } = require('../utils/index');
|
|
14
14
|
const spinner = ora('开始check');
|
|
15
15
|
|
|
16
16
|
// 同步不同的语言包
|
|
17
17
|
function main() {
|
|
18
18
|
(async () => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const enUS = syncLang('en-US');
|
|
22
|
-
const enUSFlat = flatObject(enUS);
|
|
19
|
+
const config = getProjectConfig();
|
|
20
|
+
const distLangs = config.distLangs || ['en-US'];
|
|
23
21
|
const outpuDir = path.resolve(__dirname, '../octopus');
|
|
24
|
-
|
|
25
22
|
fs.mkdirSync(outpuDir, { recursive: true });
|
|
23
|
+
const allLangs = ['zh-CN', ...distLangs];
|
|
26
24
|
spinner.start('开始缓存');
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
for (const lang of allLangs) {
|
|
26
|
+
const syncLangData = syncLang(lang);
|
|
27
|
+
const syncLangDataFlat = flatObject(syncLangData);
|
|
28
|
+
fs.writeFileSync(path.resolve(outpuDir, `${lang}.js`), JSON.stringify(syncLangDataFlat, null, 2), 'utf-8');
|
|
29
|
+
}
|
|
29
30
|
spinner.succeed('缓存完成');
|
|
30
31
|
})();
|
|
31
32
|
}
|