@gmcb/cli 0.9.3 → 0.9.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.
- package/CHANGELOG.md +22 -5
- package/README.md +15 -11
- package/lib/actions/build.js +40 -133
- package/lib/actions/publish.js +4 -12
- package/lib/commands/option.d.ts +2 -2
- package/lib/commands/option.js +1 -1
- package/lib/commands/platform.d.ts +1 -0
- package/lib/commands/platform.js +2 -0
- package/lib/utils/function.d.ts +0 -4
- package/lib/utils/function.js +0 -10
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,18 +3,35 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [0.9.
|
|
6
|
+
## [0.9.5](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.4...@gmcb/cli@0.9.5) (2026-11-04)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
### Bug Fixes
|
|
10
|
-
|
|
11
|
-
* 合并 CLI 调整(image/config 命令、gradlew 构建流程与 uni-app x 路由) ([4e1734b](http://10.10.10.16/caoben/front-end-tools/commits/4e1734b7ae1ec0c3f2a910c27d9220f1ea7010ec))
|
|
8
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
12
9
|
|
|
13
10
|
|
|
14
11
|
|
|
15
12
|
|
|
16
13
|
|
|
17
14
|
|
|
15
|
+
## [0.9.4](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.3...@gmcb/cli@0.9.4) (2026-11-04)
|
|
16
|
+
|
|
17
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## [0.9.3](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.2...@gmcb/cli@0.9.3) (2026-11-04)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* 合并 CLI 调整(image/config 命令、gradlew 构建流程与 uni-app x 路由) ([4e1734b](http://10.10.10.16/caoben/front-end-tools/commits/4e1734b7ae1ec0c3f2a910c27d9220f1ea7010ec))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
18
35
|
## [0.9.2](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.1...@gmcb/cli@0.9.2) (2026-11-02)
|
|
19
36
|
|
|
20
37
|
**Note:** Version bump only for package @gmcb/cli
|
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ npm i @gmcb/cli -g
|
|
|
29
29
|
|
|
30
30
|
| 选项 | 描述 |
|
|
31
31
|
|---|---|
|
|
32
|
-
| `-p, --platform` | 编译平台,默认 h5
|
|
32
|
+
| `-p, --platform` | 编译平台,默认 h5(`web` 为 h5 的别名,HBuilderX 5.x 平台名) |
|
|
33
33
|
| `-c, --compiler` | 构建工具,默认 uni |
|
|
34
34
|
| `-b, --branch` | Git 分支名称 |
|
|
35
35
|
| `-e, --env` | 构建环境,默认 prod |
|
|
@@ -41,6 +41,8 @@ npm i @gmcb/cli -g
|
|
|
41
41
|
|
|
42
42
|
使用 `--wgt` 构建移动应用热更新资源时,经典 uni-app 会先通过 vite/uni 正常构建 app,再将构建产物(`dist/build/app` 或 `unpackage/dist/build/app-plus`)打包为 `.wgt` 文件,输出路径默认为 `unpackage/release`;uni-app x 的 wgt 由 HBuilderX 直接导出(见「uni-app x 兼容」)。
|
|
43
43
|
|
|
44
|
+
`gmcb build` 与 `gmcb publish` 的 `-p web` 等价 `-p h5`:`web` 是 HBuilderX 5.x 的平台名,CLI 会在构建/发布前统一归一化为 `h5`,经典 uni-app 与 uni-app x 行为一致。
|
|
45
|
+
|
|
44
46
|
`uni.build.json` 中可通过 `app.wgt` 配置导出文件名和路径:
|
|
45
47
|
|
|
46
48
|
```json
|
|
@@ -67,7 +69,7 @@ gmcb build -p app --wgt
|
|
|
67
69
|
|
|
68
70
|
| 选项 | 描述 |
|
|
69
71
|
|---|---|
|
|
70
|
-
| `-p, --platform` | 编译平台,默认 h5 |
|
|
72
|
+
| `-p, --platform` | 编译平台,默认 h5(`web` 为 h5 的别名) |
|
|
71
73
|
| `-c, --compiler` | 构建工具,默认 uni |
|
|
72
74
|
| `-b, --branch` | Git 分支名称 |
|
|
73
75
|
| `-e, --env` | 构建环境,默认 prod |
|
|
@@ -104,29 +106,31 @@ gmcb publish -p app --wgt -a
|
|
|
104
106
|
### 识别与前提
|
|
105
107
|
|
|
106
108
|
- `src/manifest.json` 或项目根 `manifest.json` 含 `uni-app-x` 字段(如 `"uni-app-x": {}`)即识别为 uni-app x 工程
|
|
107
|
-
- **App 平台(`app` / `app-android` / `app-ios` / `app-harmony`)始终使用 `cli.hbuilderx` 编译**:无论工程有没有 `src` 目录,都走 `publish
|
|
109
|
+
- **App 平台(`app` / `app-android` / `app-ios` / `app-harmony`)始终使用 `cli.hbuilderx` 编译**:无论工程有没有 `src` 目录,都走 HBuilderX 命令:`app` 用 `publish --platform APP --type appResource|wgt`,`app-android` / `app-ios` 用 `publish --platform app-android|app-ios --type ...`,`app-harmony` 用 `publish app-harmony --type ...`;无参数打包分别走 `pack --platform ...` / `pack --platform harmony`,不需要 `--pack`
|
|
108
110
|
- H5 / 微信小程序按布局分流:含 `src` 走本地 npm CLI(`uni build`);无 `src` 走 `cli.hbuilderx publish ...`(传 `--pack` 或 `-P` 时也走 HBuilderX)
|
|
109
111
|
- HBuilderX 4.67+(蒸汽模式 wgt 需要 5.33+),需启动 HBuilderX 且项目已导入,CLI 路径用 `gmcb config --cli.hbuilderx <cli-path>` 配置;`src` 布局工程需在 HBuilderX 中被识别为 uni-app x(如 App 导出提示“不支持”,可在 HBuilderX 中调整项目类型)
|
|
110
|
-
- `-p web` 是 `-p h5` 的别名(仅 uni-app x)
|
|
111
112
|
|
|
112
113
|
### 平台与命令行映射(HBuilderX 编译分支)
|
|
113
114
|
|
|
114
|
-
下表为 App 平台(有无 `src` 均如此)以及无 `src`(或传 `--pack` / `-P`)时 H5 / 微信小程序实际执行的 HBuilderX
|
|
115
|
+
下表为 App 平台(有无 `src` 均如此)以及无 `src`(或传 `--pack` / `-P`)时 H5 / 微信小程序实际执行的 HBuilderX 命令(App 平台按 `-p` 平台区分命令):
|
|
115
116
|
|
|
116
117
|
| `-p` 平台 | 附加参数 | 执行的 HBuilderX 命令 | 输出目录 |
|
|
117
118
|
|---|---|---|---|
|
|
118
|
-
| `h5` / `web` | - | `publish
|
|
119
|
-
| `mp-weixin` | - | `publish
|
|
120
|
-
| `app`
|
|
121
|
-
| `app
|
|
119
|
+
| `h5` / `web` | - | `publish --platform h5` | `unpackage/dist/build/web` |
|
|
120
|
+
| `mp-weixin` | - | `publish --platform MP-WEIXIN [--appid ...]` | `unpackage/dist/build/mp-weixin` |
|
|
121
|
+
| `app` | `--res` | `publish --platform APP --type appResource` | `unpackage/resources/app-*`(`-p app` 同时导出 app-android、app-ios) |
|
|
122
|
+
| `app-android` / `app-ios` | `--res` | `publish --platform app-android\|app-ios --type appResource` | `unpackage/resources/app-*` |
|
|
123
|
+
| `app` | `--wgt` | `publish --platform APP --type wgt` | `unpackage/release`(名称/路径由 `app.wgt` 配置决定) |
|
|
124
|
+
| `app-android` / `app-ios` | `--wgt` | `publish --platform app-android\|app-ios --type wgt` | `unpackage/release`(名称/路径由 `app.wgt` 配置决定) |
|
|
122
125
|
| `app` / `app-android` / `app-ios` | 无 | `pack --platform android,ios\|android\|ios` | 云端打包 |
|
|
123
|
-
| `app-harmony` | `--res` / `--wgt` / 无 | `publish app-harmony --type appResource\|wgt` / `pack
|
|
126
|
+
| `app-harmony` | `--res` / `--wgt` / 无 | `publish app-harmony --type appResource\|wgt` / `pack --platform harmony` | 以 HBuilderX 实际输出为准 |
|
|
124
127
|
|
|
125
128
|
- uni-app x 的 `--wgt` 仅蒸汽模式(`manifest.json` 的 `"uni-app-x": { "vapor": true }`)支持,由 HBuilderX 校验
|
|
126
129
|
- `--res` 产物结构随编译模式不同:VDOM 模式包含 `uniappx/app-android/src/**/*.kt` 等页面 Kotlin 源码;蒸汽模式(vapor)为 `__UNI__xxx/www/bytes/**/*.bytes` + `app-service.js`,不含 Kotlin 源码
|
|
127
|
-
- `--wgt`
|
|
130
|
+
- `--wgt` 产物由 HBuilderX 导出,导出路径/文件名由 `uni.build.json` 的 `app.wgt.path` / `app.wgt.name` 控制;`gmcb publish --wgt` 上传时同样读取该配置,或直接手动上传
|
|
128
131
|
- `mp-weixin` 的 `appid` 取 `manifest.json` 的 `mp-weixin.appid`,有值时才传 `--appid`;appid 为空时仍可编译出产物,但 HBuilderX 会尝试打开微信开发者工具并提示 appid 不存在,配置 appid 后即可正常使用;发布上传时为空会给出明确错误
|
|
129
132
|
- 云打包的证书/包名等配置与经典 uni-app 相同(`uni.build.json` 的 `app.android` / `app.ios`)
|
|
133
|
+
- uni-app x 的 HBuilderX 子命令按平台区分:`app` 使用 `--platform APP`,`app-android` / `app-ios` 使用 `--platform app-android|app-ios`,`app-harmony` 使用 `publish app-harmony` / `pack --platform harmony`,后续再按 HBuilderX 版本继续优化
|
|
130
134
|
- 含 `src` 的工程执行上表 App 命令时会自动走 HBuilderX(`src` 布局的 H5 / `mp-weixin` 仍为本地 `uni build`,不会走 HBuilderX)
|
|
131
135
|
- 完整示例见 `examples/uniapp-x`(`src` 布局的蒸汽模式工程),可直接验证下列命令
|
|
132
136
|
|
package/lib/actions/build.js
CHANGED
|
@@ -117,39 +117,12 @@ async function syncLatestVersion() {
|
|
|
117
117
|
}
|
|
118
118
|
spinner.stop();
|
|
119
119
|
}
|
|
120
|
-
/**
|
|
121
|
-
* 归一化 wgt 导出参数(uni-app x 新分支使用):正确识别 --path,保证只出现一次
|
|
122
|
-
*/
|
|
123
|
-
function prepareWgtFlags(wgtFlags) {
|
|
124
|
-
const flags = [...wgtFlags];
|
|
125
|
-
const index = flags.findIndex((item) => item === '--path' || item.startsWith('--path '));
|
|
126
|
-
let dist;
|
|
127
|
-
if (index === -1) {
|
|
128
|
-
dist = (0, path_1.resolve)('unpackage/release');
|
|
129
|
-
flags.push('--path', dist);
|
|
130
|
-
}
|
|
131
|
-
else if (flags[index] === '--path') {
|
|
132
|
-
dist = flags[index + 1] || (0, path_1.resolve)('unpackage/release');
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
dist = flags[index].slice('--path '.length);
|
|
136
|
-
}
|
|
137
|
-
(0, fs_extra_1.ensureDirSync)(dist);
|
|
138
|
-
const manifest = (0, utils_1.readManifest)();
|
|
139
|
-
if (manifest.appid) {
|
|
140
|
-
(0, fs_extra_1.removeSync)((0, path_1.join)(dist, `${manifest.appid}.wgt`));
|
|
141
|
-
}
|
|
142
|
-
return { flags, dist };
|
|
143
|
-
}
|
|
144
120
|
async function getCommands(...args) {
|
|
145
121
|
const opts = args[0];
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// uni-app x 使用 HBuilderX 5.x 平台名:-p web 等价 -p h5(经典 uni-app 保持原有行为)
|
|
149
|
-
opts.platform = (0, utils_1.normalizePlatform)(opts.platform);
|
|
122
|
+
if (opts.platform === 'web') {
|
|
123
|
+
opts.platform = 'h5';
|
|
150
124
|
}
|
|
151
|
-
|
|
152
|
-
const isUniappXApp = isUniappX && !!opts.platform?.startsWith('app');
|
|
125
|
+
const isUniappX = (0, utils_1.isUniappXManifest)();
|
|
153
126
|
if (config_1.CONFIG_DATA.branch && config_1.CONFIG_DATA.branch !== 'false') {
|
|
154
127
|
opts.branch = config_1.CONFIG_DATA.branch;
|
|
155
128
|
}
|
|
@@ -178,25 +151,30 @@ async function getCommands(...args) {
|
|
|
178
151
|
}
|
|
179
152
|
const currentName = (0, path_1.basename)(utils_1.COMMAND_PATH);
|
|
180
153
|
const projectName = opts.project || currentName;
|
|
181
|
-
let useHBuilderX = false;
|
|
182
154
|
if (opts.compiler === 'uni') {
|
|
183
|
-
|
|
155
|
+
const isUniappXApp = isUniappX && opts.platform.startsWith('app');
|
|
156
|
+
// 无 src、uni-app x 的 App 平台、-P 指定了不同的 HBuilderX 项目名时都必须由 HBuilderX 构建,统一归一到 opts.pack
|
|
157
|
+
if (!utils_1.HAS_SRC || isUniappXApp || projectName !== currentName) {
|
|
184
158
|
opts.pack = true;
|
|
185
159
|
}
|
|
186
|
-
|
|
187
|
-
useHBuilderX = projectName !== currentName || !!opts.pack || isUniappXApp;
|
|
188
|
-
if (!useHBuilderX) {
|
|
160
|
+
if (!opts.pack) {
|
|
189
161
|
commands = [...commands, bin, 'build -p', opts.platform];
|
|
190
162
|
}
|
|
191
163
|
else {
|
|
192
164
|
if (!(0, fs_1.existsSync)(config_1.CONFIG_DATA?.cli?.hbuilderx)) {
|
|
193
165
|
utils_1.log.error('HbuilderX Cli路径不正确,请执行“gmcb config --cli.hbuilderx <cli-path>”设置正确的路径!');
|
|
194
166
|
}
|
|
167
|
+
if (!(0, fs_1.existsSync)(utils_1.PACKAGE_PATH)) {
|
|
168
|
+
commands = [];
|
|
169
|
+
}
|
|
170
|
+
let projectPath = utils_1.COMMAND_PATH;
|
|
195
171
|
if (projectName !== currentName) {
|
|
196
|
-
|
|
197
|
-
|
|
172
|
+
if (opts.source) {
|
|
173
|
+
projectPath = (0, path_1.join)(utils_1.COMMAND_PATH, opts.source);
|
|
174
|
+
}
|
|
175
|
+
envPath = (0, path_1.join)(projectPath, 'buildenv');
|
|
198
176
|
if (opts.source && opts.branch) {
|
|
199
|
-
const git = (0, simple_git_1.default)(
|
|
177
|
+
const git = (0, simple_git_1.default)(projectPath);
|
|
200
178
|
const branch = await git.branch();
|
|
201
179
|
if (opts.branch !== branch.current) {
|
|
202
180
|
utils_1.log.error(`您当前构建分支为“${opts.branch}”,项目“${projectName}”构建分支为“${branch.current}”,分支不一致,无法完成构建,请更改后重试!`);
|
|
@@ -212,54 +190,10 @@ async function getCommands(...args) {
|
|
|
212
190
|
}
|
|
213
191
|
(0, fs_1.writeFileSync)(envPath, buildEnv);
|
|
214
192
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const cleanFlags = (flags) => flags.filter((item) => !/^--[\w.]+ (\{\}|\[\]|)$/.test(item));
|
|
218
|
-
if (opts.platform === 'app-harmony') {
|
|
219
|
-
if (opts.wgt) {
|
|
220
|
-
cmds = ['publish', 'app-harmony', '--type', 'wgt', ...prepareWgtFlags(platform.app(opts).wgt).flags];
|
|
221
|
-
}
|
|
222
|
-
else if (opts.res) {
|
|
223
|
-
cmds = ['publish', 'app-harmony', '--type', 'appResource'];
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
cmds = ['pack', 'app-harmony'];
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
else if (opts.platform.startsWith('app')) {
|
|
230
|
-
const app = platform.app(opts);
|
|
231
|
-
if (opts.wgt) {
|
|
232
|
-
cmds = ['publish', opts.platform, '--type', 'wgt', ...prepareWgtFlags(app.wgt).flags];
|
|
233
|
-
}
|
|
234
|
-
else if (opts.res) {
|
|
235
|
-
cmds = ['publish', opts.platform, '--type', 'appResource'];
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
const packPlatform = opts.platform === 'app' ? 'android,ios' : opts.platform.replace('app-', '');
|
|
239
|
-
cmds = [
|
|
240
|
-
'pack',
|
|
241
|
-
'--platform',
|
|
242
|
-
packPlatform,
|
|
243
|
-
...cleanFlags(app.common),
|
|
244
|
-
...cleanFlags(app.android),
|
|
245
|
-
...cleanFlags(app.ios),
|
|
246
|
-
];
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
else if (opts.platform === 'mp-weixin') {
|
|
250
|
-
const manifest = (0, utils_1.readManifest)();
|
|
251
|
-
const appid = manifest['mp-weixin']?.appid;
|
|
252
|
-
cmds = ['publish', 'mp-weixin', ...(appid ? ['--appid', appid] : []), ...platform.mp().common];
|
|
253
|
-
}
|
|
254
|
-
else if (opts.platform === 'h5') {
|
|
255
|
-
cmds = ['publish', 'web', ...platform.h5()];
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
utils_1.log.error(`uni-app x 仅支持 h5/web、mp-weixin、app、app-android、app-ios、app-harmony 平台,当前平台:${opts.platform}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
else if (opts.platform.startsWith('app')) {
|
|
193
|
+
const cleanFlags = (flags) => flags.filter((item) => !/^--[\w.]+ (\{\}|\[\]|)$/.test(item));
|
|
194
|
+
if (opts.platform.startsWith('app')) {
|
|
262
195
|
const app = platform.app(opts);
|
|
196
|
+
const isHarmony = opts.platform === 'app-harmony';
|
|
263
197
|
if (opts.wgt) {
|
|
264
198
|
if (opts.pack) {
|
|
265
199
|
// HBuilderX CLI publish 流程
|
|
@@ -274,7 +208,12 @@ async function getCommands(...args) {
|
|
|
274
208
|
if (manifest.appid) {
|
|
275
209
|
(0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
|
|
276
210
|
}
|
|
277
|
-
cmds = [
|
|
211
|
+
cmds = [
|
|
212
|
+
'publish',
|
|
213
|
+
isHarmony ? opts.platform : `--platform ${opts.platform === 'app' ? 'APP' : opts.platform}`,
|
|
214
|
+
'--type wgt',
|
|
215
|
+
...app.wgt,
|
|
216
|
+
];
|
|
278
217
|
}
|
|
279
218
|
else {
|
|
280
219
|
// 普通构建,后续由 generatePackage 打包 wgt
|
|
@@ -283,29 +222,32 @@ async function getCommands(...args) {
|
|
|
283
222
|
}
|
|
284
223
|
}
|
|
285
224
|
else if (opts.res) {
|
|
286
|
-
cmds = [
|
|
225
|
+
cmds = [
|
|
226
|
+
'publish',
|
|
227
|
+
isHarmony ? opts.platform : `--platform ${opts.platform === 'app' ? 'APP' : opts.platform}`,
|
|
228
|
+
'--type appResource',
|
|
229
|
+
];
|
|
287
230
|
}
|
|
288
231
|
else {
|
|
289
232
|
cmds = ['pack', '--platform'];
|
|
290
233
|
if (opts.platform === 'app') {
|
|
291
|
-
|
|
292
|
-
cmds = [...cmds, _platform, ...app.common, ...app.android, ...app.ios];
|
|
234
|
+
cmds = [...cmds, 'android,ios', ...cleanFlags([...app.common, ...app.android, ...app.ios])];
|
|
293
235
|
}
|
|
294
236
|
else {
|
|
295
237
|
const _platform = opts.platform.replace('app-', '');
|
|
296
|
-
cmds = [...cmds, _platform, ...app.common, ...app[_platform]];
|
|
238
|
+
cmds = [...cmds, _platform, ...cleanFlags([...app.common, ...(app[_platform] ?? [])])];
|
|
297
239
|
}
|
|
298
240
|
}
|
|
299
241
|
}
|
|
300
242
|
else if (opts.platform.startsWith('mp')) {
|
|
301
243
|
const mp = platform.mp();
|
|
302
244
|
const manifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(utils_1.MAINFEST_PATH).toString()));
|
|
245
|
+
const appid = manifest[opts.platform]?.appid;
|
|
303
246
|
cmds = [
|
|
304
247
|
'publish',
|
|
305
248
|
'--platform',
|
|
306
249
|
opts.platform.toUpperCase(),
|
|
307
|
-
'--appid',
|
|
308
|
-
manifest[opts.platform].appid,
|
|
250
|
+
...(appid ? ['--appid', appid] : []),
|
|
309
251
|
...mp.common,
|
|
310
252
|
];
|
|
311
253
|
}
|
|
@@ -313,8 +255,12 @@ async function getCommands(...args) {
|
|
|
313
255
|
const h5 = platform.h5();
|
|
314
256
|
cmds = ['publish', '--platform h5', ...h5];
|
|
315
257
|
}
|
|
258
|
+
else {
|
|
259
|
+
utils_1.log.error(`不支持的平台:${opts.platform}`);
|
|
260
|
+
}
|
|
316
261
|
if (cmds) {
|
|
317
|
-
|
|
262
|
+
// HBuilderX CLI 的 --project 支持绝对路径:统一传工程目录(--source 时为源码工程目录),无需先 project open
|
|
263
|
+
commands = [...commands, config_1.CONFIG_DATA?.cli?.hbuilderx, ...cmds, '--project', projectPath];
|
|
318
264
|
}
|
|
319
265
|
}
|
|
320
266
|
}
|
|
@@ -344,15 +290,6 @@ async function getCommands(...args) {
|
|
|
344
290
|
else {
|
|
345
291
|
commands = [...commands, bin, 'build'];
|
|
346
292
|
}
|
|
347
|
-
// 走 HBuilderX 且无 package.json 的 uni-app x 工程无法保证 cross-env 可执行,直接通过进程环境变量传递
|
|
348
|
-
if (isUniappX &&
|
|
349
|
-
opts.compiler === 'uni' &&
|
|
350
|
-
useHBuilderX &&
|
|
351
|
-
!(0, fs_1.existsSync)(utils_1.PACKAGE_PATH) &&
|
|
352
|
-
commands[0] === 'cross-env') {
|
|
353
|
-
process.env.NODE_ENV = 'production';
|
|
354
|
-
commands = commands.slice(2).filter((item) => !/^(NODE_ENV|BUILD_ENV)=/.test(item));
|
|
355
|
-
}
|
|
356
293
|
return commands;
|
|
357
294
|
}
|
|
358
295
|
function generateH5Manifest() {
|
|
@@ -434,31 +371,6 @@ function downloadFile(url, dest) {
|
|
|
434
371
|
.on('error', rej);
|
|
435
372
|
});
|
|
436
373
|
}
|
|
437
|
-
/**
|
|
438
|
-
* 调用 HBuilderX CLI 对 .repo 工程执行 project open/close
|
|
439
|
-
* - open 用于让 HBuilderX 加载最新的 manifest.json / package.json
|
|
440
|
-
* - close 用于构建后释放项目
|
|
441
|
-
* 错误在本函数内处理:open 失败提示并退出,close 失败仅告警
|
|
442
|
-
*/
|
|
443
|
-
function runHBuilderXProject(action, repoDir) {
|
|
444
|
-
const hbuilderxCli = config_1.CONFIG_DATA?.cli?.hbuilderx;
|
|
445
|
-
if (!hbuilderxCli) {
|
|
446
|
-
utils_1.log.error('HbuilderX Cli路径不正确,请执行“gmcb config --cli.hbuilderx <cli-path>”设置正确的路径!');
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
try {
|
|
450
|
-
(0, child_process_1.execSync)(`"${hbuilderxCli}" project ${action} --path "${repoDir}"`, { cwd: repoDir, stdio: 'inherit' });
|
|
451
|
-
}
|
|
452
|
-
catch (err) {
|
|
453
|
-
const message = err?.message || String(err);
|
|
454
|
-
if (action === 'open') {
|
|
455
|
-
utils_1.log.error(`打开 HBuilderX 项目失败:${message}`);
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
utils_1.log.warning(`关闭 HBuilderX 项目失败:${message}`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
374
|
async function pullRemoteResources(opts) {
|
|
463
375
|
const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
|
|
464
376
|
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
@@ -549,10 +461,7 @@ async function pullRemoteResources(opts) {
|
|
|
549
461
|
}
|
|
550
462
|
}
|
|
551
463
|
if (opts.compiler === 'gradlew') {
|
|
552
|
-
// 构建 App 并拷贝:构建前 open 让 HBuilderX 加载最新工程信息,构建后 close
|
|
553
|
-
runHBuilderXProject('open', repoDir);
|
|
554
464
|
(0, child_process_1.execSync)(`npm run build:android:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
|
|
555
|
-
runHBuilderXProject('close', repoDir);
|
|
556
465
|
(0, child_process_1.execSync)('npm run copy:android', { cwd: repoDir, stdio: 'inherit' });
|
|
557
466
|
// 修改主项目 strings.xml 中的应用名称
|
|
558
467
|
const stringsPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
|
|
@@ -606,8 +515,6 @@ async function default_1(...args) {
|
|
|
606
515
|
const deferRestore = args[args.length - 1] === true;
|
|
607
516
|
const commands = await getCommands(...args);
|
|
608
517
|
const command = commands.join(' ');
|
|
609
|
-
// uni-app x 的 App 产物(含 wgt)由 HBuilderX 产出,不再走本地二次打包
|
|
610
|
-
const isUniappXApp = (0, utils_1.isUniappXManifest)() && !!opts.platform?.startsWith('app');
|
|
611
518
|
remoteBackups.clear();
|
|
612
519
|
if (opts.latest) {
|
|
613
520
|
await syncLatestVersion();
|
|
@@ -634,7 +541,7 @@ async function default_1(...args) {
|
|
|
634
541
|
}
|
|
635
542
|
if ((opts.compiler === 'electron-vite' && (opts.zip || opts.win)) ||
|
|
636
543
|
(opts.compiler === 'uni' && opts.platform === 'h5' && opts.zip) ||
|
|
637
|
-
(opts.compiler === 'uni' && opts.platform?.startsWith('app') && opts.wgt && !opts.pack
|
|
544
|
+
(opts.compiler === 'uni' && opts.platform?.startsWith('app') && opts.wgt && !opts.pack) ||
|
|
638
545
|
(opts.compiler === 'gradlew' && opts.apk)) {
|
|
639
546
|
await generatePackage(opts);
|
|
640
547
|
}
|
package/lib/actions/publish.js
CHANGED
|
@@ -34,9 +34,8 @@ const build_1 = __importStar(require("./build"));
|
|
|
34
34
|
const config_1 = require("../utils/config");
|
|
35
35
|
async function default_1(...args) {
|
|
36
36
|
const opts = args[0];
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
opts.platform = (0, utils_1.normalizePlatform)(opts.platform);
|
|
37
|
+
if (opts.platform === 'web') {
|
|
38
|
+
opts.platform = 'h5';
|
|
40
39
|
}
|
|
41
40
|
const isPublishFlow = !!config_1.CONFIG_DATA.publish;
|
|
42
41
|
const isAuto = opts.skip || !!config_1.CONFIG_DATA.skip;
|
|
@@ -226,15 +225,8 @@ async function default_1(...args) {
|
|
|
226
225
|
try {
|
|
227
226
|
let cmds;
|
|
228
227
|
if (opts.compiler === 'uni' && opts.wgt && opts.zip) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
opts.platform = 'app';
|
|
232
|
-
cmds = await (0, build_1.default)(opts, true);
|
|
233
|
-
// 再构建 h5(生成 zip)
|
|
234
|
-
opts.platform = 'h5';
|
|
235
|
-
await (0, build_1.default)(opts, true);
|
|
236
|
-
// 恢复
|
|
237
|
-
opts.platform = originalPlatform;
|
|
228
|
+
cmds = await (0, build_1.default)({ ...opts, platform: 'app' }, true);
|
|
229
|
+
await (0, build_1.default)({ ...opts, platform: 'h5' }, true);
|
|
238
230
|
}
|
|
239
231
|
else {
|
|
240
232
|
cmds = await (0, build_1.default)(opts, true);
|
package/lib/commands/option.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PLATFORM_OPTIONS, COMPILER_OPTIONS } from '../utils';
|
|
2
2
|
export declare const version: readonly ["-v, --version", "输出版本号"];
|
|
3
3
|
export declare const template: readonly ["-t, --template <template-name>", "模版仓库名称"];
|
|
4
|
-
export declare const platform: readonly ["-p, --platform <platform-name>", "编译平台,默认h5", "h5"];
|
|
4
|
+
export declare const platform: readonly ["-p, --platform <platform-name>", "编译平台,默认h5(web 等价 h5)", "h5"];
|
|
5
5
|
export declare const project: readonly ["-P, --project <project-name>", "HbuilderX工作台中的项目名称"];
|
|
6
6
|
export declare const compiler: readonly ["-c, --compiler <compiler-name>", "构建工具,默认uni", "uni"];
|
|
7
7
|
export declare const env: readonly ["-e, --env <env-name>", "构建环境,可选如dev/sit/uat/prod等"];
|
|
@@ -46,7 +46,7 @@ export declare const templateRepo: readonly ["--template.repo <repo-url>", "项
|
|
|
46
46
|
export interface Options {
|
|
47
47
|
template?: string;
|
|
48
48
|
branch?: string | boolean;
|
|
49
|
-
platform?: (typeof PLATFORM_OPTIONS)[number];
|
|
49
|
+
platform?: (typeof PLATFORM_OPTIONS)[number] | 'web';
|
|
50
50
|
compiler?: (typeof COMPILER_OPTIONS)[number];
|
|
51
51
|
project?: string;
|
|
52
52
|
env?: string;
|
package/lib/commands/option.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.templateRepo = exports.skillRepo = exports.cosSecretkey = exports.cosSecretid = exports.alipayCli = exports.weixinCli = exports.hbuilderxCli = exports.bg = exports.top = exports.left = exports.height = exports.width = exports.ico = exports.sizes = exports.size = exports.radius = exports.nobuild = exports.restore = exports.latest = exports.pull = exports.skip = exports.apk = exports.res = exports.wgt = exports.pack = exports.custom = exports.zip = exports.linux = exports.mac = exports.win = exports.link = exports.path = exports.name = exports.clean = exports.ignore = exports.dest = exports.source = exports.branch = exports.env = exports.compiler = exports.project = exports.platform = exports.template = exports.version = void 0;
|
|
4
4
|
exports.version = ['-v, --version', '输出版本号'];
|
|
5
5
|
exports.template = ['-t, --template <template-name>', '模版仓库名称'];
|
|
6
|
-
exports.platform = ['-p, --platform <platform-name>', '编译平台,默认h5', 'h5'];
|
|
6
|
+
exports.platform = ['-p, --platform <platform-name>', '编译平台,默认h5(web 等价 h5)', 'h5'];
|
|
7
7
|
exports.project = ['-P, --project <project-name>', 'HbuilderX工作台中的项目名称'];
|
|
8
8
|
exports.compiler = ['-c, --compiler <compiler-name>', '构建工具,默认uni', 'uni'];
|
|
9
9
|
exports.env = ['-e, --env <env-name>', '构建环境,可选如dev/sit/uat/prod等'];
|
package/lib/commands/platform.js
CHANGED
|
@@ -34,10 +34,12 @@ const app = (opts) => {
|
|
|
34
34
|
const android = (0, utils_1.filterToArray)(androidCommand);
|
|
35
35
|
const ios = (0, utils_1.filterToArray)(iosCommand);
|
|
36
36
|
const wgt = (0, utils_1.filterToArray)(wgtCommand);
|
|
37
|
+
const harmony = [];
|
|
37
38
|
return {
|
|
38
39
|
common,
|
|
39
40
|
android,
|
|
40
41
|
ios,
|
|
42
|
+
harmony,
|
|
41
43
|
wgt,
|
|
42
44
|
};
|
|
43
45
|
};
|
package/lib/utils/function.d.ts
CHANGED
|
@@ -3,10 +3,6 @@ export declare function readManifest(): Record<string, unknown>;
|
|
|
3
3
|
* 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
|
|
4
4
|
*/
|
|
5
5
|
export declare function isUniappXManifest(manifest?: Record<string, unknown>): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* 平台名归一化:web 是 HBuilderX 5.x 的平台名,等价 h5
|
|
8
|
-
*/
|
|
9
|
-
export declare function normalizePlatform(platform?: string): string;
|
|
10
6
|
export declare function objectToCommand(obj?: Record<string, any>): {};
|
|
11
7
|
export declare function filterToArray(obj?: Record<string, any>): any[];
|
|
12
8
|
export declare function spawnSync(command?: string): import("child_process").SpawnSyncReturns<Buffer>;
|
package/lib/utils/function.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.readManifest = readManifest;
|
|
7
7
|
exports.isUniappXManifest = isUniappXManifest;
|
|
8
|
-
exports.normalizePlatform = normalizePlatform;
|
|
9
8
|
exports.objectToCommand = objectToCommand;
|
|
10
9
|
exports.filterToArray = filterToArray;
|
|
11
10
|
exports.spawnSync = spawnSync;
|
|
@@ -34,15 +33,6 @@ function readManifest() {
|
|
|
34
33
|
function isUniappXManifest(manifest = readManifest()) {
|
|
35
34
|
return Object.prototype.hasOwnProperty.call(manifest, 'uni-app-x');
|
|
36
35
|
}
|
|
37
|
-
/**
|
|
38
|
-
* 平台名归一化:web 是 HBuilderX 5.x 的平台名,等价 h5
|
|
39
|
-
*/
|
|
40
|
-
function normalizePlatform(platform) {
|
|
41
|
-
if (!platform) {
|
|
42
|
-
return 'h5';
|
|
43
|
-
}
|
|
44
|
-
return platform === 'web' ? 'h5' : platform;
|
|
45
|
-
}
|
|
46
36
|
function objectToCommand(obj = {}) {
|
|
47
37
|
const object = (0, flat_1.flatten)(obj);
|
|
48
38
|
const res = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmcb/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "工茂草本前端命令行工具",
|
|
5
5
|
"author": "yinjiazeng@163.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"@types/rimraf": "^4.0.5",
|
|
59
59
|
"@types/user-home": "^2.0.2"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "9035e1ec3a89eb7d2c864ce0c0280e48759e2d04"
|
|
62
62
|
}
|