@infly/libs 2.6.0 → 2.7.0
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 +18 -0
- 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 +34 -44
- 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 +5 -1
- 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 +1 -1
- 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 +813 -828
- package/script/git-automation/submodule-utils.js +16 -16
- package/workspace/config.js +144 -144
package/README.md
CHANGED
|
@@ -482,3 +482,21 @@ source 构建组件可配置 `monorepoContextFiles: [tooling/install.cjs]`,逐
|
|
|
482
482
|
`source.standalone: true` 可显式使用独立源码上下文,即使业务仓位于 monorepo 中也不带根公共包;适用于已有独立安装契约的紧急构建。target 的 `recordConfigurationRevision: true` 则让未注入文件的外部源码组件也记录并复核部署仓提交。两者均为可选布尔值,默认保持原有行为。
|
|
483
483
|
|
|
484
484
|
组件可声明 `health: {timeoutSeconds: 60, addHost: api:127.0.0.1}`,复用运行镜像的 HEALTHCHECK,失败不推送本组任何镜像。普通 check 仍用于语法或文件检查;不要对后端启动真实业务进程作本地镜像探针。
|
|
485
|
+
|
|
486
|
+
组件可按需声明下列 Docker 构建输入。dry-run 只给出配置计划,实际执行前才从进程环境解析仓库和密钥文件路径。
|
|
487
|
+
|
|
488
|
+
```yaml
|
|
489
|
+
repositoryEnv: IMAGE_REPOSITORY
|
|
490
|
+
buildSecrets:
|
|
491
|
+
- id: app_env
|
|
492
|
+
fileEnv: APP_ENV_FILE
|
|
493
|
+
defaultFile: .env.app.local
|
|
494
|
+
noCacheFilter: [frontend-build]
|
|
495
|
+
buildTimestampArg: BUILD_TIMESTAMP
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
- `repositoryEnv` 可替代固定的 `repository`,用于让构建执行者选择镜像仓库。
|
|
499
|
+
- `buildSecrets` 声明 BuildKit 密钥 ID 和保存文件路径的环境变量名。可用 `defaultFile` 声明相对部署仓的本机文件路径,未设置环境变量时使用该文件。密钥文件应放在构建上下文之外,并保持 Git 忽略,由 Dockerfile 使用 `RUN --mount=type=secret` 消费。文件路径和内容均不写入发布记录。
|
|
500
|
+
- `noCacheFilter` 按阶段传给 Buildx。依赖密钥内容改变的编译阶段应列入此处,仍可复用其他构建阶段缓存。
|
|
501
|
+
- `buildTimestampArg` 通过指定的构建参数提供一份 `+08:00` 时间戳。镜像检查可声明 `check.network: none` 进行无网络验证。
|
|
502
|
+
- `--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,20 +4,13 @@
|
|
|
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");
|
|
@@ -300,7 +293,7 @@ async function init() {
|
|
|
300
293
|
await previewInit(true);
|
|
301
294
|
}
|
|
302
295
|
} catch (error) {
|
|
303
|
-
|
|
296
|
+
logTerminal("error", `自动构建脚本执行出错, 错误信息:\n${error}`);
|
|
304
297
|
process.exit(1);
|
|
305
298
|
}
|
|
306
299
|
}
|
|
@@ -380,23 +373,21 @@ function askUserConfirmation(message, defaultYes = false) {
|
|
|
380
373
|
*/
|
|
381
374
|
async function validateConfig(buildConfig, targetBranch = currentBranch) {
|
|
382
375
|
if (!buildConfig) {
|
|
383
|
-
|
|
376
|
+
logTerminal("error", `ZIP压缩已禁用,版本控制文件${versionFileName}配置错误`);
|
|
384
377
|
process.exit(1);
|
|
385
378
|
}
|
|
386
379
|
|
|
387
380
|
if (buildConfig?.buildConfigs?.enabled === false) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
`⚠️ ZIP压缩已禁用,版本控制文件${versionFileName}中的 enabled 属性设置为 false`
|
|
381
|
+
logTerminal(
|
|
382
|
+
"warning", `ZIP压缩已禁用,版本控制文件${versionFileName}中的 enabled 属性设置为 false`
|
|
391
383
|
);
|
|
392
384
|
process.exit(0);
|
|
393
385
|
}
|
|
394
386
|
|
|
395
387
|
if (!buildConfig?.buildConfigs?.gitAutoPushReposBranchMap[targetBranch]) {
|
|
396
388
|
if (![testScript].includes(scriptEvent)) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
`❌ 目标分支 ${targetBranch} 非 gitAutoPushReposBranchMap 配置可构建分支,请检查`
|
|
389
|
+
logTerminal(
|
|
390
|
+
"error", `目标分支 ${targetBranch} 非 gitAutoPushReposBranchMap 配置可构建分支,请检查`
|
|
400
391
|
);
|
|
401
392
|
process.exit(1);
|
|
402
393
|
}
|
|
@@ -407,18 +398,18 @@ async function validateConfig(buildConfig, targetBranch = currentBranch) {
|
|
|
407
398
|
const isStageBuild = buildMode === "stage";
|
|
408
399
|
|
|
409
400
|
if (targetBranch === "master" && !isProdBuild) {
|
|
410
|
-
|
|
401
|
+
logTerminal("error", `目标分支为 master 分支,请使用正式环境构建命令进行构建`);
|
|
411
402
|
process.exit(1);
|
|
412
403
|
}
|
|
413
404
|
|
|
414
405
|
if (targetBranch !== "master" && !isStageBuild) {
|
|
415
|
-
|
|
416
|
-
|
|
406
|
+
logTerminal("warning", `目标分支为 ${targetBranch} 分支,建议使用测试环境构建命令`);
|
|
407
|
+
logTerminal("info", `推荐命令: npm run infly:build:stage`);
|
|
417
408
|
|
|
418
409
|
const shouldContinue = await askUserConfirmation("确定要继续当前构建吗?", false);
|
|
419
410
|
|
|
420
411
|
if (!shouldContinue) {
|
|
421
|
-
|
|
412
|
+
logTerminal("info", "构建已取消,请使用正确的构建命令");
|
|
422
413
|
process.exit(1);
|
|
423
414
|
}
|
|
424
415
|
}
|
|
@@ -458,14 +449,14 @@ function validateFileExists(checkPath, logKey) {
|
|
|
458
449
|
}
|
|
459
450
|
}[logKey];
|
|
460
451
|
if (!fs.existsSync(checkPath)) {
|
|
461
|
-
|
|
452
|
+
logTerminal("error", `${error}`);
|
|
462
453
|
process.exit(1);
|
|
463
454
|
}
|
|
464
455
|
if (success) {
|
|
465
|
-
|
|
456
|
+
logTerminal("success", `${success}`);
|
|
466
457
|
}
|
|
467
458
|
if (link) {
|
|
468
|
-
|
|
459
|
+
logTerminal("info", `${link}`);
|
|
469
460
|
}
|
|
470
461
|
}
|
|
471
462
|
|
|
@@ -552,7 +543,7 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
552
543
|
let allVersionExist = true; // 是否所有版本都存在于 version-config.json 中
|
|
553
544
|
if (zipFiles.length === 0) {
|
|
554
545
|
if (!isPkg) {
|
|
555
|
-
|
|
546
|
+
logTerminal("warning", "没有 ZIP 文件,跳过版本更新。");
|
|
556
547
|
}
|
|
557
548
|
} else {
|
|
558
549
|
zipFiles.forEach((zipFile) => {
|
|
@@ -563,15 +554,15 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
563
554
|
allVersionExist = false;
|
|
564
555
|
buildConfig.versionConfig.versionList.unshift(singleVersionInfo);
|
|
565
556
|
const updateText = isDisableUpdateVersionEnv
|
|
566
|
-
?
|
|
567
|
-
:
|
|
568
|
-
|
|
557
|
+
? `新版本${version}已生成,当前环境跳过写入${versionFileName}`
|
|
558
|
+
: `新版本${version}写入${versionFileName}文件更新成功`;
|
|
559
|
+
logTerminal("success", updateText);
|
|
569
560
|
}
|
|
570
561
|
// 如果是更新,压缩脚本进行打包则删除全部旧文件
|
|
571
562
|
if (isBuilZipScript && opt === "update") {
|
|
572
563
|
deleteOldFile.push(fileName);
|
|
573
564
|
fs.unlinkSync(path.join(projectRoot, fileName));
|
|
574
|
-
|
|
565
|
+
logTerminal("success", `已删除 ZIP 文件: ${fileName}`);
|
|
575
566
|
}
|
|
576
567
|
});
|
|
577
568
|
}
|
|
@@ -598,7 +589,7 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
598
589
|
|
|
599
590
|
if (allVersionExist) {
|
|
600
591
|
if (!isPkg) {
|
|
601
|
-
|
|
592
|
+
logTerminal("success", `所有文件版本已存在于${versionFileName}中,无需更新`);
|
|
602
593
|
}
|
|
603
594
|
} else if (!isBuilZipScript || opt !== "update") {
|
|
604
595
|
// 如果是自动压缩的命令,只在完成压缩更新版本后统一输出,更新的时候不输出减少重复信息
|
|
@@ -606,7 +597,7 @@ function updateVersionList(zipFiles = [], extraParams) {
|
|
|
606
597
|
}
|
|
607
598
|
// 如果不是自动压缩的命令,在更新版本json文件后退出
|
|
608
599
|
if (!isBuilZipScript) {
|
|
609
|
-
|
|
600
|
+
logTerminal("warning", "此次仅进行版本号更新,不进行压缩。");
|
|
610
601
|
process.exit(0);
|
|
611
602
|
}
|
|
612
603
|
return { deleteOldFile };
|
|
@@ -674,13 +665,12 @@ function copyToClipboard(text) {
|
|
|
674
665
|
}
|
|
675
666
|
const child = exec(command, (error) => {
|
|
676
667
|
if (error) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
`❌ 文本复制失败: ${error}\n请确保已安装 xclip 或 xsel(Linux),或手动复制:\n${text}`
|
|
668
|
+
logTerminal(
|
|
669
|
+
"error", `文本复制失败: ${error}\n请确保已安装 xclip 或 xsel(Linux),或手动复制:\n${text}`
|
|
680
670
|
);
|
|
681
671
|
reject(error);
|
|
682
672
|
} else {
|
|
683
|
-
|
|
673
|
+
logTerminal("success", `文本已复制到剪贴板\n${text}`);
|
|
684
674
|
resolve(text);
|
|
685
675
|
}
|
|
686
676
|
});
|
|
@@ -728,7 +718,7 @@ function scriptInit() {
|
|
|
728
718
|
scriptWrite(targetProjectPackageJSON, tempInflyConfig, npmPackageConfigKey);
|
|
729
719
|
|
|
730
720
|
if (isExistTargetProjectVersionConfig) {
|
|
731
|
-
|
|
721
|
+
logTerminal("success", `${versionFileName}配置迁移成功, 可手动删除旧版本控制文件`);
|
|
732
722
|
}
|
|
733
723
|
}
|
|
734
724
|
|
|
@@ -756,7 +746,7 @@ function copyVersionConfigFile() {
|
|
|
756
746
|
}
|
|
757
747
|
|
|
758
748
|
if (err) {
|
|
759
|
-
|
|
749
|
+
logTerminal("error", `读取复制文件失败: ${err.message}`);
|
|
760
750
|
return;
|
|
761
751
|
}
|
|
762
752
|
|
|
@@ -774,17 +764,17 @@ function copyVersionConfigFile() {
|
|
|
774
764
|
|
|
775
765
|
fs.writeFile(targetProjectVersionConfigPath, tempVersionConfigStr, (err) => {
|
|
776
766
|
if (err) {
|
|
777
|
-
|
|
767
|
+
logTerminal("error", `读取vue.config.js配置更新失败: ${err.message}`);
|
|
778
768
|
} else {
|
|
779
|
-
|
|
769
|
+
logTerminal("success", `读取vue.config.js配置更新成功`);
|
|
780
770
|
}
|
|
781
771
|
});
|
|
782
772
|
});
|
|
783
|
-
|
|
773
|
+
logTerminal("success", `版本JSON文件已成功复制到根目录:${targetProjectVersionConfigPath}`);
|
|
784
774
|
});
|
|
785
775
|
|
|
786
776
|
writeStream.on("error", (err) => {
|
|
787
|
-
|
|
777
|
+
logTerminal("error", `复制版本JSON文件失败:${err.message}`);
|
|
788
778
|
});
|
|
789
779
|
}
|
|
790
780
|
}
|
|
@@ -809,7 +799,7 @@ async function beforeBuild() {
|
|
|
809
799
|
const currentProjectStatus = checkSingleDirGitStatus(projectGitRoot, sourceRepoName);
|
|
810
800
|
|
|
811
801
|
if (currentProjectStatus.hasUncommitted) {
|
|
812
|
-
|
|
802
|
+
logTerminal("error", `\n当前项目存在未提交的更改,请先提交或暂存后再继续构建`);
|
|
813
803
|
process.exit(1);
|
|
814
804
|
}
|
|
815
805
|
|
|
@@ -818,7 +808,7 @@ async function beforeBuild() {
|
|
|
818
808
|
);
|
|
819
809
|
|
|
820
810
|
if (!currentProjectUpdateResult.success) {
|
|
821
|
-
|
|
811
|
+
logTerminal("error", `\n当前项目切换到 ${targetBranch} 分支失败,请检查`);
|
|
822
812
|
process.exit(1);
|
|
823
813
|
}
|
|
824
814
|
|
|
@@ -846,14 +836,14 @@ async function beforeBuild() {
|
|
|
846
836
|
const siblingStatus = checkSingleDirGitStatus(siblingDir, siblingName);
|
|
847
837
|
|
|
848
838
|
if (siblingStatus.hasUncommitted) {
|
|
849
|
-
|
|
839
|
+
logTerminal("error", `\n兄弟项目 ${siblingName} 存在未提交的更改,请先提交或暂存后再继续构建`);
|
|
850
840
|
process.exit(1);
|
|
851
841
|
}
|
|
852
842
|
|
|
853
843
|
const siblingUpdateResult = pullSingleDirFromBranch(siblingDir, siblingName, targetBranch);
|
|
854
844
|
|
|
855
845
|
if (!siblingUpdateResult.success) {
|
|
856
|
-
|
|
846
|
+
logTerminal("warning", `\n兄弟项目 ${siblingName} 更新失败,但可以继续执行`);
|
|
857
847
|
}
|
|
858
848
|
}
|
|
859
849
|
}
|
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
...
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
...
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
const { logTerminal } = require("../../cli/terminal-style");
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
|
|
4
|
+
function run(command, args, options = {}) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
|
|
7
|
+
// Avoid DEP0190: when shell=true, pass command+args as single string
|
|
8
|
+
const [cmd, cmdArgs] = useShell
|
|
9
|
+
? [[command, ...args].join(" "), []]
|
|
10
|
+
: [command, args];
|
|
11
|
+
const child = spawn(cmd, cmdArgs, {
|
|
12
|
+
cwd: options.cwd || process.cwd(),
|
|
13
|
+
env: {
|
|
14
|
+
...process.env,
|
|
15
|
+
...(options.env || {})
|
|
16
|
+
},
|
|
17
|
+
stdio: options.stdio || "inherit",
|
|
18
|
+
shell: useShell
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
child.on("close", (code) => {
|
|
22
|
+
if (code === 0) {
|
|
23
|
+
resolve();
|
|
24
|
+
} else {
|
|
25
|
+
reject(new Error(`${command} ${args.join(" ")} failed with exit code ${code}`));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
child.on("error", reject);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function spawnBackground(command, args, options = {}) {
|
|
34
|
+
const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
|
|
35
|
+
const [cmd, cmdArgs] = useShell
|
|
36
|
+
? [[command, ...args].join(" "), []]
|
|
37
|
+
: [command, args];
|
|
38
|
+
const child = spawn(cmd, cmdArgs, {
|
|
39
|
+
cwd: options.cwd || process.cwd(),
|
|
40
|
+
env: {
|
|
41
|
+
...process.env,
|
|
42
|
+
...(options.env || {})
|
|
43
|
+
},
|
|
44
|
+
stdio: options.stdio || "inherit",
|
|
45
|
+
shell: useShell
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
child.on("error", (error) => {
|
|
49
|
+
logTerminal("error", error.message);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return child;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
run,
|
|
57
|
+
spawnBackground
|
|
58
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 从项目的 webpack/vite 等构建配置中解析对兄弟 app 的依赖。
|
|
6
|
-
*
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 从项目的 webpack/vite 等构建配置中解析对兄弟 app 的依赖。
|
|
6
|
+
*
|
|
7
7
|
* 规则:如果 vue.config.js / vite.config.* / next.config.* 的 alias 中存在指向 ../ 的路径,
|
|
8
|
-
* 则认为当前项目依赖该兄弟 app,构建前需要确保兄弟 app 源码是最新的。
|
|
9
|
-
*
|
|
10
|
-
* 示例(vue.config.js):
|
|
11
|
-
* alias: {
|
|
12
|
-
* "@example-admin": projectResolve("../example-admin/src")
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* @param {string} appDir - 当前 app 目录的绝对路径
|
|
16
|
-
* @returns {string[]} 兄弟 app 根目录(含 package.json)的绝对路径列表
|
|
17
|
-
*/
|
|
8
|
+
* 则认为当前项目依赖该兄弟 app,构建前需要确保兄弟 app 源码是最新的。
|
|
9
|
+
*
|
|
10
|
+
* 示例(vue.config.js):
|
|
11
|
+
* alias: {
|
|
12
|
+
* "@example-admin": projectResolve("../example-admin/src")
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* @param {string} appDir - 当前 app 目录的绝对路径
|
|
16
|
+
* @returns {string[]} 兄弟 app 根目录(含 package.json)的绝对路径列表
|
|
17
|
+
*/
|
|
18
18
|
function resolveSiblingAppDeps(appDir) {
|
|
19
19
|
const siblings = [];
|
|
20
20
|
const configFiles = [
|
|
@@ -51,13 +51,13 @@ function resolveSiblingAppDeps(appDir) {
|
|
|
51
51
|
addSibling(match[2]);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
for (const configFile of configFiles) {
|
|
56
|
-
const configPath = path.join(appDir, configFile);
|
|
57
|
-
if (!fs.existsSync(configPath)) continue;
|
|
58
|
-
|
|
59
|
-
const content = fs.readFileSync(configPath, "utf8");
|
|
60
|
-
|
|
54
|
+
|
|
55
|
+
for (const configFile of configFiles) {
|
|
56
|
+
const configPath = path.join(appDir, configFile);
|
|
57
|
+
if (!fs.existsSync(configPath)) continue;
|
|
58
|
+
|
|
59
|
+
const content = fs.readFileSync(configPath, "utf8");
|
|
60
|
+
|
|
61
61
|
// 匹配 alias 中指向 ../ 兄弟目录的值,兼容以下写法:
|
|
62
62
|
// "@foo": projectResolve("../foo/src")
|
|
63
63
|
// "@foo": resolve("../foo/src")
|
|
@@ -77,8 +77,8 @@ function resolveSiblingAppDeps(appDir) {
|
|
|
77
77
|
|
|
78
78
|
[...objectAliasPatterns, ...arrayAliasPatterns].forEach((pattern) => collectMatches(content, pattern));
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
return siblings;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = { resolveSiblingAppDeps };
|
|
80
|
+
|
|
81
|
+
return siblings;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { resolveSiblingAppDeps };
|