@infly/libs 2.6.0 → 2.7.1
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 +21 -1
- package/adapters/vue2/project-preview.js +9 -16
- package/adapters/webpack/auto-export.js +53 -52
- package/bin/cli.js +3 -2
- package/build/build-dist/index.js +52 -67
- package/build/build-utils/command.js +58 -57
- package/build/build-utils/deps.js +28 -28
- package/build/build-utils/git.js +246 -254
- package/build/build-utils/preview.js +79 -78
- package/build/build-utils/webhook.js +135 -135
- package/build/docker/deployment/health-check.sh +5 -1
- package/build/docker/deployment/release.sh +25 -2
- package/build/docker/docker-build-push.js +20 -21
- package/build/docker/release-docker.js +5 -4
- package/build/docker/release-paths.js +30 -30
- package/build/docker/release-validation.js +51 -7
- package/build/docker/target-image.js +44 -6
- package/build/docker/target-release.js +540 -527
- package/build/project-files.js +47 -47
- package/cli/progress.js +4 -11
- package/cli/terminal-style.js +40 -0
- package/core/async/concurrency.js +29 -29
- package/package.json +3 -3
- package/script/git-automation/check-packages.js +5 -12
- package/script/git-automation/git-clone.js +6 -5
- package/script/git-automation/git-configure.js +3 -3
- package/script/git-automation/git-submodule.js +3 -2
- package/script/git-automation/git-utils.js +59 -59
- package/script/git-automation/index.js +862 -828
- package/script/git-automation/submodule-utils.js +16 -16
- package/workspace/config.js +144 -144
package/README.md
CHANGED
|
@@ -147,6 +147,8 @@ infly-libs release:docker --local --health-check --health-timeout=60
|
|
|
147
147
|
|
|
148
148
|
`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 更新。
|
|
149
149
|
|
|
150
|
+
`infly-libs afterBuild` 按产物仓目标分支和输出目录查找上次构建的源码提交,摘要会过滤自动版本提交。根仓批量发布传入 Vite 的实际输出目录和构建前的源码提交,子模块单独发布使用本项目的构建配置和源码提交。产物提交只包含当前输出目录,并用 `Infly-Source-Commit` 记录本次源码提交号。旧产物提交在只涉及当前目录、完整提交说明能在源码历史中唯一匹配时可作为起点。起点无法确认时,通知会说明并附上可识别的提交摘要。
|
|
151
|
+
|
|
150
152
|
`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 发布不统一绕过确认。显式未知模式不会回退到命令名识别。
|
|
151
153
|
|
|
152
154
|
受控紧急构建可使用 `--emergency` 跳过 `checks`、覆盖率文件校验和 Sonar,但必须提供 8~200 个字符且无控制字符的 `--emergency-reason`,并同时启用 `--standalone --commit-only --health-check`。紧急模式仍执行工作树干净检查、commit/revision 解析、镜像构建、健康检查和推送;缺少任一保护参数会在调用 Docker 前失败。
|
|
@@ -467,7 +469,7 @@ Jenkins 地址可在 Docker 配置顶层或单个 target 设置 `cicdUrl`。解
|
|
|
467
469
|
|
|
468
470
|
`release:docker` 不是强制构建入口。独立源码仓可以直接使用 Dockerfile 或 Compose 构建,但若镜像要进入这里生成的部署流程,必须自行保证仓库名、不可变完整 40 位提交标签以及 `org.opencontainers.image.revision`、`org.opencontainers.image.version`、`com.infly.platform` 标签与目标配置一致;公共发布入口只是自动化这些校验和映射。部署侧仅为既有镜像保留旧 12 位标签兼容,新构建不再生成 12 位标签。
|
|
469
471
|
|
|
470
|
-
远端发布持锁后读取全部组件镜像基线,保存 .release-history;配置 `runtimeEnv` 时先从服务器总环境文件按白名单原子生成应用专用文件,再仅更新传入组件的服务(up -d --no-deps
|
|
472
|
+
远端发布持锁后读取全部组件镜像基线,保存 .release-history;配置 `runtimeEnv` 时先从服务器总环境文件按白名单原子生成应用专用文件,再仅更新传入组件的服务(up -d --no-deps)。同目录中的发布锁记录持有者 PID。若遇到遗留锁,发布停止并报告 PID 是否可访问,开发人员核对正在运行的发布与恢复状态后处理。首次接入可由发布入口显式传入 `--initialize-baseline`:仅在 `deploy.env` 不存在时,从配置声明的运行中服务读取唯一且仓库匹配的 RepoDigest,保存权限受限的 `.onboarding-backup` 接入证据并原子创建基线;已有基线时拒绝覆盖,未显式初始化时仍要求基线预先存在。失败恢复镜像环境文件、应用专用环境文件及选中服务;回滚验证失败明确报错。不创建总环境文件,不创建/修改数据库,不更新未配置的基础设施。服务器不需要 npm/Node,仍需 Bash、Docker Compose 和 curl。
|
|
471
473
|
|
|
472
474
|
### 部署仓拥有镜像打包规则
|
|
473
475
|
|
|
@@ -482,3 +484,21 @@ source 构建组件可配置 `monorepoContextFiles: [tooling/install.cjs]`,逐
|
|
|
482
484
|
`source.standalone: true` 可显式使用独立源码上下文,即使业务仓位于 monorepo 中也不带根公共包;适用于已有独立安装契约的紧急构建。target 的 `recordConfigurationRevision: true` 则让未注入文件的外部源码组件也记录并复核部署仓提交。两者均为可选布尔值,默认保持原有行为。
|
|
483
485
|
|
|
484
486
|
组件可声明 `health: {timeoutSeconds: 60, addHost: api:127.0.0.1}`,复用运行镜像的 HEALTHCHECK,失败不推送本组任何镜像。普通 check 仍用于语法或文件检查;不要对后端启动真实业务进程作本地镜像探针。
|
|
487
|
+
|
|
488
|
+
组件可按需声明下列 Docker 构建输入。dry-run 只给出配置计划,实际执行前才从进程环境解析仓库和密钥文件路径。
|
|
489
|
+
|
|
490
|
+
```yaml
|
|
491
|
+
repositoryEnv: IMAGE_REPOSITORY
|
|
492
|
+
buildSecrets:
|
|
493
|
+
- id: app_env
|
|
494
|
+
fileEnv: APP_ENV_FILE
|
|
495
|
+
defaultFile: .env.app.local
|
|
496
|
+
noCacheFilter: [frontend-build]
|
|
497
|
+
buildTimestampArg: BUILD_TIMESTAMP
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
- `repositoryEnv` 可替代固定的 `repository`,用于让构建执行者选择镜像仓库。
|
|
501
|
+
- `buildSecrets` 声明 BuildKit 密钥 ID 和保存文件路径的环境变量名。可用 `defaultFile` 声明相对部署仓的本机文件路径,未设置环境变量时使用该文件。密钥文件应放在构建上下文之外,并保持 Git 忽略,由 Dockerfile 使用 `RUN --mount=type=secret` 消费。文件路径和内容均不写入发布记录。
|
|
502
|
+
- `noCacheFilter` 按阶段传给 Buildx。依赖密钥内容改变的编译阶段应列入此处,仍可复用其他构建阶段缓存。
|
|
503
|
+
- `buildTimestampArg` 通过指定的构建参数提供一份 `+08:00` 时间戳。镜像检查可声明 `check.network: none` 进行无网络验证。
|
|
504
|
+
- `--output <路径>` 在成功后写出目标及组件构建结果。推送模式的结果包含已回拉校验的 digest 和 image ID。dry-run 不写文件。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
1
2
|
const fs = require("fs");
|
|
2
3
|
const path = require("path");
|
|
3
4
|
const net = require("net");
|
|
@@ -24,14 +25,6 @@ function getBuildContext() {
|
|
|
24
25
|
|
|
25
26
|
const buildContext = getBuildContext();
|
|
26
27
|
|
|
27
|
-
global.logColor = global.logColor || {
|
|
28
|
-
success: "\n\x1b[32m%s\x1b[0m",
|
|
29
|
-
error: "\n\x1b[31m%s\x1b[0m",
|
|
30
|
-
warning: "\n\x1b[33m%s\x1b[0m",
|
|
31
|
-
link: "\x1b[34m%s\x1b[0m",
|
|
32
|
-
info: "\n\x1b[36m%s\x1b[0m"
|
|
33
|
-
};
|
|
34
|
-
|
|
35
28
|
const DEFAULT_CONFIG = {
|
|
36
29
|
port: 9001,
|
|
37
30
|
publicPath: "/",
|
|
@@ -69,7 +62,7 @@ async function findAvailablePort(startPort, maxTries = 10) {
|
|
|
69
62
|
|
|
70
63
|
if (available) {
|
|
71
64
|
if (i > 0) {
|
|
72
|
-
|
|
65
|
+
logTerminal("warning", `端口 ${startPort} 被占用,使用端口 ${port}`);
|
|
73
66
|
}
|
|
74
67
|
return port;
|
|
75
68
|
}
|
|
@@ -114,25 +107,25 @@ async function init(skipBuild = false) {
|
|
|
114
107
|
const targetSuffix = buildContext.targetLabel ? ` (${buildContext.targetLabel})` : '';
|
|
115
108
|
|
|
116
109
|
if (buildContext.batchPreview === true || process.env.INFLY_BATCH_PREVIEW === "1") {
|
|
117
|
-
|
|
110
|
+
logTerminal("info", `${projectPackage.name || path.basename(projectRoot)}${targetSuffix}: ${previewUrl}`);
|
|
118
111
|
return;
|
|
119
112
|
}
|
|
120
113
|
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
logTerminal("success", `项目构建预览已启动,按 Ctrl+C 退出`);
|
|
115
|
+
logTerminal("info", previewUrl);
|
|
123
116
|
});
|
|
124
117
|
|
|
125
118
|
server.on("error", (error) => {
|
|
126
119
|
if (error.code === "EADDRINUSE") {
|
|
127
|
-
|
|
120
|
+
logTerminal("error", `端口 ${listenPort} 仍然被占用`);
|
|
128
121
|
} else {
|
|
129
|
-
|
|
122
|
+
logTerminal("error", `服务器启动失败:${error.message}`);
|
|
130
123
|
}
|
|
131
124
|
});
|
|
132
125
|
|
|
133
126
|
return server;
|
|
134
127
|
} catch (error) {
|
|
135
|
-
|
|
128
|
+
logTerminal("error", `预览项目失败:${error.message}`);
|
|
136
129
|
throw error;
|
|
137
130
|
}
|
|
138
131
|
}
|
|
@@ -141,7 +134,7 @@ function buildProject() {
|
|
|
141
134
|
try {
|
|
142
135
|
execSync(`vue-cli-service build ${args}`, { stdio: "inherit" });
|
|
143
136
|
} catch (err) {
|
|
144
|
-
|
|
137
|
+
logTerminal("error", "构建失败:", err.message);
|
|
145
138
|
process.exit(1);
|
|
146
139
|
}
|
|
147
140
|
}
|
|
@@ -1,56 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Webpack require.context 适配器。
|
|
3
|
-
* 自动导出目录下所有文件
|
|
4
|
-
* @param {Function} requireContext - require.context 返回的函数
|
|
5
|
-
* @returns {Object} 导出对象,key 为文件名(不含扩展名),value 为模块内容
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* // 在 components/Dialog/index.js 中使用
|
|
3
|
+
* 自动导出目录下所有文件
|
|
4
|
+
* @param {Function} requireContext - require.context 返回的函数
|
|
5
|
+
* @returns {Object} 导出对象,key 为文件名(不含扩展名),value 为模块内容
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // 在 components/Dialog/index.js 中使用
|
|
9
9
|
* import { autoExportFiles } from '@infly/libs/adapters/webpack/auto-export';
|
|
10
|
-
* const components = autoExportFiles(require.context('./', false, /\.vue$/));
|
|
11
|
-
* Object.keys(components).forEach(name => {
|
|
12
|
-
* module.exports[name] = components[name];
|
|
13
|
-
* });
|
|
14
|
-
*
|
|
15
|
-
* // 或者直接一行
|
|
16
|
-
* Object.assign(module.exports, autoExportFiles(require.context('./', false, /\.vue$/)));
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
.replace(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
* @param {
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
10
|
+
* const components = autoExportFiles(require.context('./', false, /\.vue$/));
|
|
11
|
+
* Object.keys(components).forEach(name => {
|
|
12
|
+
* module.exports[name] = components[name];
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // 或者直接一行
|
|
16
|
+
* Object.assign(module.exports, autoExportFiles(require.context('./', false, /\.vue$/)));
|
|
17
|
+
*/
|
|
18
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
19
|
+
function autoExportFiles(requireContext) {
|
|
20
|
+
if (!requireContext || typeof requireContext !== 'function') {
|
|
21
|
+
logTerminal("error", 'autoExportFiles: requireContext 必须是 require.context 返回的函数');
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const exports = {};
|
|
26
|
+
|
|
27
|
+
requireContext.keys().forEach(fileName => {
|
|
28
|
+
// 跳过 index 文件自身
|
|
29
|
+
if (fileName.includes('index')) return;
|
|
30
|
+
|
|
31
|
+
const componentConfig = requireContext(fileName);
|
|
32
|
+
const componentName = fileName
|
|
33
|
+
.replace(/^\.\//, '') // 移除 './'
|
|
34
|
+
.replace(/\.\w+$/, ''); // 移除扩展名
|
|
35
|
+
|
|
36
|
+
exports[componentName] = componentConfig.default || componentConfig;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return exports;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 简化版:直接挂载到 module.exports
|
|
44
|
+
* @param {Function} requireContext - require.context 返回的函数
|
|
45
|
+
* @param {Object} targetExports - 目标导出对象(通常是 module.exports)
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // 在 components/Dialog/index.js 中使用
|
|
48
49
|
* import { autoExportToModule } from '@infly/libs/adapters/webpack/auto-export';
|
|
49
|
-
* autoExportToModule(require.context('./', false, /\.vue$/), module.exports);
|
|
50
|
-
*/
|
|
51
|
-
function autoExportToModule(requireContext, targetExports) {
|
|
52
|
-
const files = autoExportFiles(requireContext);
|
|
53
|
-
Object.assign(targetExports, files);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export { autoExportFiles, autoExportToModule };
|
|
50
|
+
* autoExportToModule(require.context('./', false, /\.vue$/), module.exports);
|
|
51
|
+
*/
|
|
52
|
+
function autoExportToModule(requireContext, targetExports) {
|
|
53
|
+
const files = autoExportFiles(requireContext);
|
|
54
|
+
Object.assign(targetExports, files);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { autoExportFiles, autoExportToModule };
|
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
const { logTerminal } = require("../cli/terminal-style");
|
|
3
4
|
const fs = require("node:fs");
|
|
4
5
|
const path = require("node:path");
|
|
5
6
|
|
|
@@ -230,7 +231,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
230
231
|
if (command && commandMap[command]) {
|
|
231
232
|
await commandMap[command]();
|
|
232
233
|
} else {
|
|
233
|
-
|
|
234
|
+
logTerminal("error", `未知命令: ${command || "未提供命令"}`);
|
|
234
235
|
console.log(`可用命令: ${Object.keys(commandMap).join(", ")}`);
|
|
235
236
|
process.exitCode = 1;
|
|
236
237
|
}
|
|
@@ -238,7 +239,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
238
239
|
|
|
239
240
|
if (require.main === module) {
|
|
240
241
|
main().catch((error) => {
|
|
241
|
-
|
|
242
|
+
logTerminal("error", "执行失败:", error.message || error);
|
|
242
243
|
process.exitCode = 1;
|
|
243
244
|
});
|
|
244
245
|
}
|
|
@@ -4,25 +4,19 @@
|
|
|
4
4
|
* 工具实现根据配置自动切换分支,构建到配置的对应文件夹路径,并且执行自动提交推送,也可执行自动压缩提交到当前项目
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
7
8
|
const path = require("path");
|
|
8
9
|
const fs = require("fs");
|
|
9
10
|
const readline = require("readline");
|
|
10
11
|
|
|
11
12
|
const { exec } = require("child_process");
|
|
12
13
|
|
|
13
|
-
global.logColor = {
|
|
14
|
-
success: "\n\x1b[32m%s\x1b[0m",
|
|
15
|
-
error: "\n\x1b[31m%s\x1b[0m",
|
|
16
|
-
warning: "\n\x1b[33m%s\x1b[0m",
|
|
17
|
-
link: "\x1b[34m%s\x1b[0m",
|
|
18
|
-
info: "\n\x1b[36m%s\x1b[0m"
|
|
19
|
-
};
|
|
20
|
-
|
|
21
14
|
const { zipSync } = require("./zip.js");
|
|
22
15
|
const { buildList } = require("../../script");
|
|
23
16
|
const { init: previewInit } = require("../../adapters/vue2/project-preview.js");
|
|
24
17
|
const { postVersionFileAndMsg } = require("../build-utils/webhook-single.js");
|
|
25
18
|
const { resolveWebhookUrl } = require("../release-result");
|
|
19
|
+
const { parseBuildContext } = require("../build-utils/env");
|
|
26
20
|
const { scriptWrite, targetProjectFileResolve, currentProjectFileResolve } = require("../project-files.js");
|
|
27
21
|
const { shouldManageBuildScripts } = require("./script-management.js");
|
|
28
22
|
const { applyBuildConfigDefaults } = require("./config.js");
|
|
@@ -50,6 +44,7 @@ const npmPackageConfigKey = "infly";
|
|
|
50
44
|
const currentBranch = getCurrentBranch();
|
|
51
45
|
|
|
52
46
|
const projectRoot = process.cwd();
|
|
47
|
+
const buildContext = parseBuildContext();
|
|
53
48
|
// 构建配置可以位于主仓中的子目录(例如合并后的 level/)。配置、产物仍以
|
|
54
49
|
// projectRoot 为基准,只有 Git 检查与分支更新定位到实际工作树根目录。
|
|
55
50
|
const projectGitRoot = resolveGitWorktreeRoot(projectRoot);
|
|
@@ -84,7 +79,7 @@ const isPkg = versionFileName === "package.json";
|
|
|
84
79
|
|
|
85
80
|
const targetProjectVueConfig = isExistVueConfigFile ? require(targetProjectVueConfigPath) : {};
|
|
86
81
|
const { outputDir: vueOutputDir, configureWebpack } = targetProjectVueConfig || {};
|
|
87
|
-
|
|
82
|
+
const batchOutputDir = buildContext.targetOutputDir;
|
|
88
83
|
|
|
89
84
|
const { updateDevText = "测试环境" } = { master: { updateDevText: "正式环境" } }[currentBranch] || {}; // 更新环境和处理分支
|
|
90
85
|
|
|
@@ -110,29 +105,15 @@ const {
|
|
|
110
105
|
enableClipboard, // 启用粘贴板
|
|
111
106
|
disableUpdateVersionEnv // 禁止更新版本信息环境
|
|
112
107
|
} = buildConfigs || {};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (targetProjectOutputDir && !path.isAbsolute(targetProjectOutputDir)) {
|
|
118
|
-
targetProjectOutputDir = path.resolve(projectRoot, targetProjectOutputDir);
|
|
119
|
-
}
|
|
120
|
-
const buildFoldName = zipBuildFoldName || targetProjectOutputDir || "dist";
|
|
108
|
+
const configuredOutputDir = vueOutputDir || outputPath;
|
|
109
|
+
const resolvedOutputDir = configuredOutputDir && path.resolve(projectRoot, configuredOutputDir);
|
|
110
|
+
const targetProjectOutputDir = batchOutputDir ? path.resolve(projectRoot, batchOutputDir) : resolvedOutputDir;
|
|
111
|
+
const buildFoldName = zipBuildFoldName || resolvedOutputDir || "dist";
|
|
121
112
|
const { mainVersion: verMainVersion, baseName, versionList = [], links } = versionConfig || {};
|
|
122
113
|
const mainVersion = verMainVersion || major; // 主版本号
|
|
123
114
|
const [lastestVersionItem] = versionList || [];
|
|
124
115
|
const { lastVersion = projectVersion || "1.0.0" } = lastestVersionItem || {};
|
|
125
116
|
|
|
126
|
-
function getBuildContext() {
|
|
127
|
-
try {
|
|
128
|
-
return JSON.parse(process.env.INFLY_BUILD_CONTEXT || "{}");
|
|
129
|
-
} catch {
|
|
130
|
-
return {};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const buildContext = getBuildContext();
|
|
135
|
-
|
|
136
117
|
function hasArg(name) {
|
|
137
118
|
return process.argv.includes(name);
|
|
138
119
|
}
|
|
@@ -202,6 +183,11 @@ async function init() {
|
|
|
202
183
|
try {
|
|
203
184
|
// validateConfig(buildConfig);
|
|
204
185
|
validateFileExists(configPath, versionFileName);
|
|
186
|
+
const gitInfo = getLatestCommitInfo(projectRoot, buildContext.sourceCommit);
|
|
187
|
+
const { branch, commitMsg, fullHash } = gitInfo;
|
|
188
|
+
if (buildContext.sourceCommit && fullHash !== buildContext.sourceCommit) {
|
|
189
|
+
throw new Error("无法读取本次批量构建的源码提交 " + buildContext.sourceCommit);
|
|
190
|
+
}
|
|
205
191
|
|
|
206
192
|
// 处理版本信息
|
|
207
193
|
const zipFiles = handleZipFiles(`-${buildFoldName}-v`);
|
|
@@ -215,9 +201,11 @@ async function init() {
|
|
|
215
201
|
const baseFileName = `${tempPlatformName}-${buildFoldName}-${baseName}`;
|
|
216
202
|
const newVersion = isMaster ? incrementVersion(lastVersion, mainVersion) : lastVersion; // 非正式环境构建不更新版本信息
|
|
217
203
|
const newFileName = baseFileName.replace("{version}", newVersion).replace("{timestamp}", timestamp);
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
204
|
+
const updateText = getBuildUpdateText(gitAutoCommitText, projectRoot, undefined, {
|
|
205
|
+
sourceCommit: fullHash,
|
|
206
|
+
targetOutputDir: gitAutoPushRepos ? targetProjectOutputDir : undefined,
|
|
207
|
+
targetBranch: gitAutoPushReposBranchMap?.[branch]
|
|
208
|
+
}) || commitMsg;
|
|
221
209
|
let tempLink = typeof links === "object" ? links[branch] : links || "";
|
|
222
210
|
if (typeof tempLink === "object") {
|
|
223
211
|
tempLink = tempLink[process.env.VUE_APP_PLATFORM] || tempLink["DEFAULT"] || JSON.stringify(tempLink);
|
|
@@ -237,7 +225,7 @@ async function init() {
|
|
|
237
225
|
// 处理文件路径
|
|
238
226
|
const outputDir = path.resolve(projectRoot, "./", outputPath);
|
|
239
227
|
const outputPathFull = path.join(outputDir, newFileName);
|
|
240
|
-
const distPath = gitAutoPushRepos ? targetProjectOutputDir : path.resolve(projectRoot, "./" + buildFoldName);
|
|
228
|
+
const distPath = gitAutoPushRepos || batchOutputDir ? targetProjectOutputDir : path.resolve(projectRoot, "./" + buildFoldName);
|
|
241
229
|
// Next.js standalone 项目检查 server.js,Vue/SPA 项目检查 index.html
|
|
242
230
|
const validatePath = hasNextConfig ? getNextStandaloneServerPath(distPath) : path.join(distPath, "index.html");
|
|
243
231
|
|
|
@@ -300,7 +288,7 @@ async function init() {
|
|
|
300
288
|
await previewInit(true);
|
|
301
289
|
}
|
|
302
290
|
} catch (error) {
|
|
303
|
-
|
|
291
|
+
logTerminal("error", `自动构建脚本执行出错, 错误信息:\n${error}`);
|
|
304
292
|
process.exit(1);
|
|
305
293
|
}
|
|
306
294
|
}
|
|
@@ -380,23 +368,21 @@ function askUserConfirmation(message, defaultYes = false) {
|
|
|
380
368
|
*/
|
|
381
369
|
async function validateConfig(buildConfig, targetBranch = currentBranch) {
|
|
382
370
|
if (!buildConfig) {
|
|
383
|
-
|
|
371
|
+
logTerminal("error", `ZIP压缩已禁用,版本控制文件${versionFileName}配置错误`);
|
|
384
372
|
process.exit(1);
|
|
385
373
|
}
|
|
386
374
|
|
|
387
375
|
if (buildConfig?.buildConfigs?.enabled === false) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
`⚠️ ZIP压缩已禁用,版本控制文件${versionFileName}中的 enabled 属性设置为 false`
|
|
376
|
+
logTerminal(
|
|
377
|
+
"warning", `ZIP压缩已禁用,版本控制文件${versionFileName}中的 enabled 属性设置为 false`
|
|
391
378
|
);
|
|
392
379
|
process.exit(0);
|
|
393
380
|
}
|
|
394
381
|
|
|
395
382
|
if (!buildConfig?.buildConfigs?.gitAutoPushReposBranchMap[targetBranch]) {
|
|
396
383
|
if (![testScript].includes(scriptEvent)) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
`❌ 目标分支 ${targetBranch} 非 gitAutoPushReposBranchMap 配置可构建分支,请检查`
|
|
384
|
+
logTerminal(
|
|
385
|
+
"error", `目标分支 ${targetBranch} 非 gitAutoPushReposBranchMap 配置可构建分支,请检查`
|
|
400
386
|
);
|
|
401
387
|
process.exit(1);
|
|
402
388
|
}
|
|
@@ -407,18 +393,18 @@ async function validateConfig(buildConfig, targetBranch = currentBranch) {
|
|
|
407
393
|
const isStageBuild = buildMode === "stage";
|
|
408
394
|
|
|
409
395
|
if (targetBranch === "master" && !isProdBuild) {
|
|
410
|
-
|
|
396
|
+
logTerminal("error", `目标分支为 master 分支,请使用正式环境构建命令进行构建`);
|
|
411
397
|
process.exit(1);
|
|
412
398
|
}
|
|
413
399
|
|
|
414
400
|
if (targetBranch !== "master" && !isStageBuild) {
|
|
415
|
-
|
|
416
|
-
|
|
401
|
+
logTerminal("warning", `目标分支为 ${targetBranch} 分支,建议使用测试环境构建命令`);
|
|
402
|
+
logTerminal("info", `推荐命令: npm run infly:build:stage`);
|
|
417
403
|
|
|
418
404
|
const shouldContinue = await askUserConfirmation("确定要继续当前构建吗?", false);
|
|
419
405
|
|
|
420
406
|
if (!shouldContinue) {
|
|
421
|
-
|
|
407
|
+
logTerminal("info", "构建已取消,请使用正确的构建命令");
|
|
422
408
|
process.exit(1);
|
|
423
409
|
}
|
|
424
410
|
}
|
|
@@ -458,14 +444,14 @@ function validateFileExists(checkPath, logKey) {
|
|
|
458
444
|
}
|
|
459
445
|
}[logKey];
|
|
460
446
|
if (!fs.existsSync(checkPath)) {
|
|
461
|
-
|
|
447
|
+
logTerminal("error", `${error}`);
|
|
462
448
|
process.exit(1);
|
|
463
449
|
}
|
|
464
450
|
if (success) {
|
|
465
|
-
|
|
451
|
+
logTerminal("success", `${success}`);
|
|
466
452
|
}
|
|
467
453
|
if (link) {
|
|
468
|
-
|
|
454
|
+
logTerminal("info", `${link}`);
|
|
469
455
|
}
|
|
470
456
|
}
|
|
471
457
|
|
|
@@ -552,7 +538,7 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
552
538
|
let allVersionExist = true; // 是否所有版本都存在于 version-config.json 中
|
|
553
539
|
if (zipFiles.length === 0) {
|
|
554
540
|
if (!isPkg) {
|
|
555
|
-
|
|
541
|
+
logTerminal("warning", "没有 ZIP 文件,跳过版本更新。");
|
|
556
542
|
}
|
|
557
543
|
} else {
|
|
558
544
|
zipFiles.forEach((zipFile) => {
|
|
@@ -563,15 +549,15 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
563
549
|
allVersionExist = false;
|
|
564
550
|
buildConfig.versionConfig.versionList.unshift(singleVersionInfo);
|
|
565
551
|
const updateText = isDisableUpdateVersionEnv
|
|
566
|
-
?
|
|
567
|
-
:
|
|
568
|
-
|
|
552
|
+
? `新版本${version}已生成,当前环境跳过写入${versionFileName}`
|
|
553
|
+
: `新版本${version}写入${versionFileName}文件更新成功`;
|
|
554
|
+
logTerminal("success", updateText);
|
|
569
555
|
}
|
|
570
556
|
// 如果是更新,压缩脚本进行打包则删除全部旧文件
|
|
571
557
|
if (isBuilZipScript && opt === "update") {
|
|
572
558
|
deleteOldFile.push(fileName);
|
|
573
559
|
fs.unlinkSync(path.join(projectRoot, fileName));
|
|
574
|
-
|
|
560
|
+
logTerminal("success", `已删除 ZIP 文件: ${fileName}`);
|
|
575
561
|
}
|
|
576
562
|
});
|
|
577
563
|
}
|
|
@@ -598,7 +584,7 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
598
584
|
|
|
599
585
|
if (allVersionExist) {
|
|
600
586
|
if (!isPkg) {
|
|
601
|
-
|
|
587
|
+
logTerminal("success", `所有文件版本已存在于${versionFileName}中,无需更新`);
|
|
602
588
|
}
|
|
603
589
|
} else if (!isBuilZipScript || opt !== "update") {
|
|
604
590
|
// 如果是自动压缩的命令,只在完成压缩更新版本后统一输出,更新的时候不输出减少重复信息
|
|
@@ -606,7 +592,7 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
606
592
|
}
|
|
607
593
|
// 如果不是自动压缩的命令,在更新版本json文件后退出
|
|
608
594
|
if (!isBuilZipScript) {
|
|
609
|
-
|
|
595
|
+
logTerminal("warning", "此次仅进行版本号更新,不进行压缩。");
|
|
610
596
|
process.exit(0);
|
|
611
597
|
}
|
|
612
598
|
return { deleteOldFile };
|
|
@@ -674,13 +660,12 @@ function copyToClipboard(text) {
|
|
|
674
660
|
}
|
|
675
661
|
const child = exec(command, (error) => {
|
|
676
662
|
if (error) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
`❌ 文本复制失败: ${error}\n请确保已安装 xclip 或 xsel(Linux),或手动复制:\n${text}`
|
|
663
|
+
logTerminal(
|
|
664
|
+
"error", `文本复制失败: ${error}\n请确保已安装 xclip 或 xsel(Linux),或手动复制:\n${text}`
|
|
680
665
|
);
|
|
681
666
|
reject(error);
|
|
682
667
|
} else {
|
|
683
|
-
|
|
668
|
+
logTerminal("success", `文本已复制到剪贴板\n${text}`);
|
|
684
669
|
resolve(text);
|
|
685
670
|
}
|
|
686
671
|
});
|
|
@@ -728,7 +713,7 @@ function scriptInit() {
|
|
|
728
713
|
scriptWrite(targetProjectPackageJSON, tempInflyConfig, npmPackageConfigKey);
|
|
729
714
|
|
|
730
715
|
if (isExistTargetProjectVersionConfig) {
|
|
731
|
-
|
|
716
|
+
logTerminal("success", `${versionFileName}配置迁移成功, 可手动删除旧版本控制文件`);
|
|
732
717
|
}
|
|
733
718
|
}
|
|
734
719
|
|
|
@@ -756,7 +741,7 @@ function copyVersionConfigFile() {
|
|
|
756
741
|
}
|
|
757
742
|
|
|
758
743
|
if (err) {
|
|
759
|
-
|
|
744
|
+
logTerminal("error", `读取复制文件失败: ${err.message}`);
|
|
760
745
|
return;
|
|
761
746
|
}
|
|
762
747
|
|
|
@@ -774,17 +759,17 @@ function copyVersionConfigFile() {
|
|
|
774
759
|
|
|
775
760
|
fs.writeFile(targetProjectVersionConfigPath, tempVersionConfigStr, (err) => {
|
|
776
761
|
if (err) {
|
|
777
|
-
|
|
762
|
+
logTerminal("error", `读取vue.config.js配置更新失败: ${err.message}`);
|
|
778
763
|
} else {
|
|
779
|
-
|
|
764
|
+
logTerminal("success", `读取vue.config.js配置更新成功`);
|
|
780
765
|
}
|
|
781
766
|
});
|
|
782
767
|
});
|
|
783
|
-
|
|
768
|
+
logTerminal("success", `版本JSON文件已成功复制到根目录:${targetProjectVersionConfigPath}`);
|
|
784
769
|
});
|
|
785
770
|
|
|
786
771
|
writeStream.on("error", (err) => {
|
|
787
|
-
|
|
772
|
+
logTerminal("error", `复制版本JSON文件失败:${err.message}`);
|
|
788
773
|
});
|
|
789
774
|
}
|
|
790
775
|
}
|
|
@@ -809,7 +794,7 @@ async function beforeBuild() {
|
|
|
809
794
|
const currentProjectStatus = checkSingleDirGitStatus(projectGitRoot, sourceRepoName);
|
|
810
795
|
|
|
811
796
|
if (currentProjectStatus.hasUncommitted) {
|
|
812
|
-
|
|
797
|
+
logTerminal("error", `\n当前项目存在未提交的更改,请先提交或暂存后再继续构建`);
|
|
813
798
|
process.exit(1);
|
|
814
799
|
}
|
|
815
800
|
|
|
@@ -818,7 +803,7 @@ async function beforeBuild() {
|
|
|
818
803
|
);
|
|
819
804
|
|
|
820
805
|
if (!currentProjectUpdateResult.success) {
|
|
821
|
-
|
|
806
|
+
logTerminal("error", `\n当前项目切换到 ${targetBranch} 分支失败,请检查`);
|
|
822
807
|
process.exit(1);
|
|
823
808
|
}
|
|
824
809
|
|
|
@@ -846,14 +831,14 @@ async function beforeBuild() {
|
|
|
846
831
|
const siblingStatus = checkSingleDirGitStatus(siblingDir, siblingName);
|
|
847
832
|
|
|
848
833
|
if (siblingStatus.hasUncommitted) {
|
|
849
|
-
|
|
834
|
+
logTerminal("error", `\n兄弟项目 ${siblingName} 存在未提交的更改,请先提交或暂存后再继续构建`);
|
|
850
835
|
process.exit(1);
|
|
851
836
|
}
|
|
852
837
|
|
|
853
838
|
const siblingUpdateResult = pullSingleDirFromBranch(siblingDir, siblingName, targetBranch);
|
|
854
839
|
|
|
855
840
|
if (!siblingUpdateResult.success) {
|
|
856
|
-
|
|
841
|
+
logTerminal("warning", `\n兄弟项目 ${siblingName} 更新失败,但可以继续执行`);
|
|
857
842
|
}
|
|
858
843
|
}
|
|
859
844
|
}
|