@infly/libs 2.0.38 → 2.0.42
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 +66 -0
- package/bin/cli.js +103 -21
- package/build/build-dist/index.js +865 -840
- package/build/build-dist/script-management.js +5 -0
- package/build/build-dist/script-management.test.js +16 -0
- package/build/docker/compose-command.js +74 -0
- package/build/docker/compose-command.test.js +148 -0
- package/build/docker/compose-release.js +91 -0
- package/build/docker/compose-release.test.js +101 -0
- package/build/docker/docker-build-push.js +240 -0
- package/build/docker/docker-build-push.test.js +124 -0
- package/module/Uts.js +1 -1
- package/package.json +8 -4
- package/script/build/deps.js +63 -0
- package/script/git-automation/index.js +2 -38
- package/script/webhook/webhook.js +1 -1
- package/tools/project-command.js +194 -0
- package/tools/project-command.test.js +267 -0
- package/tools/select-option.js +60 -0
- package/tools/select-option.test.js +52 -0
package/README.md
CHANGED
|
@@ -37,3 +37,69 @@
|
|
|
37
37
|
# 项目安装
|
|
38
38
|
npm/pnpm install @infly/libs
|
|
39
39
|
```
|
|
40
|
+
|
|
41
|
+
## Docker 镜像构建
|
|
42
|
+
|
|
43
|
+
在应用目录中执行:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
infly-libs build:docker --local --env prod
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
可通过可选参数 `--cicd-url` 在构建和镜像推送全部成功后输出蓝色发布系统链接。支持等号和空格两种传参形式:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
infly-libs build:docker --local --cicd-url="https://cicd.sutpay.com/view/积分商城/"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
infly-libs build:docker --local --cicd-url "https://cicd.sutpay.com/view/积分商城/"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
未传 `--cicd-url` 时保持原有输出。参数值必须是合法的 HTTP/HTTPS URL,且不能包含用户名、密码或控制字符。
|
|
60
|
+
|
|
61
|
+
## 配置驱动的项目命令
|
|
62
|
+
|
|
63
|
+
`project` 命令将多平台项目的开发和构建目标从 package scripts 移到项目配置:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
infly-libs project
|
|
67
|
+
infly-libs project dev
|
|
68
|
+
infly-libs project build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
命令从当前目录 `package.json` 的 `infly.targets`、`infly.dev` 和 `infly.build` 读取配置。交互选择会追加“退出”选项;选择退出或按取消键时会正常结束,不执行后续命令。项目命令不支持 `--config` 文件入口。
|
|
72
|
+
|
|
73
|
+
未指定 action、target 或构建环境时,会在 TTY 中显示单选菜单。CI/CD 必须显式传参:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
infly-libs project dev --target QDXY
|
|
77
|
+
infly-libs project build --env stage --target SQ223
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`--dry-run` 只打印带 `VUE_APP_PLATFORM` 的命令计划。`infly.targets` 推荐使用平台代码数组,例如 `["DEFAULT", "MER", "JXEE"]`;同时兼容对象形式,对象值中的 `label` 只用于交互显示。普通 target 就是注入 `VUE_APP_PLATFORM` 的平台代码,批量构建通过 `build.presets` 组合多个 target。
|
|
81
|
+
|
|
82
|
+
`dev.command` 以及 `build.before/command/after` 同时支持字符串和参数数组。字符串按空白拆分为可执行文件和参数,不经过 shell;参数本身包含空格时应继续使用数组形式。
|
|
83
|
+
|
|
84
|
+
`build.environments` 推荐使用 `选择键:实际 mode` 数组,例如 `["prod:production", "stage:staging"]`;CLI 使用冒号前的值进行选择,并把冒号后的值作为 `--mode` 参数。没有冒号时选择键和 mode 同名。对象形式继续兼容,用于自定义 `label`、`mode` 或 `args`。项目如果自行管理构建入口,应设置 `infly.buildConfigs.manageScripts=false`,避免安装阶段重新写入传统 `build:prod/build:stage`。
|
|
85
|
+
|
|
86
|
+
### Docker Compose 版本发布
|
|
87
|
+
|
|
88
|
+
`docker:compose` 面向已有 Compose 文件的镜像版本递增、配置校验和构建,与上面的 Dockerfile/commit-tag `build:docker` 流程互不替代:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
infly-libs docker:compose --target yhqy --bump patch
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
默认从当前目录 `package.json` 的 `infly.docker.targets` 读取目标,并以该 package 所在目录解析 Compose 相对路径;省略 `--target` 时在 TTY 中交互选择。`--config` 外部 JS 配置和原有 `--project-dir` + `--file` 直传方式继续兼容。
|
|
95
|
+
|
|
96
|
+
参数约束:
|
|
97
|
+
|
|
98
|
+
- `--target`:选择 `infly.docker.targets` 或外部配置中的目标;非交互环境必须显式传入。
|
|
99
|
+
- `--config`:可选的外部 JS 配置文件,使用 `targets.<name>.file` 结构。
|
|
100
|
+
- `--project-dir` + `--file`:不使用 target 配置时的兼容直传方式,Compose 文件不能越出 `project-dir`。
|
|
101
|
+
- `--bump patch`:目前只支持 patch 递增,且 Compose 中必须恰好有一个 `x.y.z` 镜像 tag。
|
|
102
|
+
- `--push`:显式推送;未传时只执行 `docker compose config` 和 `build`。
|
|
103
|
+
- `--dry-run`:只打印版本变化和计划命令,不写文件、不调用 Docker。
|
|
104
|
+
|
|
105
|
+
构建、校验或推送失败时,命令会恢复原 Compose 内容。公共包不内置 yhqy、qdxy 等业务目标映射;目标配置和单一发布 script 应归 Compose 所在项目所有。
|
package/bin/cli.js
CHANGED
|
@@ -8,31 +8,113 @@ function loadPreview() {
|
|
|
8
8
|
return require("../tools/project-preview");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
function parseArgs(argv) {
|
|
12
|
+
const options = { env: "prod", local: false, dryRun: false };
|
|
13
|
+
const valueOptions = {
|
|
14
|
+
"--env": "env",
|
|
15
|
+
"--cicd-url": "cicdUrl",
|
|
16
|
+
"--project-dir": "projectDir",
|
|
17
|
+
"--file": "file",
|
|
18
|
+
"--bump": "bump",
|
|
19
|
+
"--config": "config",
|
|
20
|
+
"--target": "target",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let i = 0;
|
|
24
|
+
while (i < argv.length) {
|
|
25
|
+
const arg = argv[i];
|
|
26
|
+
const equalsIndex = arg.indexOf("=");
|
|
27
|
+
if (equalsIndex > 0) {
|
|
28
|
+
const flag = arg.slice(0, equalsIndex);
|
|
29
|
+
const key = valueOptions[flag];
|
|
30
|
+
if (key) {
|
|
31
|
+
const value = arg.slice(equalsIndex + 1);
|
|
32
|
+
if (!value) throw new Error(`${flag} requires a value.`);
|
|
33
|
+
options[key] = value;
|
|
34
|
+
i++;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (arg === "--local") {
|
|
40
|
+
options.local = true;
|
|
41
|
+
i++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (arg === "--dry-run") {
|
|
45
|
+
options.dryRun = true;
|
|
46
|
+
i++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (arg === "--push") {
|
|
50
|
+
options.push = true;
|
|
51
|
+
i++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const key = valueOptions[arg];
|
|
56
|
+
if (key) {
|
|
57
|
+
const value = argv[i + 1];
|
|
58
|
+
if (!value || value.startsWith("--")) throw new Error(`${arg} requires a value.`);
|
|
59
|
+
options[key] = value;
|
|
60
|
+
i += 2;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
return options;
|
|
67
|
+
}
|
|
68
|
+
function parseProjectArgs(argv) {
|
|
69
|
+
const options = parseArgs(argv);
|
|
70
|
+
const hasExplicitEnv = argv.some((arg) => arg === "--env" || arg.startsWith("--env="));
|
|
71
|
+
delete options.local;
|
|
72
|
+
if (!hasExplicitEnv) delete options.env;
|
|
73
|
+
return options;
|
|
74
|
+
}
|
|
75
|
+
async function main(argv = process.argv.slice(2)) {
|
|
76
|
+
const command = argv[0];
|
|
77
|
+
const commandMap = {
|
|
78
|
+
afterBuild: () => loadBuildDist().init(),
|
|
79
|
+
initZip: () => loadBuildDist().init(),
|
|
80
|
+
preview: () => loadPreview().init(),
|
|
81
|
+
"--preview": () => loadPreview().init(),
|
|
82
|
+
beforeBuild: () => loadBuildDist().beforeBuild(),
|
|
83
|
+
scriptOverride: () => {
|
|
84
|
+
const preview = loadPreview();
|
|
85
|
+
const buildDist = loadBuildDist();
|
|
86
|
+
preview.scriptInit();
|
|
87
|
+
buildDist.scriptInit();
|
|
88
|
+
},
|
|
89
|
+
"build:docker": () => {
|
|
90
|
+
const opts = parseArgs(argv.slice(1));
|
|
91
|
+
return require("../build/docker/docker-build-push").dockerBuildPush(opts);
|
|
92
|
+
},
|
|
93
|
+
"docker:compose": () => {
|
|
94
|
+
const opts = parseArgs(argv.slice(1));
|
|
95
|
+
return require("../build/docker/compose-command").runComposeCommand(opts);
|
|
96
|
+
},
|
|
97
|
+
project: () => {
|
|
98
|
+
const action = argv[1] && !argv[1].startsWith("--") ? argv[1] : undefined;
|
|
99
|
+
const opts = parseProjectArgs(argv.slice(action ? 2 : 1));
|
|
100
|
+
return require("../tools/project-command").runProjectCommand({ ...opts, action });
|
|
101
|
+
},
|
|
102
|
+
};
|
|
26
103
|
|
|
27
|
-
(async () => {
|
|
28
104
|
if (command && commandMap[command]) {
|
|
29
105
|
await commandMap[command]();
|
|
30
106
|
} else {
|
|
31
107
|
console.error(`未知命令: ${command || "未提供命令"}`);
|
|
32
108
|
console.log(`可用命令: ${Object.keys(commandMap).join(", ")}`);
|
|
33
|
-
process.
|
|
109
|
+
process.exitCode = 1;
|
|
34
110
|
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (require.main === module) {
|
|
114
|
+
main().catch((error) => {
|
|
115
|
+
console.error("执行失败:", error.message || error);
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { main, parseArgs, parseProjectArgs };
|