@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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzclub/z-cli",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "all-in-one 工具箱,专为提升日常及工作效率而生",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -81,23 +81,27 @@ const translateCmd = {
81
81
  } else {
82
82
  file_spinner.succeed(`正在翻译${chalk.yellowBright(filePath)}`);
83
83
  file_spinner.start();
84
- let file_content = await readAndTranslateFileContent(filePath);
85
- let fileName = path.basename(filePath);
86
- let dirPath = path.dirname(filePath);
87
- let newFileName =
88
- fileName.split(".")[0] +
89
- `-${option.language}.` +
90
- fileName.split(".")[1];
91
- let newFilePath = dirPath + "/" + newFileName;
92
- writeFileContent(newFilePath, file_content, (spinner, isOk) => {
93
- if (isOk) {
94
- spinner.succeed("翻译结束");
95
- } else {
96
- spinner.fail("翻译失败!");
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
- file_spinner.stop();
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
- let jsPath = path.join(filePath, file);
284
- let targetPath = path.join(dirPath, translateConfig.targetDirName);
285
- filePaths.push({
286
- sourcePath: jsPath,
287
- targetPath,
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);