fe-build-cli 1.2.2 → 1.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fe-build-cli",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "前端项目打包部署 CLI 工具,支持多服务器部署、分支管理、回滚、钉钉通知、智能处理本地改动等功能",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/cli.js CHANGED
@@ -236,17 +236,6 @@ async function deployCommand(config) {
236
236
  const skipBuild = args.includes('--skip-build');
237
237
  const noPush = args.includes('--no-push');
238
238
 
239
- // 确定发布模式
240
- let deployMode = config.deployMode || 'main'; // 默认主分支发布
241
-
242
- if (useTestBranch) {
243
- deployMode = 'test';
244
- } else if (useCurrentBranch) {
245
- deployMode = 'current';
246
- } else if (useMainBranch) {
247
- deployMode = 'main';
248
- }
249
-
250
239
  // 获取目标环境(排除 deploy 命令本身)
251
240
  const argEnv = args.find(arg => arg !== 'deploy' && !arg.startsWith('--'));
252
241
  let selectedServers = [];
@@ -279,6 +268,30 @@ async function deployCommand(config) {
279
268
  }
280
269
  }
281
270
 
271
+ // 确定发布模式(根据部署环境自动选择)
272
+ let deployMode = config.deployMode || 'main'; // 默认主分支发布
273
+
274
+ // 命令行参数优先
275
+ if (useTestBranch) {
276
+ deployMode = 'test';
277
+ } else if (useCurrentBranch) {
278
+ deployMode = 'current';
279
+ } else if (useMainBranch) {
280
+ deployMode = 'main';
281
+ } else {
282
+ // 自动根据部署环境选择发布模式
283
+ // test 环境 → test 发布模式
284
+ // production 环境 → main 发布模式
285
+ const targetEnv = selectedServers[0];
286
+ if (targetEnv === 'test') {
287
+ deployMode = 'test';
288
+ console.log('\n📌 自动识别:部署到 test 环境,使用 test 发布模式');
289
+ } else if (targetEnv === 'production') {
290
+ deployMode = 'main';
291
+ console.log('\n📌 自动识别:部署到 production 环境,使用 main 发布模式');
292
+ }
293
+ }
294
+
282
295
  // 执行分支发布流程
283
296
  let branchResult = null;
284
297
  let originalBranch = getCurrentBranch(); // 记录原始分支
@@ -352,7 +365,8 @@ async function deployCommand(config) {
352
365
  buildVersion: '未完成',
353
366
  serverHost: envConfig?.sshHost || '未知',
354
367
  branch: originalBranch,
355
- error: `分支流程失败: ${branchError.message}`
368
+ error: `分支流程失败: ${branchError.message}`,
369
+ keyword: config.dingtalk.keyword || '部署'
356
370
  });
357
371
  }
358
372
 
@@ -409,7 +423,8 @@ async function deployCommand(config) {
409
423
  deployUrl: envConfig.deployUrl,
410
424
  branch: currentBranch,
411
425
  deployMode,
412
- duration: `${duration}秒`
426
+ duration: `${duration}秒`,
427
+ keyword: config.dingtalk.keyword || '部署'
413
428
  });
414
429
  }
415
430
  } catch (error) {
@@ -424,7 +439,8 @@ async function deployCommand(config) {
424
439
  buildVersion,
425
440
  serverHost: envConfig.sshHost,
426
441
  branch: currentBranch,
427
- error: error.message
442
+ error: error.message,
443
+ keyword: config.dingtalk.keyword || '部署'
428
444
  });
429
445
  }
430
446
 
@@ -511,7 +527,8 @@ async function rollbackCommand(config) {
511
527
  backupFile: backupFile || '最新备份',
512
528
  serverHost: envConfig.sshHost,
513
529
  deployUrl: envConfig.deployUrl,
514
- success: true
530
+ success: true,
531
+ keyword: config.dingtalk.keyword || '部署'
515
532
  });
516
533
  }
