@zzclub/z-cli 0.7.1 → 0.8.0
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/command/translate.js +29 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v0.8.0
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.7.1...v0.8.0)
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
|
|
10
|
+
- 翻译目标文件类型校验 ([cc87490](https://github.com/aatrooox/z-cli/commit/cc87490))
|
|
11
|
+
|
|
12
|
+
### ❤️ Contributors
|
|
13
|
+
|
|
14
|
+
- Aatrox <gnakzz@qq.com>
|
|
15
|
+
|
|
4
16
|
## v0.7.1
|
|
5
17
|
|
|
6
18
|
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.7.0...v0.7.1)
|
package/package.json
CHANGED
package/src/command/translate.js
CHANGED
|
@@ -81,23 +81,27 @@ const translateCmd = {
|
|
|
81
81
|
} else {
|
|
82
82
|
file_spinner.succeed(`正在翻译${chalk.yellowBright(filePath)}`);
|
|
83
83
|
file_spinner.start();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
if (filePath.endsWith(".js") || filePath.endsWith(".ts")) {
|
|
85
|
+
let file_content = await readAndTranslateFileContent(filePath);
|
|
86
|
+
let fileName = path.basename(filePath);
|
|
87
|
+
let dirPath = path.dirname(filePath);
|
|
88
|
+
let newFileName =
|
|
89
|
+
fileName.split(".")[0] +
|
|
90
|
+
`-${option.language}.` +
|
|
91
|
+
fileName.split(".")[1];
|
|
92
|
+
let newFilePath = dirPath + "/" + newFileName;
|
|
93
|
+
writeFileContent(newFilePath, file_content, (spinner, isOk) => {
|
|
94
|
+
if (isOk) {
|
|
95
|
+
spinner.succeed("翻译结束");
|
|
96
|
+
} else {
|
|
97
|
+
spinner.fail("翻译失败!");
|
|
98
|
+
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
file_spinner.stop();
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
file_spinner.fail("无效的文件");
|
|
104
|
+
}
|
|
101
105
|
}
|
|
102
106
|
},
|
|
103
107
|
};
|
|
@@ -280,12 +284,15 @@ function getAllFilePaths(translateConfig, dirPath, filePaths) {
|
|
|
280
284
|
// 找到目标文件夹, 获取所有文件
|
|
281
285
|
let files = fs.readdirSync(filePath);
|
|
282
286
|
files.forEach((file) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
// 判断文件是否是以.js或.ts结尾
|
|
288
|
+
if (file.endsWith(".js") || file.endsWith(".ts")) {
|
|
289
|
+
let jsPath = path.join(filePath, file);
|
|
290
|
+
let targetPath = path.join(dirPath, translateConfig.targetDirName);
|
|
291
|
+
filePaths.push({
|
|
292
|
+
sourcePath: jsPath,
|
|
293
|
+
targetPath,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
289
296
|
});
|
|
290
297
|
} else if (!translateConfig.ignoreFiles.includes(file)) {
|
|
291
298
|
getAllFilePaths(translateConfig, filePath, filePaths);
|