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 +1 -1
- package/src/cli.js +34 -16
- package/src/config-template.js +2 -1
- package/src/dingtalk.js +29 -14
- package/src/index.d.ts +2 -0
package/package.json
CHANGED
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
|
|
package/src/config-template.js
CHANGED
|
@@ -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
|
|
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 ? `|
|
|
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
|
|
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
|
|
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
|
};
|