@zzclub/z-cli 0.6.2 → 0.7.1
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 +51 -0
- package/README.md +45 -6
- package/package.json +4 -2
- package/src/command/translate.js +6 -6
- package/src/index.js +8 -4
- package/src/translate-api/index.js +51 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v0.7.1
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.7.0...v0.7.1)
|
|
7
|
+
|
|
8
|
+
### 📖 Documentation
|
|
9
|
+
|
|
10
|
+
- 更新说明 ([459c72f](https://github.com/aatrooox/z-cli/commit/459c72f))
|
|
11
|
+
|
|
12
|
+
### ❤️ Contributors
|
|
13
|
+
|
|
14
|
+
- Aatrox <gnakzz@qq.com>
|
|
15
|
+
|
|
16
|
+
## v0.7.0
|
|
17
|
+
|
|
18
|
+
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.6.2...v0.7.0)
|
|
19
|
+
|
|
20
|
+
### 🚀 Enhancements
|
|
21
|
+
|
|
22
|
+
- 剔除axios改为原生fetch ([6ca4bda](https://github.com/aatrooox/z-cli/commit/6ca4bda))
|
|
23
|
+
|
|
24
|
+
### 🏡 Chore
|
|
25
|
+
|
|
26
|
+
- **release:** V0.7.0 ([2c21466](https://github.com/aatrooox/z-cli/commit/2c21466))
|
|
27
|
+
- **release:** V0.8.0 ([61441e4](https://github.com/aatrooox/z-cli/commit/61441e4))
|
|
28
|
+
- **release:** V0.7.1 ([3044a7f](https://github.com/aatrooox/z-cli/commit/3044a7f))
|
|
29
|
+
- Rollback ([f348572](https://github.com/aatrooox/z-cli/commit/f348572))
|
|
30
|
+
|
|
31
|
+
### ❤️ Contributors
|
|
32
|
+
|
|
33
|
+
- Aatrox <gnakzz@qq.com>
|
|
34
|
+
|
|
35
|
+
## v0.7.1
|
|
36
|
+
|
|
37
|
+
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.8.0...v0.7.1)
|
|
38
|
+
|
|
39
|
+
## v0.8.0
|
|
40
|
+
|
|
41
|
+
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.7.0...v0.8.0)
|
|
42
|
+
|
|
43
|
+
### 🚀 Enhancements
|
|
44
|
+
|
|
45
|
+
- 剔除axios改为原生fetch ([6ca4bda](https://github.com/aatrooox/z-cli/commit/6ca4bda))
|
|
46
|
+
|
|
47
|
+
### ❤️ Contributors
|
|
48
|
+
|
|
49
|
+
- Aatrox <gnakzz@qq.com>
|
|
50
|
+
|
|
51
|
+
## v0.7.0
|
|
52
|
+
|
|
53
|
+
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.6.2...v0.7.0)
|
|
54
|
+
|
|
4
55
|
## v0.6.2
|
|
5
56
|
|
|
6
57
|
[compare changes](https://github.com/aatrooox/z-cli/compare/v0.6.1...v0.6.2)
|
package/README.md
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
**这是一个效率类命令行工具, 为了解决工作中或个人开发过程中的重复或繁琐问题**
|
|
4
4
|
|
|
5
|
-
node >= 18.18.0
|
|
6
|
-
|
|
7
|
-
推荐版本(我的):`20.18.1`
|
|
8
|
-
|
|
9
5
|
## 功能一览
|
|
10
6
|
|
|
11
7
|
- `i18n`: 提取 `.vue` 文件中的 `i18n` 语法
|
|
@@ -20,15 +16,58 @@
|
|
|
20
16
|
**特别注意:**
|
|
21
17
|
**tiny命令不再支持和picgo联动, 仅支持压缩后,自动替换一下md文件里的图片链接, 之后的操作可以用obsidian里的插件[image auto upload Plugin]完成~~**
|
|
22
18
|
|
|
23
|
-
|
|
24
19
|
## 安装
|
|
25
20
|
|
|
26
|
-
`
|
|
21
|
+
> 对于不擅长nodejs的使用者更推荐使用 `bun`
|
|
22
|
+
|
|
23
|
+
### Node
|
|
24
|
+
|
|
25
|
+
使用 `nvm` 管理多个 `node` 版本
|
|
26
|
+
|
|
27
|
+
`node >= 18.18.0`
|
|
28
|
+
|
|
29
|
+
推荐版本(我的):`20.18.1`
|
|
30
|
+
|
|
31
|
+
查看 `registry` (非必要步骤)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm config get registry
|
|
35
|
+
# https://registry.npmjs.org
|
|
36
|
+
# 如果不是,则需要先设置
|
|
37
|
+
npm config set registry=https://registry.npmjs.org
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
安装最新版
|
|
27
41
|
|
|
28
42
|
```shell
|
|
29
43
|
npm i -g @zzclub/z-cli
|
|
30
44
|
```
|
|
31
45
|
|
|
46
|
+
安装后只能在当前 `node` 版本下使用,切换到其他低版本 `node` 则无效
|
|
47
|
+
|
|
48
|
+
全局命令为:`zz` 或 `z`
|
|
49
|
+
|
|
50
|
+
### Bun
|
|
51
|
+
|
|
52
|
+
macos
|
|
53
|
+
```bash
|
|
54
|
+
curl -fsSL https://bun.sh/install | bash
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
wind
|
|
58
|
+
```bash
|
|
59
|
+
powershell -c "irm bun.sh/install.ps1 | iex"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
安装最新版
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
bun i -g @zzclub/z-cli
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**如果提示缺少某个包**,可以按提示再次运行相关命令
|
|
69
|
+
|
|
70
|
+
|
|
32
71
|
## i18n 规则说明
|
|
33
72
|
|
|
34
73
|
### 文件
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zzclub/z-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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",
|
package/src/command/translate.js
CHANGED
|
@@ -169,13 +169,13 @@ function startTranslate(limitedWords, cb) {
|
|
|
169
169
|
console.log(err);
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
-
let translate_result = res
|
|
173
|
-
? res
|
|
172
|
+
let translate_result = res?.trans_result
|
|
173
|
+
? res?.trans_result[0].dst
|
|
174
174
|
: word.value;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
10
|
+
import { i18nCmd } from "./command/i18n.js";
|
|
11
|
+
|
|
12
12
|
const program = new Command();
|
|
13
13
|
|
|
14
14
|
initProgram(program, async () => {
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
}
|