@infly/libs 2.2.15 → 2.2.16
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/README.md +3 -1
- package/build/build-dist/build-mode.js +26 -0
- package/build/build-dist/config.js +18 -0
- package/build/build-dist/index.js +7 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,7 +135,9 @@ infly-libs release:docker --local --health-check --health-timeout=60
|
|
|
135
135
|
|
|
136
136
|
`checks` 中的名称必须对应应用已有的 pnpm script;任一检查、覆盖率文件验证、Sonar Quality Gate 或镜像健康门禁失败,命令都会退出且不会推送镜像。`sonar` 默认为 `true`;设为 `false` 时由 CI 单独负责扫描和 Quality Gate。本地启用 Sonar 时必须通过当前进程环境或应用根目录下被 Git 忽略的 `.env.production.local` 提供 `SONAR_TOKEN`,并确保 `sonar-scanner` CLI 可执行;当前进程环境变量的优先级更高。`release:docker` 会拒绝含未提交文件的应用工作树,固定使用完整 40 位应用 commit 作为镜像标签及 OCI revision/version;普通 `build:docker` 未显式传版本时同样使用完整 commit。应用差异保留在应用配置,通用编排由 `infly-libs` 维护。
|
|
137
137
|
|
|
138
|
-
`infly-libs beforeBuild`
|
|
138
|
+
`infly-libs beforeBuild` 在应用未配置 `infly.buildConfigs.gitAutoPushReposBranchMap` 时,默认使用 `{ "master": "master", "develop": "develop" }`;应用显式配置的映射(包括空对象)会整体覆盖默认值,不合并分支。默认映射不会隐式启用产物仓推送;显式映射仍沿用原有启用行为,`gitAutoPushRepos: false` 始终优先。当前应用、可选产物仓、历史独立 packages 仓以及 monorepo 根仓更新均只允许 fast-forward,分支发生分叉时立即停止,不自动创建 merge commit。只需要更新应用和根仓源码的项目应显式设置 `gitAuto: false` 与 `gitAutoPushRepos: false`,避免进入产物自动提交或产物仓分支处理。兄弟应用依赖会从 `vue.config.js`、`vite.config.js/mjs/ts` 和 `next.config.js/mjs/ts` 的相对路径 alias 中静态识别,不执行配置文件;识别到的兄弟仓同样要求工作树干净并以 fast-forward-only 更新。
|
|
139
|
+
|
|
140
|
+
`beforeBuild` 优先使用当前调用的显式 `--mode`:测试发布推荐 `infly-libs beforeBuild --mode staging`,正式发布推荐 `infly-libs beforeBuild --mode production`。未传参数时,按构建/发布脚本名的冒号分段识别 `test/stage/staging` 或 `pro/prod/production`,兼容现有 `build:stage`、`build:prod` 和 `release:*:test:docker`、`release:prod:docker`;不再从整条脚本的其他命令中推测环境。测试模式沿用现有映射选择测试分支,正式模式选择 `master`;环境未知或命令名同时包含两种环境字段时保留原有校验提示,Docker 发布不统一绕过确认。显式未知模式不会回退到命令名识别。
|
|
139
141
|
|
|
140
142
|
受控紧急构建可使用 `--emergency` 跳过 `checks`、覆盖率文件校验和 Sonar,但必须提供 8~200 个字符且无控制字符的 `--emergency-reason`,并同时启用 `--standalone --commit-only --health-check`。紧急模式仍执行工作树干净检查、commit/revision 解析、镜像构建、健康检查和推送;缺少任一保护参数会在调用 Docker 前失败。
|
|
141
143
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const modes = new Map([
|
|
2
|
+
["test", "stage"],
|
|
3
|
+
["stage", "stage"],
|
|
4
|
+
["staging", "stage"],
|
|
5
|
+
["pro", "prod"],
|
|
6
|
+
["prod", "prod"],
|
|
7
|
+
["production", "prod"],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
function resolveBuildMode(modeArg, lifecycleEvent = "") {
|
|
11
|
+
// 显式环境优先,未知参数不再通过命令名猜测环境。
|
|
12
|
+
if (modeArg) {
|
|
13
|
+
return modes.get(modeArg) || "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const fields = lifecycleEvent.split(":");
|
|
17
|
+
if (!fields.includes("build") && !fields.includes("release")) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const inferredModes = new Set(fields.map((field) => modes.get(field)).filter(Boolean));
|
|
22
|
+
// 命令名同时包含测试和正式环境字段时,交给原有校验提示处理。
|
|
23
|
+
return inferredModes.size === 1 ? [...inferredModes][0] : "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = { resolveBuildMode };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function applyBuildConfigDefaults(config) {
|
|
2
|
+
const buildConfigs = config.buildConfigs || {};
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
...config,
|
|
6
|
+
buildConfigs: {
|
|
7
|
+
gitAutoPushReposBranchMap: { master: "master", develop: "develop" },
|
|
8
|
+
...buildConfigs,
|
|
9
|
+
// 默认映射只声明可构建分支;不能因此隐式启用产物仓推送。
|
|
10
|
+
gitAutoPushRepos:
|
|
11
|
+
buildConfigs.gitAutoPushRepos === undefined
|
|
12
|
+
? buildConfigs.gitAutoPushReposBranchMap || false
|
|
13
|
+
: buildConfigs.gitAutoPushRepos,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = { applyBuildConfigDefaults };
|
|
@@ -24,6 +24,8 @@ const { init: previewInit } = require("../../adapters/vue2/project-preview.js");
|
|
|
24
24
|
const { postVersionFileAndMsg } = require("../build-utils/webhook-single.js");
|
|
25
25
|
const { scriptWrite, targetProjectFileResolve, currentProjectFileResolve } = require("../project-files.js");
|
|
26
26
|
const { shouldManageBuildScripts } = require("./script-management.js");
|
|
27
|
+
const { applyBuildConfigDefaults } = require("./config.js");
|
|
28
|
+
const { resolveBuildMode } = require("./build-mode.js");
|
|
27
29
|
const {
|
|
28
30
|
autoBranchProcess,
|
|
29
31
|
autoGitProcess,
|
|
@@ -162,25 +164,7 @@ function getNextStandaloneServerPath(distPath) {
|
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
function getBuildMode() {
|
|
165
|
-
|
|
166
|
-
const lifecycleText = [process.env.npm_lifecycle_event, process.env.npm_lifecycle_script, ...process.argv]
|
|
167
|
-
.filter(Boolean)
|
|
168
|
-
.join(" ");
|
|
169
|
-
|
|
170
|
-
if (modeArg === "staging" || lifecycleText.includes("build:stage") || lifecycleText.includes("--mode staging")) {
|
|
171
|
-
return "stage";
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
modeArg === "production" ||
|
|
176
|
-
modeArg === "prod" ||
|
|
177
|
-
lifecycleText.includes("build:prod") ||
|
|
178
|
-
lifecycleText.includes("build:pro")
|
|
179
|
-
) {
|
|
180
|
-
return "prod";
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return "";
|
|
167
|
+
return resolveBuildMode(getArgValue("--mode"), process.env.npm_lifecycle_event);
|
|
184
168
|
}
|
|
185
169
|
|
|
186
170
|
function getStageBranch(branchMap = {}, branch = currentBranch) {
|
|
@@ -336,6 +320,8 @@ function normalizeBuildConfig(config, packageKey, branch, title) {
|
|
|
336
320
|
normalizedConfig = normalizedConfig[packageKey];
|
|
337
321
|
}
|
|
338
322
|
|
|
323
|
+
normalizedConfig = applyBuildConfigDefaults(normalizedConfig);
|
|
324
|
+
|
|
339
325
|
// 自动启用 gitAutoPushRepos
|
|
340
326
|
if (!normalizedConfig.gitAutoPushRepos && normalizedConfig.gitAutoPushReposBranchMap) {
|
|
341
327
|
normalizedConfig.gitAutoPushRepos = true;
|
|
@@ -416,9 +402,8 @@ async function validateConfig(buildConfig, targetBranch = currentBranch) {
|
|
|
416
402
|
}
|
|
417
403
|
|
|
418
404
|
const buildMode = getBuildMode();
|
|
419
|
-
const
|
|
420
|
-
const
|
|
421
|
-
const isStageBuild = buildMode === "stage" || lifecycleEvent.includes("stage");
|
|
405
|
+
const isProdBuild = buildMode === "prod";
|
|
406
|
+
const isStageBuild = buildMode === "stage";
|
|
422
407
|
|
|
423
408
|
if (targetBranch === "master" && !isProdBuild) {
|
|
424
409
|
console.error(global.logColor.error, `❌ 目标分支为 master 分支,请使用正式环境构建命令进行构建`);
|