fe-build-cli 1.2.3 → 1.2.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +27 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fe-build-cli",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
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,33 @@ async function deployCommand(config) {
279
268
  }
280
269
  }
281
270
 
271
+ // 确定发布模式
272
+ // 优先级:命令行参数 > 配置文件 deployMode > 自动识别
273
+ let deployMode = 'main'; // 默认值
274
+
275
+ // 1. 命令行参数优先
276
+ if (useTestBranch) {
277
+ deployMode = 'test';
278
+ } else if (useCurrentBranch) {
279
+ deployMode = 'current';
280
+ } else if (useMainBranch) {
281
+ deployMode = 'main';
282
+ } else if (config.deployMode) {
283
+ // 2. 使用配置文件的 deployMode
284
+ deployMode = config.deployMode;
285
+ console.log(`\n📌 使用配置文件发布模式: ${deployMode}`);
286
+ } else {
287
+ // 3. 自动根据部署环境选择发布模式(仅当配置文件未设置时)
288
+ const targetEnv = selectedServers[0];
289
+ if (targetEnv === 'test') {
290
+ deployMode = 'test';
291
+ console.log('\n📌 自动识别:部署到 test 环境,使用 test 发布模式');
292
+ } else if (targetEnv === 'production') {
293
+ deployMode = 'main';
294
+ console.log('\n📌 自动识别:部署到 production 环境,使用 main 发布模式');
295
+ }
296
+ }
297
+
282
298
  // 执行分支发布流程
283
299
  let branchResult = null;
284
300
  let originalBranch = getCurrentBranch(); // 记录原始分支