cc-translate 0.5.3 → 0.5.5
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 +5 -4
- package/src/index.ts +2 -0
- package/src/lib/cache/index.ts +3 -0
- package/src/lib/utils.ts +11 -0
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-translate",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "A language translation tool based on OpenAI",
|
|
5
5
|
"author": "maybe",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"packageManager": "yarn@1.22.22",
|
|
7
8
|
"types": "./index.d.ts",
|
|
8
9
|
"main": "./index.mjs",
|
|
@@ -21,11 +22,9 @@
|
|
|
21
22
|
},
|
|
22
23
|
"homepage": "https://github.com/cctip/cwallet-translate-script",
|
|
23
24
|
"bugs": "https://github.com/xxx/cwallet-translate-script/issues",
|
|
24
|
-
"type": "module",
|
|
25
25
|
"scripts": {
|
|
26
26
|
"publish": "npx tsc && npm publish",
|
|
27
|
-
"compile": "tsc"
|
|
28
|
-
"check-env": "echo check environment successfully"
|
|
27
|
+
"compile": "tsc"
|
|
29
28
|
},
|
|
30
29
|
"exports": {
|
|
31
30
|
".": {
|
|
@@ -37,11 +36,13 @@
|
|
|
37
36
|
"ansi-colors": "^4.1.3",
|
|
38
37
|
"cli-progress": "^3.12.0",
|
|
39
38
|
"openai": "^4.68.1",
|
|
39
|
+
"semver": "^7.6.3",
|
|
40
40
|
"ts-node": "^10.9.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/cli-progress": "^3.11.6",
|
|
44
44
|
"@types/node": "^22.7.9",
|
|
45
|
+
"@types/semver": "^7.5.8",
|
|
45
46
|
"typescript": "^5.6.3"
|
|
46
47
|
},
|
|
47
48
|
"engines": {
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
SupportLanguageType,
|
|
15
15
|
} from "./types";
|
|
16
16
|
import {
|
|
17
|
+
checkEnvNodeVersion,
|
|
17
18
|
dequeue,
|
|
18
19
|
getRandomNumber,
|
|
19
20
|
notExistsToCreateFile,
|
|
@@ -59,6 +60,7 @@ export class CwalletTranslate {
|
|
|
59
60
|
this.OUTPUT_ROOT_PATH = params.outputRootPath;
|
|
60
61
|
this.fineTune = params.fineTune;
|
|
61
62
|
this.languages = params.languages ?? [];
|
|
63
|
+
checkEnvNodeVersion();
|
|
62
64
|
this.createOpenAIClient();
|
|
63
65
|
}
|
|
64
66
|
|
package/src/lib/cache/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import {
|
|
4
|
+
checkEnvNodeVersion,
|
|
4
5
|
intersection,
|
|
5
6
|
notExistsToCreateFile,
|
|
6
7
|
readJsonFileSync,
|
|
@@ -83,6 +84,7 @@ export const registerLanguageCacheFile = async (
|
|
|
83
84
|
* 根据已翻译文件生成缓存
|
|
84
85
|
*/
|
|
85
86
|
export const generateCache = async (params: IGenerateCacheParams) => {
|
|
87
|
+
checkEnvNodeVersion();
|
|
86
88
|
const { sourceFolderPath, languages, exportFolderPath, sourceLanguage } =
|
|
87
89
|
params;
|
|
88
90
|
|
|
@@ -167,6 +169,7 @@ const readFile = (sourceFolderPath: string, fileName: string): ICacheFile => {
|
|
|
167
169
|
* @param params
|
|
168
170
|
*/
|
|
169
171
|
export const deleteBatchCache = (params: IDeleteSingleCacheParams) => {
|
|
172
|
+
checkEnvNodeVersion();
|
|
170
173
|
const { keys, cacheFolderPath, languages, cacheFileName } = params;
|
|
171
174
|
let deleteLanguages: string[] = [];
|
|
172
175
|
const localLanguages = fs.readdirSync(cacheFolderPath);
|
package/src/lib/utils.ts
CHANGED
|
@@ -2,6 +2,7 @@ import path from "path";
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import { ICreateJsonFileParams } from "../types";
|
|
4
4
|
import { logErrorToFile } from "./log/index.js";
|
|
5
|
+
import semver from "semver";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 不存在的文件夹则创建
|
|
@@ -111,3 +112,13 @@ export const dequeue = async (queue: (() => Promise<void>)[]) => {
|
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
};
|
|
115
|
+
const REQUIRED_VERSION = ">=20.12.1";
|
|
116
|
+
export const checkEnvNodeVersion = () => {
|
|
117
|
+
// 检查当前 Node.js 版本
|
|
118
|
+
if (!semver.satisfies(process.version, REQUIRED_VERSION)) {
|
|
119
|
+
console.error(
|
|
120
|
+
`\x1b[31mError:\x1b[0m Unsupported Node.js version. Current version: ${process.version}. Required: ${REQUIRED_VERSION}.`
|
|
121
|
+
);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
};
|