517
534
  } catch (error) {
@@ -526,7 +543,8 @@ async function rollbackCommand(config) {
526
543
  backupFile: backupFile || '未知',
527
544
  serverHost: envConfig.sshHost,
528
545
  deployUrl: envConfig.deployUrl,
529
- success: false
546
+ success: false,
547
+ keyword: config.dingtalk.keyword || '部署'
530
548
  });
531
549
  }
532
550
 
@@ -78,6 +78,7 @@ export default {
78
78
  */
79
79
  dingtalk: {
80
80
  webhook: 'https://oapi.dingtalk.com/robot/send?access_token=your-token', // 钉钉机器人 webhook URL
81
- enabled: true // 是否启用钉钉通知,默认 true
81
+ enabled: true, // 是否启用钉钉通知,默认 true
82
+ keyword: '部署' // 安全设置关键词(如果机器人设置了关键词,必须配置此项)
82
83
  }
83
84
  };
package/src/dingtalk.js CHANGED
@@ -44,6 +44,7 @@ export async function sendDingTalkMessage(webhookUrl, message) {
44
44
  * @param {string} options.branch - 分支名称
45
45
  * @param {string} options.deployMode - 发布模式
46
46
  * @param {string} options.duration - 部署耗时(可选)
47
+ * @param {string} options.keyword - 安全关键词(可选)
47
48
  */
48
49
  export async function sendDeploySuccessNotification(webhookUrl, options) {
49
50
  const {
@@ -53,7 +54,8 @@ export async function sendDeploySuccessNotification(webhookUrl, options) {
53
54
  deployUrl,
54
55
  branch,
55
56
  deployMode,
56
- duration
57
+ duration,
58
+ keyword = '部署'
57
59
  } = options;
58
60
 
59
61
  const now = new Date();
@@ -66,12 +68,15 @@ export async function sendDeploySuccessNotification(webhookUrl, options) {
66
68
  second: '2-digit'
67
69
  });
68
70
 
71
+ // 标题必须包含关键词,否则钉钉会拒绝
72
+ const title = `${keyword}成功 - ${environment}`;
73
+
69
74
  const message = {
70
75
  msgtype: 'markdown',
71
76
  markdown: {
72
- title: `部署成功 - ${environment}`,
77
+ title,
73
78
  text: `
74
- ## 🚀 部署成功通知
79
+ ## 🚀 ${keyword}成功通知
75
80
 
76
81
  **环境**: ${environment}
77
82
  **状态**: ✅ 成功
@@ -79,15 +84,15 @@ export async function sendDeploySuccessNotification(webhookUrl, options) {
79
84
 
80
85
  ---
81
86
 
82
- ### 部署详情
87
+ ### ${keyword}详情
83
88
 
84
89
  | 项目 | 内容 |
85
90
  |:---:|:---|
86
91
  | 构建版本 | ${buildVersion} |
87
92
  | 发布分支 | ${branch} |
88
- | 发布模式 | ${deployMode === 'main' ? '主分支发布' : '当前分支发布'} |
93
+ | 发布模式 | ${deployMode === 'main' ? '主分支发布' : deployMode === 'test' ? 'Test环境发布' : '当前分支发布'} |
89
94
  | 服务器 | ${serverHost} |
90
- ${duration ? `| 部署耗时 | ${duration} |` : ''}
95
+ ${duration ? `| ${keyword}耗时 | ${duration} |` : ''}
91
96
 
92
97
  ---
93
98
 
@@ -95,7 +100,7 @@ ${duration ? `| 部署耗时 | ${duration} |` : ''}
95
100
 
96
101
  [${deployUrl}](${deployUrl})
97
102
 
98
- > 部署完成,请及时验证功能是否正常。
103
+ > ${keyword}完成,请及时验证功能是否正常。
99
104
  `.trim()
100
105
  }
101
106
  };
@@ -112,6 +117,7 @@ ${duration ? `| 部署耗时 | ${duration} |` : ''}
112
117
  * @param {string} options.serverHost - 服务器地址
113
118
  * @param {string} options.branch - 分支名称
114
119
  * @param {string} options.error - 错误信息
120
+ * @param {string} options.keyword - 安全关键词(可选)
115
121
  */
116
122
  export async function sendDeployFailureNotification(webhookUrl, options) {
117
123
  const {
@@ -119,7 +125,8 @@ export async function sendDeployFailureNotification(webhookUrl, options) {
119
125
  buildVersion,
120
126
  serverHost,
121
127
  branch,
122
- error
128
+ error,
129
+ keyword = '部署'
123
130
  } = options;
124
131
 
125
132
  const now = new Date();
@@ -132,12 +139,15 @@ export async function sendDeployFailureNotification(webhookUrl, options) {
132
139
  second: '2-digit'
133
140
  });
134
141
 
142
+ // 标题必须包含关键词
143
+ const title = `${keyword}失败 - ${environment}`;
144
+
135
145
  const message = {
136
146
  msgtype: 'markdown',
137
147
  markdown: {
138
- title: `部署失败 - ${environment}`,
148
+ title,
139
149
  text: `
140
- ## ❌ 部署失败通知
150
+ ## ❌ ${keyword}失败通知
141
151
 
142
152
  **环境**: ${environment}
143
153
  **状态**: ❌ 失败
@@ -159,7 +169,7 @@ export async function sendDeployFailureNotification(webhookUrl, options) {
159
169
 
160
170
  ${error}
161
171
 
162
- > 请及时排查问题并重新部署。
172
+ > 请及时排查问题并重新${keyword}。
163
173
  `.trim()
164
174
  }
165
175
  };
@@ -176,6 +186,7 @@ ${error}
176
186
  * @param {string} options.serverHost - 服务器地址
177
187
  * @param {string} options.deployUrl - 部署后的访问地址
178
188
  * @param {boolean} options.success - 是否成功
189
+ * @param {string} options.keyword - 安全关键词(可选)
179
190
  */
180
191
  export async function sendRollbackNotification(webhookUrl, options) {
181
192
  const {
@@ -183,7 +194,8 @@ export async function sendRollbackNotification(webhookUrl, options) {
183
194
  backupFile,
184
195
  serverHost,
185
196
  deployUrl,
186
- success
197
+ success,
198
+ keyword = '部署'
187
199
  } = options;
188
200
 
189
201
  const now = new Date();
@@ -196,10 +208,13 @@ export async function sendRollbackNotification(webhookUrl, options) {
196
208
  second: '2-digit'
197
209
  });
198
210
 
211
+ // 标题必须包含关键词
212
+ const title = `回滚${success ? '成功' : '失败'} - ${environment}`;
213
+
199
214
  const message = {
200
215
  msgtype: 'markdown',
201
216
  markdown: {
202
- title: `回滚${success ? '成功' : '失败'} - ${environment}`,
217
+ title,
203
218
  text: `
204
219
  ## ${success ? '🔄' : '❌'} 回滚${success ? '成功' : '失败'}通知
205
220
 
@@ -222,7 +237,7 @@ ${success ? `### 访问地址
222
237
 
223
238
  [${deployUrl}](${deployUrl})` : ''}
224
239
 
225
- > ${success ? '回滚完成,请验证功能是否正常。' : '回滚失败,请手动处理。'}
240
+ > ${success ? '回滚完成,请验证功能是否正常。' : '回滚失败,请手动处理。'}(${keyword}系统)
226
241
  `.trim()
227
242
  }
228
243
  };
package/src/index.d.ts CHANGED
@@ -48,6 +48,8 @@ export interface DingtalkConfig {
48
48
  webhook: string;
49
49
  /** 是否启用钉钉通知,默认 true */
50
50
  enabled?: boolean;
51
+ /** 安全设置关键词(如果机器人设置了关键词,必须配置此项) */
52
+ keyword?: string;
51
53
  }
52
54
 
53
55
  /**