daodou-command 1.4.7 → 1.4.9

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/.daodourc ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ // build 命令配置
3
+ build: {
4
+ // Jenkins 基础配置
5
+ // jenkinsUrl: "https://jenkins.example.com/",
6
+ // jenkinsBase: "https://jenkins.example.com/job",
7
+ // jenkinsToken: "your-jenkins-token",
8
+ // jenkinsUsername: "your-username",
9
+ // jenkinsPassword: "your-password",
10
+
11
+ // 构建任务配置(必须配置)
12
+ // jobName: "your-job-name", // 必须配置的任务名称
13
+
14
+ // 构建参数配置
15
+ // buildParams: {
16
+ // token: "your-jenkins-token",
17
+ // BUILD_ENV: "test",
18
+ // version: "0.0.1"
19
+ // }
20
+ },
21
+
22
+ // lang 命令配置
23
+ lang: {
24
+ defaultLang: "en",
25
+ defaultDir: "./public/locales",
26
+ fileName: "common.json",
27
+
28
+ // 翻译引擎配置
29
+ translation: {
30
+ // 默认翻译引擎 (microsoft, google, baidu, ali, youdao, deepl, openai)
31
+ defaultEngine: "microsoft",
32
+
33
+ // 引擎优先级列表(按顺序尝试)
34
+ enginePriority: ["microsoft", "google", "baidu", "ali", "youdao", "deepl", "openai"],
35
+
36
+ // 各引擎API配置
37
+ engines: {
38
+ // 微软翻译(免费,无需配置)
39
+ microsoft: {
40
+ enabled: true
41
+ },
42
+
43
+ // Google翻译(免费,无需配置)
44
+ google: {
45
+ enabled: true
46
+ },
47
+
48
+ // 百度翻译(需要API密钥)
49
+ baidu: {
50
+ enabled: false,
51
+ appId: "", // 百度翻译API App ID
52
+ appKey: "" // 百度翻译API App Key
53
+ },
54
+
55
+ // 阿里云翻译(需要API密钥)
56
+ ali: {
57
+ enabled: false,
58
+ accessKeyId: "", // 阿里云AccessKey ID
59
+ accessKeySecret: "" // 阿里云AccessKey Secret
60
+ },
61
+
62
+ // 有道翻译(需要API密钥)
63
+ youdao: {
64
+ enabled: false,
65
+ appId: "", // 有道翻译API App ID
66
+ appKey: "" // 有道翻译API App Key
67
+ },
68
+
69
+ // DeepL翻译(需要API密钥)
70
+ deepl: {
71
+ enabled: false,
72
+ apiKey: "" // DeepL API Key
73
+ },
74
+
75
+ // OpenAI翻译(需要API密钥)
76
+ openai: {
77
+ enabled: false,
78
+ apiKey: "", // OpenAI API Key
79
+ model: "gpt-3.5-turbo", // 使用的模型
80
+ baseUrl: "https://api.openai.com/v1" // API基础URL
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
package/README.md CHANGED
@@ -1,220 +1,237 @@
1
1
  # 刀豆命令行工具 (Daodou CLI)
2
2
 
3
- 一个功能强大的命令行工具,支持自动化构建和多语言管理。
3
+ 用于 Jenkins 构建触发、多语言文案维护、版本检查升级与配置管理的命令行工具。
4
4
 
5
5
  ## 安装
6
6
 
7
+ 全局安装:
8
+
7
9
  ```bash
8
10
  npm install -g daodou-command
9
11
  ```
10
12
 
11
- ## 功能特性
13
+ 本地开发:
12
14
 
13
- ### 🚀 构建功能
14
- - 自动检测Git分支
15
- - 一键触发Jenkins构建
16
- - 实时监听构建进度
15
+ ```bash
16
+ git clone <repository-url>
17
+ cd daodou-command
18
+ npm install
19
+ npm link
20
+ ```
17
21
 
18
- ### 🌐 多语言管理
19
- - 支持多语言文件管理
20
- - 多引擎翻译支持(微软、Google、百度、阿里云、有道、DeepL、OpenAI)
21
- - HTML文档翻译支持,保持标签结构
22
- - 智能引擎调度和故障转移
23
- - 灵活的引擎配置和优先级设置
22
+ ## 快速开始
24
23
 
25
- ### 🔄 自动更新
26
- - 智能版本检查和更新
27
- - 一键升级到最新版本
28
- - 支持强制更新和仅检查模式
24
+ 1. 初始化全局配置:
29
25
 
30
- ### ⚙️ 配置管理
31
- - 全局配置和项目配置支持
32
- - 交互式配置向导
33
- - 配置文件编辑和管理
26
+ ```bash
27
+ dao config init
28
+ ```
34
29
 
35
- ## 快速开始
30
+ 2. 执行常用命令:
36
31
 
37
- ### 构建项目
38
32
  ```bash
39
- # 在项目根目录下执行
40
- cd your-project
41
33
  dao build
34
+ dao lang add "hello.world" "Hello World"
35
+ dao upgrade --check
42
36
  ```
43
37
 
44
- ### 检查更新
45
- ```bash
46
- # 检查是否有新版本
47
- dao upgrade --check
38
+ 说明:
48
39
 
49
- # 更新到最新版本
50
- dao upgrade
40
+ - 当全局配置和项目配置都不存在时,首次执行 `dao build` 会自动生成默认项目配置 `./.daodourc`。
51
41
 
52
- # 强制更新
53
- dao upgrade --force
54
- ```
42
+ ## 配置说明
55
43
 
56
- ### 配置管理
57
- ```bash
58
- # 初始化全局配置
59
- dao config init
44
+ 配置来源:
60
45
 
61
- # 查看当前配置
62
- dao config show
46
+ - 全局配置:`~/.daodou/config.json`
47
+ - 项目配置:`./.daodourc`
48
+ - 合并规则:项目配置覆盖全局配置
63
49
 
64
- # 编辑配置文件
65
- dao config edit
50
+ 建议:
66
51
 
67
- # 清除配置文件
68
- dao config clear
69
- ```
52
+ - `build.jobName` 放在项目配置中(不同项目通常不同)。
53
+ - Jenkins 账号和 Token 放在全局配置中(减少重复)。
70
54
 
71
- ### 翻译引擎配置
72
- 支持7种翻译引擎,可在lang命令配置中灵活配置:
55
+ 最小配置示例(JSON5):
73
56
 
74
- ```json
57
+ ```json5
75
58
  {
76
- "lang": {
77
- "defaultLang": "en",
78
- "defaultDir": "./public/locales",
79
- "fileName": "common.json",
80
- "translation": {
81
- "defaultEngine": "microsoft",
82
- "enginePriority": ["microsoft", "google", "baidu", "ali", "youdao", "deepl", "openai"],
83
- "engines": {
84
- "microsoft": { "enabled": true },
85
- "google": { "enabled": true },
86
- "baidu": { "enabled": false, "appId": "", "appKey": "" },
87
- "ali": { "enabled": false, "accessKeyId": "", "accessKeySecret": "" },
88
- "youdao": { "enabled": false, "appId": "", "appKey": "" },
89
- "deepl": { "enabled": false, "apiKey": "" },
90
- "openai": { "enabled": false, "apiKey": "", "model": "gpt-3.5-turbo" }
91
- }
59
+ build: {
60
+ jenkinsUrl: "https://jenkins.example.com/",
61
+ jenkinsBase: "https://jenkins.example.com/job",
62
+ jenkinsToken: "your-token",
63
+ jenkinsUsername: "your-username",
64
+ jenkinsPassword: "your-password",
65
+ jobName: "your-job-name",
66
+ buildParams: {
67
+ token: "your-token",
68
+ BUILD_ENV: "test"
69
+ }
70
+ },
71
+ lang: {
72
+ defaultLang: "en",
73
+ defaultDir: "./public/locales",
74
+ fileName: "common.json",
75
+ translation: {
76
+ defaultEngine: "microsoft",
77
+ enginePriority: ["microsoft", "google", "baidu", "ali", "youdao", "deepl", "openai"]
92
78
  }
93
79
  }
94
80
  }
95
81
  ```
96
82
 
97
- **支持的翻译引擎:**
98
- - **微软翻译**: 免费,无需配置,支持HTML翻译
99
- - **Google翻译**: 免费,无需配置,支持HTML翻译
100
- - **百度翻译**: 需要App ID和App Key
101
- - **阿里云翻译**: 需要AccessKey ID和AccessKey Secret,支持HTML翻译
102
- - **有道翻译**: 需要App ID和App Key
103
- - **DeepL翻译**: 需要API Key
104
- - **OpenAI翻译**: 需要API Key和模型配置,支持HTML翻译
105
-
106
- **HTML翻译支持:**
107
- - 微软翻译:原生支持HTML格式,保持标签结构
108
- - Google翻译:支持HTML格式翻译
109
- - 阿里云翻译:支持HTML格式翻译
110
- - OpenAI翻译:智能识别HTML标签,保持结构完整
111
-
112
- ### 多语言管理
83
+ ## 命令详解
84
+
85
+ ### `dao build`
86
+
87
+ 用途:
88
+
89
+ - 读取配置并触发 Jenkins 构建。
90
+ - 默认自动检测当前 Git 分支。
91
+ - 构建后轮询 Jenkins 队列与构建状态,输出进度日志。
92
+
93
+ 常用写法:
94
+
113
95
  ```bash
114
- # 添加多语言项(自动翻译)
115
- dao lang add "hello world"
96
+ # 自动读取当前分支并构建
97
+ dao build
116
98
 
117
- # 添加多语言项(指定值)
118
- dao lang add "welcome" "欢迎"
99
+ # 指定分支构建
100
+ dao build -b feature/new-login
119
101
 
120
- # 删除多语言项
121
- dao lang remove "hello world"
102
+ # 显式传入 Jenkins 地址与任务名(推荐仍在配置文件中维护)
103
+ dao build -j https://jenkins.example.com -n web-build
122
104
  ```
123
105
 
124
- ## 配置
106
+ 参数含义:
125
107
 
126
- 首次运行会自动生成 `.daodourc` 配置文件:
108
+ - `-b, --branch <branch>`:指定构建分支;不传时自动读取当前 Git 分支。
109
+ - `-j, --jenkins-url <url>`:Jenkins 服务器地址。
110
+ - `-n, --job-name <name>`:Jenkins 任务名称。
111
+ - `-u, --username <username>`:Jenkins 用户名。
112
+ - `-t, --token <token>`:Jenkins API Token。
113
+ - `-p, --parameters <json>`:额外构建参数(JSON 字符串)。
127
114
 
128
- ```json5
129
- {
130
- build: {
131
- jenkinsUrl: 'your-jenkins-url',
132
- jenkinsBase: 'your-jenkins-base',
133
- jenkinsToken: 'your-jenkins-token',
134
- jenkinsUsername: 'your-username',
135
- jenkinsPassword: 'your-password',
136
- jobName: 'your-job-name',
115
+ 前置条件:
137
116
 
138
- buildParams: {
139
- token: 'your-jenkins-token',
140
- BUILD_ENV: 'test',
141
- version: '0.0.1'
142
- }
143
- },
144
-
145
- lang: {
146
- defaultLang: 'en',
147
- defaultDir: './public/locales',
148
- fileName: 'common.json'
149
- }
150
- }
151
- ```
117
+ - 当前目录是 Git 仓库(未传 `--branch` 时)。
118
+ - Jenkins 配置已填写且不是模板值。
119
+ - 首次构建前建议先运行 `dao config show` 检查合并配置是否正确。
120
+
121
+ ### `dao config`
122
+
123
+ 用途:
124
+
125
+ - 管理全局配置与项目配置。
126
+ - 查看“全局 / 项目 / 合并结果”三类配置视图。
127
+ - 直接执行 `dao config` 可进入交互式配置向导。
128
+
129
+ 交互模式:
152
130
 
153
- ## 命令用法
131
+ - 命令:`dao config`
132
+ - 作用:以菜单方式引导你选择 `init / show / edit / clear`,适合不记子命令时使用。
133
+
134
+ 子命令:
135
+
136
+ - `dao config init`:初始化全局配置文件 `~/.daodou/config.json`。
137
+ - `dao config show`:显示当前配置与合并结果。
138
+ - `dao config edit`:打开编辑器修改配置。
139
+ - `dao config clear`:删除指定配置(全局/项目/全部)。
140
+
141
+ 常用写法:
154
142
 
155
- ### 构建命令
156
143
  ```bash
157
- dao build # 自动检测分支并构建
158
- dao build --branch feature # 指定分支构建
159
- dao build --help # 查看帮助
144
+ dao config
145
+ dao config init
146
+ dao config show
147
+ dao config edit
148
+ dao config clear
160
149
  ```
161
150
 
162
- ### 更新命令
163
- ```bash
164
- dao upgrade # 检查并更新到最新版本
165
- dao upgrade --check # 仅检查是否有新版本
166
- dao upgrade --force # 强制更新到最新版本
167
- dao upgrade --help # 查看帮助
151
+ ### `dao lang`
152
+
153
+ 用途:
154
+
155
+ - 在多语言 JSON 文件中批量新增或删除 key。
156
+ - 新增时会以默认语言为源文,其他语言自动翻译。
157
+
158
+ 目录约定:
159
+
160
+ ```text
161
+ public/locales/{lang}/common.json
168
162
  ```
169
163
 
170
- ### 配置命令
171
- ```bash
172
- dao config # 配置管理向导
173
- dao config init # 初始化全局配置
174
- dao config show # 显示当前配置
175
- dao config edit # 编辑配置文件
176
- dao config clear # 清除配置文件
177
- dao config --help # 查看帮助
164
+ 例如:
165
+
166
+ ```text
167
+ public/locales/en/common.json
168
+ public/locales/zh/common.json
169
+ public/locales/ja/common.json
178
170
  ```
179
171
 
180
- ### 多语言命令
172
+ 子命令:
173
+
174
+ - `dao lang add <key> [value]`:添加 key。
175
+ - `dao lang remove <key>`:删除 key。
176
+
177
+ 参数含义:
178
+
179
+ - `-l, --lang <language>`:只处理指定语言(如 `en`、`zh`、`ja`)。
180
+ - `-d, --dir <directory>`:指定语言目录,默认读取 `lang.defaultDir`。
181
+
182
+ 常用写法:
183
+
181
184
  ```bash
182
- dao lang add "key" "value" # 添加多语言项
183
- dao lang remove "key" # 删除多语言项
184
- dao lang add "key" --lang zh # 只处理特定语言
185
- dao lang --help # 查看帮助
186
- ```
185
+ # 默认以 key 作为默认语言文案,并自动翻译到其他语言
186
+ dao lang add "user.profile.title"
187
187
 
188
- ## 多语言文件结构
188
+ # 手动指定默认语言文案
189
+ dao lang add "user.profile.title" "Profile"
189
190
 
190
- 工具会自动扫描 `/public/locales/[lang]/common.json` 文件:
191
+ # 只处理 zh(默认 defaultLang=en 时,会先翻译再写入 zh)
192
+ dao lang add "user.profile.title" "Profile" --lang zh
191
193
 
192
- ```
193
- public/
194
- └── locales/
195
- ├── en/
196
- │ └── common.json
197
- ├── zh/
198
- │ └── common.json
199
- └── ja/
200
- └── common.json
194
+ # 删除 key
195
+ dao lang remove "user.profile.title"
201
196
  ```
202
197
 
203
- ## 常见问题
198
+ 说明:
199
+
200
+ - `lang` 命令不会自动创建 `public/locales` 目录结构。
201
+ - 若某语言文件不存在或 key 已存在,会跳过并给出提示。
202
+ - `add` 的 `value` 按 `defaultLang` 语义处理(默认通常是 `en`)。
203
+ - 当 `--lang` 指定语言不等于 `defaultLang` 时,会“翻译后写入”目标语言文件。
204
+ - 只有目标语言等于 `defaultLang` 时,才会“直接写入”你传入的 `value`。
205
+
206
+ ### `dao upgrade`
207
+
208
+ 用途:
209
+
210
+ - 检查 npm 上的最新版本并执行升级。
211
+
212
+ 子命令参数:
204
213
 
205
- - **Jenkins配置**: 请编辑 `.daodourc` 文件,填写真实的Jenkins配置
206
- - **多语言目录**: 工具会提示目录不存在,不会自动创建
207
- - **翻译失败**: 工具会自动重试和切换代理
214
+ - `--check`:仅检查是否有新版本,不安装。
215
+ - `--force`:即使当前版本已是最新,也强制重装最新版本。
208
216
 
209
- ## 开发
217
+ 常用写法:
210
218
 
211
219
  ```bash
212
- git clone <repository-url>
213
- cd daodou-command
214
- npm install
215
- npm link
220
+ dao upgrade --check
221
+ dao upgrade
222
+ dao upgrade --force
216
223
  ```
217
224
 
218
- ---
225
+ ## 常见问题
226
+
227
+ - 提示缺少配置:先执行 `dao config init`,并补全 Jenkins 参数。
228
+ - 提示配置仍是模板值:将 `your-jenkins-*` 等占位值替换为真实值。
229
+ - 提示不是 Git 仓库:在仓库根目录执行,或显式传 `-b/--branch`。
230
+ - `lang` 扫描不到语言目录:确认 `public/locales/{lang}/common.json` 路径存在。
231
+
232
+ ## 安全说明
233
+
234
+ 配置中可能包含 Jenkins 凭据,请勿将以下文件提交到仓库:
219
235
 
220
- **刀豆团队** - 让开发更简单 🚀
236
+ - `~/.daodou/config.json`
237
+ - `./.daodourc`
package/bin/daodou.js CHANGED
@@ -10,21 +10,17 @@ const updateChecker = require('../lib/utils/update-checker');
10
10
 
11
11
  const program = new Command();
12
12
 
13
- // 异步启动后台更新检查,不阻塞主程序
14
- setImmediate(() => {
15
- updateChecker.startBackgroundCheck();
16
- });
17
-
18
- // 检查并显示更新提醒(upgrade命令除外)
13
+ // 只在实际子命令时检查更新(排除 --help、--version、upgrade)
19
14
  const args = process.argv.slice(2);
20
- const isUpgradeCommand = args[0] === 'upgrade';
15
+ const firstArg = args[0];
16
+ const isSubCommand = firstArg && !firstArg.startsWith('-') && firstArg !== 'upgrade';
21
17
 
22
- if (!isUpgradeCommand && updateChecker.shouldRemindUpdate()) {
18
+ if (isSubCommand) {
19
+ updateChecker.startBackgroundCheck();
23
20
  const reminder = updateChecker.getUpdateReminder();
24
21
  if (reminder) {
25
- console.log(chalk.yellow(reminder));
26
- console.log(); // 空行
27
- // 不标记为已提醒,允许重复提醒
22
+ console.log(reminder);
23
+ console.log('');
28
24
  }
29
25
  }
30
26
 
@@ -41,7 +37,7 @@ program
41
37
  .option('-j, --jenkins-url <url>', 'Jenkins服务器地址')
42
38
  .option('-u, --username <username>', 'Jenkins用户名')
43
39
  .option('-t, --token <token>', 'Jenkins API Token')
44
- .option('-j, --job-name <name>', 'Jenkins任务名称')
40
+ .option('-n, --job-name <name>', 'Jenkins任务名称')
45
41
  .option('-b, --branch <branch>', '指定分支名称(默认从Git自动检测)')
46
42
  .option('-p, --parameters <params>', '额外的构建参数 (JSON格式)')
47
43
  .action(async (options) => {
@@ -213,4 +209,4 @@ program.addHelpText('after', `
213
209
  `);
214
210
 
215
211
  // 解析命令行参数
216
- program.parse();
212
+ program.parse();