@zzclub/z-cli 0.6.2 → 0.7.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,45 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+ ## v0.7.0
5
+
6
+ [compare changes](https://github.com/aatrooox/z-cli/compare/v0.6.2...v0.7.0)
7
+
8
+ ### 🚀 Enhancements
9
+
10
+ - 剔除axios改为原生fetch ([6ca4bda](https://github.com/aatrooox/z-cli/commit/6ca4bda))
11
+
12
+ ### 🏡 Chore
13
+
14
+ - **release:** V0.7.0 ([2c21466](https://github.com/aatrooox/z-cli/commit/2c21466))
15
+ - **release:** V0.8.0 ([61441e4](https://github.com/aatrooox/z-cli/commit/61441e4))
16
+ - **release:** V0.7.1 ([3044a7f](https://github.com/aatrooox/z-cli/commit/3044a7f))
17
+ - Rollback ([f348572](https://github.com/aatrooox/z-cli/commit/f348572))
18
+
19
+ ### ❤️ Contributors
20
+
21
+ - Aatrox <gnakzz@qq.com>
22
+
23
+ ## v0.7.1
24
+
25
+ [compare changes](https://github.com/aatrooox/z-cli/compare/v0.8.0...v0.7.1)
26
+
27
+ ## v0.8.0
28
+
29
+ [compare changes](https://github.com/aatrooox/z-cli/compare/v0.7.0...v0.8.0)
30
+
31
+ ### 🚀 Enhancements
32
+
33
+ - 剔除axios改为原生fetch ([6ca4bda](https://github.com/aatrooox/z-cli/commit/6ca4bda))
34
+
35
+ ### ❤️ Contributors
36
+
37
+ - Aatrox <gnakzz@qq.com>
38
+
39
+ ## v0.7.0
40
+
41
+ [compare changes](https://github.com/aatrooox/z-cli/compare/v0.6.2...v0.7.0)
42
+
4
43
  ## v0.6.2
5
44
 
6
45
  [compare changes](https://github.com/aatrooox/z-cli/compare/v0.6.1...v0.6.2)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zzclub/z-cli",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "all-in-one 工具箱,专为提升日常及工作效率而生",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -9,6 +9,9 @@
9
9
  "z": "src/index.js",
10
10
  "zz": "src/index.js"
11
11
  },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
12
15
  "repository": {
13
16
  "type": "git",
14
17
  "url": "git+https://github.com/aatrooox/z-cli.git"
@@ -35,7 +38,6 @@
35
38
  },
36
39
  "license": "MIT",
37
40
  "dependencies": {
38
- "axios": "1.6.2",
39
41
  "chalk": "5.3.0",
40
42
  "commander": "11.0.0",
41
43
  "inquirer": "9.2.8",
@@ -169,13 +169,13 @@ function startTranslate(limitedWords, cb) {
169
169
  console.log(err);
170
170
  });
171
171
 
172
- let translate_result = res.trans_result
173
- ? res.trans_result[0].dst
172
+ let translate_result = res?.trans_result
173
+ ? res?.trans_result[0].dst
174
174
  : word.value;
175
- if (res.error_code) {
176
- const spinner = ora();
177
- spinner.warn(`翻译[${word.value}]时出错:` + JSON.stringify(res))
178
- }
175
+ if (res?.error_code || !res) {
176
+ const spinner = ora();
177
+ spinner.warn(`翻译[${word.value}]时出错:` + JSON.stringify(res))
178
+ }
179
179
  word.value = translate_result;
180
180
  });
181
181
  curIndex++;
package/src/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from "commander";
3
- // const pkg = require("./package.json");
4
3
  import { registerCommand, initProgram } from "./command/index.js";
5
4
  import { translateCmd } from "./command/translate.js";
6
5
  import { configCmd } from "./command/config.js";
@@ -8,12 +7,17 @@ import { setCmd } from "./command/set.js";
8
7
  import { tinyCmd } from "./command/tiny.js";
9
8
  import { picgoCmd } from "./command/picgo.js";
10
9
  import { checkUpdate, checkNodeVersion } from './utils/common.js'
11
- import { i18nCmd } from "./command/i18n.js";
10
+ import { i18nCmd } from "./command/i18n.js";
11
+
12
12
  const program = new Command();
13
13
 
14
14
  initProgram(program, async () => {
15
- checkNodeVersion()
16
- await checkUpdate()
15
+
16
+ if (process.env.RUNTIME_ENV !== 'electron') {
17
+ checkNodeVersion()
18
+ await checkUpdate()
19
+ }
20
+
17
21
  registerCommand(program, translateCmd);
18
22
 
19
23
  registerCommand(program, setCmd);
@@ -22,27 +22,56 @@ function genSign(options) {
22
22
  return sign;
23
23
  }
24
24
 
25
+ // export async function translate(options) {
26
+ // await genUser();
27
+ // return new Promise((resolve, reject) => {
28
+ // axios({
29
+ // url: "http://api.fanyi.baidu.com/api/trans/vip/translate",
30
+ // method: "get",
31
+ // params: {
32
+ // q: options.query,
33
+ // appid: appid,
34
+ // salt: salt,
35
+ // from: options.from,
36
+ // to: options.to,
37
+ // sign: genSign(options),
38
+ // },
39
+ // })
40
+ // .then((res) => {
41
+ // console.log(res);
42
+ // resolve(res.data);
43
+ // })
44
+ // .catch((err) => {
45
+ // reject("翻译失败" + JSON.stringify(err));
46
+ // })
47
+ // .finally(() => {});
48
+ // });
49
+ // }
50
+
25
51
  export async function translate(options) {
26
52
  await genUser();
27
- return new Promise((resolve, reject) => {
28
- axios({
29
- url: "http://api.fanyi.baidu.com/api/trans/vip/translate",
30
- method: "get",
31
- params: {
32
- q: options.query,
33
- appid: appid,
34
- salt: salt,
35
- from: options.from,
36
- to: options.to,
37
- sign: genSign(options),
38
- },
39
- })
40
- .then((res) => {
41
- resolve(res.data);
42
- })
43
- .catch((err) => {
44
- reject("翻译失败");
45
- })
46
- .finally(() => {});
47
- });
48
- }
53
+
54
+ try {
55
+ const params = new URLSearchParams({
56
+ q: options.query,
57
+ appid: appid,
58
+ salt: salt,
59
+ from: options.from,
60
+ to: options.to,
61
+ sign: genSign(options)
62
+ });
63
+
64
+ const url = `http://api.fanyi.baidu.com/api/trans/vip/translate?${params}`;
65
+ const response = await fetch(url);
66
+
67
+ if (!response.ok) {
68
+ throw new Error(`HTTP error! status: ${response.status}`);
69
+ }
70
+
71
+ const data = await response.json();
72
+ // console.log(data);
73
+ return data;
74
+ } catch (error) {
75
+ throw new Error("翻译失败" + JSON.stringify(error));
76
+ }
77
+ }