@gmcb/cli 0.9.0 → 0.9.2

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 CHANGED
@@ -3,6 +3,22 @@
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.2](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.1...@gmcb/cli@0.9.2) (2026-11-02)
7
+
8
+ **Note:** Version bump only for package @gmcb/cli
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.9.1](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.9.0...@gmcb/cli@0.9.1) (2026-10-29)
15
+
16
+ **Note:** Version bump only for package @gmcb/cli
17
+
18
+
19
+
20
+
21
+
6
22
  # [0.9.0](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.13...@gmcb/cli@0.9.0) (2026-10-29)
7
23
 
8
24
 
package/README.md CHANGED
@@ -19,7 +19,7 @@ npm i @gmcb/cli -g
19
19
  | `gmcb copy` | 复制资源到指定目录 |
20
20
  | `gmcb config` | 配置管理 |
21
21
  | `gmcb icon` | 生成应用图标(圆角 PNG / ICO) |
22
- | `gmcb splash` | 按 LOGO 生成启动图(白底 + 可选 9-patch 边框) |
22
+ | `gmcb image` | 按 LOGO 生成启动图(白底 + 可选 9-patch 边框) |
23
23
  | `gmcb skill sync` | 同步技能到本地项目 |
24
24
  | `gmcb skill list` | 列出当前项目所有技能 |
25
25
 
@@ -29,11 +29,12 @@ npm i @gmcb/cli -g
29
29
 
30
30
  | 选项 | 描述 |
31
31
  |---|---|
32
- | `-p, --platform` | 编译平台,默认 h5 |
32
+ | `-p, --platform` | 编译平台,默认 h5(uni-app x 可用 web,等价 h5) |
33
33
  | `-c, --compiler` | 构建工具,默认 uni |
34
34
  | `-b, --branch` | Git 分支名称 |
35
35
  | `-e, --env` | 构建环境,默认 prod |
36
36
  | `--wgt` | 构建移动应用热更新资源 |
37
+ | `--res` | 构建移动应用本地资源(uni-app x 导出 appResource) |
37
38
  | `--zip` | 构建桌面应用热更新资源 |
38
39
  | `--apk` | 构建 Android 应用 |
39
40
  | `--nobuild` | 跳过构建步骤,仅执行后续流程(打包、远程资源拉取等) |
@@ -96,6 +97,68 @@ gmcb publish -p app --wgt -a
96
97
  - `pub`:基础发布配置(brand、type、status、platform、path)
97
98
  - `publish`:魔方发布配置(updateType、versionDesc、publishType、platform、path),配置后走魔方发布流程
98
99
 
100
+ ## uni-app x 兼容
101
+
102
+ `gmcb build` / `gmcb publish` 兼容 uni-app x 工程;**非 src 的经典 uni-app 工程与含 src 的经典 uni-app 工程的打包逻辑保持不变**。
103
+
104
+ ### 识别与前提
105
+
106
+ - 项目根目录 `manifest.json` 含 `uni-app-x` 字段(如 `"uni-app-x": {}`)即识别为 uni-app x 工程;uni-app x 只支持 HBuilderX 工程(无 `src` 目录),CLI 自动使用 `cli.hbuilderx` 编译,不需要 `--pack`
107
+ - HBuilderX 4.67+(蒸汽模式 wgt 需要 5.33+),需启动 HBuilderX 且项目已导入,CLI 路径用 `gmcb config --cli.hbuilderx <cli-path>` 配置
108
+ - `-p web` 是 `-p h5` 的别名(仅 uni-app x)
109
+
110
+ ### 平台与命令行映射
111
+
112
+ | `-p` 平台 | 附加参数 | 执行的 HBuilderX 命令 | 输出目录 |
113
+ |---|---|---|---|
114
+ | `h5` / `web` | - | `publish web` | `unpackage/dist/build/web` |
115
+ | `mp-weixin` | - | `publish mp-weixin [--appid ...]` | `unpackage/dist/build/mp-weixin` |
116
+ | `app` / `app-android` / `app-ios` | `--res` | `publish <app\|app-android\|app-ios> --type appResource` | `unpackage/resources/app-*`(`-p app` 同时导出 app-android、app-ios) |
117
+ | `app` / `app-android` / `app-ios` | `--wgt` | `publish <target> --type wgt` | `unpackage/release/<平台>/<AppID>.wgt`(平台为 app-android / app-ios,`-p app` 导出两个平台) |
118
+ | `app` / `app-android` / `app-ios` | 无 | `pack --platform android,ios\|android\|ios` | 云端打包 |
119
+ | `app-harmony` | `--res` / `--wgt` / 无 | `publish app-harmony --type appResource\|wgt` / `pack app-harmony` | `unpackage/resources/app-harmony` 等 |
120
+
121
+ - uni-app x 的 `--wgt` 仅蒸汽模式(`manifest.json` 的 `"uni-app-x": { "vapor": true }`)支持,由 HBuilderX 校验
122
+ - `--res` 产物结构随编译模式不同:VDOM 模式包含 `uniappx/app-android/src/**/*.kt` 等页面 Kotlin 源码;蒸汽模式(vapor)为 `__UNI__xxx/www/bytes/**/*.bytes` + `app-service.js`,不含 Kotlin 源码
123
+ - `--wgt` 产物按平台分子目录(`unpackage/release/app-android/<AppID>.wgt`、`app-ios/<AppID>.wgt`);`gmcb publish --wgt` 上传时可在 `uni.build.json` 的 `app.wgt.path` / `app.wgt.name` 指向对应平台目录与文件名(一次一个平台),或直接手动上传
124
+ - `mp-weixin` 的 `appid` 取 `manifest.json` 的 `mp-weixin.appid`,有值时才传 `--appid`;appid 为空时仍可编译出产物,但 HBuilderX 会尝试打开微信开发者工具并提示 appid 不存在,配置 appid 后即可正常使用;发布上传时为空会给出明确错误
125
+ - 云打包的证书/包名等配置与经典 uni-app 相同(`uni.build.json` 的 `app.android` / `app.ios`)
126
+ - 完整示例见 `examples/uniappx`(蒸汽模式工程),可直接验证下列命令
127
+
128
+ ### 无 package.json 的工程
129
+
130
+ uni-app x 的 HBuilderX 工程通常没有 `package.json`:
131
+
132
+ - `--latest` 从 `manifest.json` 读取并回写 `versionName` / `versionCode`,找不到 `appid` 时跳过同步
133
+ - `gmcb publish` 检测不到 `package.json` 时跳过依赖安装并提示,构建命令也不再依赖 `cross-env`
134
+
135
+ 示例(完整可运行示例见 `examples/uniappx`):
136
+
137
+ ```bash
138
+ # H5 / web
139
+ gmcb build -p h5
140
+ gmcb build -p web
141
+
142
+ # App 本地打包资源(-p app 同时导出 android/ios;app-android 只导出 Android)
143
+ gmcb build -p app --res
144
+ gmcb build -p app-android --res
145
+
146
+ # 蒸汽模式 wgt(产物在 unpackage/release/app-android、app-ios 平台子目录)
147
+ gmcb build -p app-android --wgt
148
+
149
+ # H5 资源 zip(unpackage/release/<AppID>.zip)
150
+ gmcb build -p h5 --zip
151
+
152
+ # App 云打包
153
+ gmcb build -p app-android -e prod
154
+
155
+ # 微信小程序
156
+ gmcb build -p mp-weixin
157
+
158
+ # 鸿蒙本地打包
159
+ gmcb build -p app-harmony
160
+ ```
161
+
99
162
  ## `gmcb icon`
100
163
 
101
164
  根据源图片生成带圆角的应用图标,可选输出 ICO 文件。
@@ -128,7 +191,7 @@ gmcb icon --source logo.png --sizes 64,128,256
128
191
  gmcb icon --source logo.png --radius 24 --ico --dest out
129
192
  ```
130
193
 
131
- ## `gmcb splash`
194
+ ## `gmcb image`
132
195
 
133
196
  按品牌 LOGO 生成启动图:默认白底、LOGO 水平居中,按画布比例计算 LOGO 尺寸,不依赖项目模板。适用于白标项目换品牌时生成/更新 `splash.9.png`。
134
197
 
@@ -155,16 +218,16 @@ gmcb icon --source logo.png --radius 24 --ico --dest out
155
218
 
156
219
  ```bash
157
220
  # uni-app 项目:直接生成/更新 static/splash.9.png
158
- gmcb splash -s ./static/appIcon.png
221
+ gmcb image -s ./static/appIcon.png
159
222
 
160
223
  # 生成普通 PNG(无 9-patch 边框)
161
- gmcb splash -s ./logo.png --name splash
224
+ gmcb image -s ./logo.png --name splash
162
225
 
163
226
  # 左右各留 40%,LOGO 宽度为画布 20%,距顶部 20%
164
- gmcb splash -s ./logo.png --left 40% --top 20%
227
+ gmcb image -s ./logo.png --left 40% --top 20%
165
228
 
166
229
  # 自定义画布与位置
167
- gmcb splash -s ./logo.png --width 2050 --height 1538 --left 500 --top 200 --bg '#f7f7f7'
230
+ gmcb image -s ./logo.png --width 2050 --height 1538 --left 500 --top 200 --bg '#f7f7f7'
168
231
  ```
169
232
 
170
233
  ## `gmcb copy`
@@ -74,14 +74,20 @@ async function restoreLocalResources(restore) {
74
74
  }
75
75
  async function syncLatestVersion() {
76
76
  const spinner = (0, ora_1.default)('正在获取最新版本数据...').start();
77
- const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
78
- const appId = pkg.appId;
77
+ const hasPackage = (0, fs_1.existsSync)(utils_1.PACKAGE_PATH);
78
+ const pkg = hasPackage ? (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH) : {};
79
+ const manifest = (0, utils_1.readManifest)();
80
+ const appId = pkg.appId || ((0, utils_1.isUniappXManifest)(manifest) ? manifest.appid : undefined);
81
+ if (!appId) {
82
+ spinner.warn('未在 package.json 或 manifest.json 中找到 appId/appid,跳过版本号同步');
83
+ return;
84
+ }
79
85
  const { versionName, versionCode, updateMode } = await (0, apis_1.fetchLatestVersion)({
80
86
  appId,
81
87
  platform: config_1.CONFIG_DATA.publish?.platform,
82
88
  publishType: config_1.CONFIG_DATA.publish?.publishType,
83
89
  });
84
- if (updateMode) {
90
+ if (updateMode && config_1.CONFIG_DATA.publish) {
85
91
  config_1.CONFIG_DATA.publish.updateMode = updateMode;
86
92
  }
87
93
  if (versionName && versionCode) {
@@ -95,7 +101,7 @@ async function syncLatestVersion() {
95
101
  (0, fs_1.writeFileSync)(utils_1.MAINFEST_PATH, content);
96
102
  }
97
103
  }
98
- else {
104
+ else if (hasPackage) {
99
105
  const localVersionCode = Number(pkg.versionCode || 0);
100
106
  if (localVersionCode < versionCode) {
101
107
  let pkgContent = (0, fs_1.readFileSync)(utils_1.PACKAGE_PATH, 'utf-8');
@@ -105,11 +111,43 @@ async function syncLatestVersion() {
105
111
  (0, fs_1.writeFileSync)(utils_1.PACKAGE_PATH, pkgContent);
106
112
  }
107
113
  }
114
+ else {
115
+ utils_1.log.warning('未找到 manifest.json 或 package.json,跳过版本号同步');
116
+ }
108
117
  }
109
118
  spinner.stop();
110
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
+ }
111
144
  async function getCommands(...args) {
112
145
  const opts = args[0];
146
+ const isUniappX = (0, utils_1.isUniappXManifest)();
147
+ if (isUniappX) {
148
+ // uni-app x 使用 HBuilderX 5.x 平台名:-p web 等价 -p h5(经典 uni-app 保持原有行为)
149
+ opts.platform = (0, utils_1.normalizePlatform)(opts.platform);
150
+ }
113
151
  if (config_1.CONFIG_DATA.branch && config_1.CONFIG_DATA.branch !== 'false') {
114
152
  opts.branch = config_1.CONFIG_DATA.branch;
115
153
  }
@@ -169,7 +207,53 @@ async function getCommands(...args) {
169
207
  }
170
208
  (0, fs_1.writeFileSync)(envPath, buildEnv);
171
209
  }
172
- if (opts.platform.startsWith('app')) {
210
+ if (isUniappX) {
211
+ // uni-app x 使用 HBuilderX 5.x 子命令形式(经典 uni-app 分支保持不变)
212
+ const cleanFlags = (flags) => flags.filter((item) => !/^--[\w.]+ (\{\}|\[\]|)$/.test(item));
213
+ if (opts.platform === 'app-harmony') {
214
+ if (opts.wgt) {
215
+ cmds = ['publish', 'app-harmony', '--type', 'wgt', ...prepareWgtFlags(platform.app(opts).wgt).flags];
216
+ }
217
+ else if (opts.res) {
218
+ cmds = ['publish', 'app-harmony', '--type', 'appResource'];
219
+ }
220
+ else {
221
+ cmds = ['pack', 'app-harmony'];
222
+ }
223
+ }
224
+ else if (opts.platform.startsWith('app')) {
225
+ const app = platform.app(opts);
226
+ if (opts.wgt) {
227
+ cmds = ['publish', opts.platform, '--type', 'wgt', ...prepareWgtFlags(app.wgt).flags];
228
+ }
229
+ else if (opts.res) {
230
+ cmds = ['publish', opts.platform, '--type', 'appResource'];
231
+ }
232
+ else {
233
+ const packPlatform = opts.platform === 'app' ? 'android,ios' : opts.platform.replace('app-', '');
234
+ cmds = [
235
+ 'pack',
236
+ '--platform',
237
+ packPlatform,
238
+ ...cleanFlags(app.common),
239
+ ...cleanFlags(app.android),
240
+ ...cleanFlags(app.ios),
241
+ ];
242
+ }
243
+ }
244
+ else if (opts.platform === 'mp-weixin') {
245
+ const manifest = (0, utils_1.readManifest)();
246
+ const appid = manifest['mp-weixin']?.appid;
247
+ cmds = ['publish', 'mp-weixin', ...(appid ? ['--appid', appid] : []), ...platform.mp().common];
248
+ }
249
+ else if (opts.platform === 'h5') {
250
+ cmds = ['publish', 'web', ...platform.h5()];
251
+ }
252
+ else {
253
+ utils_1.log.error(`uni-app x 仅支持 h5/web、mp-weixin、app、app-android、app-ios、app-harmony 平台,当前平台:${opts.platform}`);
254
+ }
255
+ }
256
+ else if (opts.platform.startsWith('app')) {
173
257
  const app = platform.app(opts);
174
258
  if (opts.wgt) {
175
259
  if (opts.pack) {
@@ -255,6 +339,11 @@ async function getCommands(...args) {
255
339
  else {
256
340
  commands = [...commands, bin, 'build'];
257
341
  }
342
+ // 无 package.json 的 uni-app x HBuilderX 工程无法保证 cross-env 可执行,直接通过进程环境变量传递
343
+ if (isUniappX && opts.compiler === 'uni' && !utils_1.HAS_SRC && !(0, fs_1.existsSync)(utils_1.PACKAGE_PATH) && commands[0] === 'cross-env') {
344
+ process.env.NODE_ENV = 'production';
345
+ commands = commands.slice(2).filter((item) => !/^(NODE_ENV|BUILD_ENV)=/.test(item));
346
+ }
258
347
  return commands;
259
348
  }
260
349
  function generateH5Manifest() {
@@ -309,7 +398,7 @@ async function generatePackage(opts) {
309
398
  if ((0, fs_1.existsSync)(dest)) {
310
399
  (0, fs_1.unlinkSync)(dest);
311
400
  }
312
- const zipRoot = compiler === 'uni' && platform === 'h5' ? (pkg.appId || '') : '';
401
+ const zipRoot = compiler === 'uni' && platform === 'h5' ? pkg.appId || '' : '';
313
402
  zip.addLocalFolder(source, zipRoot);
314
403
  zip.writeZip(dest);
315
404
  }
@@ -319,16 +408,21 @@ async function generatePackage(opts) {
319
408
  function downloadFile(url, dest) {
320
409
  return new Promise((res, rej) => {
321
410
  const mod = url.startsWith('https') ? https_1.default : http_1.default;
322
- mod.get(url, (response) => {
411
+ mod
412
+ .get(url, (response) => {
323
413
  if (response.statusCode === 301 || response.statusCode === 302) {
324
414
  downloadFile(response.headers.location, dest).then(res, rej);
325
415
  return;
326
416
  }
327
417
  const ws = require('fs').createWriteStream(dest);
328
418
  response.pipe(ws);
329
- ws.on('finish', () => { ws.close(); res(); });
419
+ ws.on('finish', () => {
420
+ ws.close();
421
+ res();
422
+ });
330
423
  ws.on('error', rej);
331
- }).on('error', rej);
424
+ })
425
+ .on('error', rej);
332
426
  });
333
427
  }
334
428
  async function pullRemoteResources(opts) {
@@ -387,8 +481,10 @@ async function pullRemoteResources(opts) {
387
481
  const repoPkg = (0, fs_extra_1.readJsonSync)(repoPkgPath);
388
482
  if (!repoPkg.scripts)
389
483
  repoPkg.scripts = {};
484
+ repoPkg.appId = appId;
390
485
  repoPkg.scripts['copy:h5'] = 'gmcb copy -s ./dist/build/h5 -d ../../out/renderer/{package.appId}/ --clean';
391
- repoPkg.scripts['copy:app'] = 'gmcb copy -s ./dist/build/app -d ../../app/src/main/assets/apps/{manifest.appid}/www/ --clean';
486
+ repoPkg.scripts['copy:app'] =
487
+ 'gmcb copy -s ./dist/build/app -d ../../app/src/main/assets/apps/{manifest.appid}/www/ --clean';
392
488
  (0, fs_extra_1.writeJsonSync)(repoPkgPath, repoPkg, { spaces: 2 });
393
489
  // 7. 执行 npm install
394
490
  (0, child_process_1.execSync)('npm install', { cwd: repoDir, stdio: 'inherit' });
@@ -482,7 +578,7 @@ async function default_1(...args) {
482
578
  const time = Date.now();
483
579
  (0, utils_1.spawnSync)(command);
484
580
  if ((Date.now() - time) / 1000 <= 1) {
485
- if (command.includes(config_1.CONFIG_DATA.cli.hbuilderx)) {
581
+ if (config_1.CONFIG_DATA.cli?.hbuilderx && command.includes(config_1.CONFIG_DATA.cli.hbuilderx)) {
486
582
  utils_1.log.error('检测到您的HbuilderX未启动或项目管理器中未发现构建项目,请检查后重试!');
487
583
  }
488
584
  }
@@ -497,7 +593,7 @@ async function default_1(...args) {
497
593
  if ((opts.compiler === 'electron-vite' && (opts.zip || opts.win)) ||
498
594
  (opts.compiler === 'uni' && opts.platform === 'h5' && opts.zip) ||
499
595
  (opts.compiler === 'uni' && opts.platform?.startsWith('app') && opts.wgt && !opts.pack) ||
500
- opts.compiler === 'gradlew' && opts.apk) {
596
+ (opts.compiler === 'gradlew' && opts.apk)) {
501
597
  await generatePackage(opts);
502
598
  }
503
599
  return commands;
@@ -27,12 +27,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.default = default_1;
30
+ const fs_1 = require("fs");
30
31
  const inquirer_1 = __importDefault(require("inquirer"));
31
32
  const utils_1 = require("../utils");
32
33
  const build_1 = __importStar(require("./build"));
33
34
  const config_1 = require("../utils/config");
34
35
  async function default_1(...args) {
35
36
  const opts = args[0];
37
+ if ((0, utils_1.isUniappXManifest)()) {
38
+ // uni-app x 使用 HBuilderX 5.x 平台名:-p web 等价 -p h5(经典 uni-app 保持原有行为)
39
+ opts.platform = (0, utils_1.normalizePlatform)(opts.platform);
40
+ }
36
41
  const isPublishFlow = !!config_1.CONFIG_DATA.publish;
37
42
  const isAuto = opts.skip || !!config_1.CONFIG_DATA.skip;
38
43
  const pub = { platform: 0, status: 0, updateType: 0, updateMode: 0 };
@@ -181,7 +186,13 @@ async function default_1(...args) {
181
186
  install = false;
182
187
  }
183
188
  if (install) {
184
- (0, utils_1.spawnSync)(config_1.CONFIG_DATA.install || 'npm install');
189
+ if ((0, fs_1.existsSync)(utils_1.PACKAGE_PATH)) {
190
+ (0, utils_1.spawnSync)(config_1.CONFIG_DATA.install || 'npm install');
191
+ }
192
+ else {
193
+ // uni-app x 的 HBuilderX 工程通常没有 package.json,无需安装依赖
194
+ utils_1.log.warning('未检测到 package.json,跳过依赖安装');
195
+ }
185
196
  }
186
197
  // 更新 CONFIG_DATA(build 之前,确保 fetchRemoteResources 能读取到)
187
198
  if (isPublishFlow) {
@@ -228,8 +239,8 @@ async function default_1(...args) {
228
239
  else {
229
240
  cmds = await (0, build_1.default)(opts, true);
230
241
  }
231
- // 从 cmds 提取 buildEnv
232
- const buildEnv = cmds[2]?.split('=')[1];
242
+ // 从 cmds 提取 buildEnv:无 package.json 的 uni-app x 工程命令中没有 cross-env/BUILD_ENV,回退到进程环境变量
243
+ const buildEnv = cmds.find((cmd) => cmd.startsWith('BUILD_ENV='))?.split('=')[1] || process.env.BUILD_ENV;
233
244
  if (!buildEnv || !['dev', 'sit', 'uat', 'pre', 'pro', 'prod'].includes(buildEnv)) {
234
245
  utils_1.log.error('没有检测到需要发布的环境,无法完成上传,请切换到dev/sit/uat/pre/master分支再次执行脚本,或者您可以选择手动上传!');
235
246
  }
package/lib/bin.js CHANGED
@@ -110,7 +110,7 @@ program
110
110
  .option(...commands_1.dest)
111
111
  .action(icon_1.default);
112
112
  program
113
- .command('splash')
113
+ .command('image')
114
114
  .description('按 LOGO 生成启动图(白底 + 可选 9-patch 边框)')
115
115
  .option(...commands_1.source)
116
116
  .option(...commands_1.dest)
@@ -9,8 +9,13 @@ const config_1 = require("../utils/config");
9
9
  async function default_1() {
10
10
  const buildEnv = process.env.BUILD_ENV || '';
11
11
  const manifest = (0, utils_1.readManifest)();
12
+ const appid = manifest['mp-weixin']?.appid;
13
+ // uni-app x 的 appid 为空时 miniprogram-ci 报错难以理解,这里提前给出明确提示(经典 uni-app 保持原有行为)
14
+ if (!appid && (0, utils_1.isUniappXManifest)(manifest)) {
15
+ utils_1.log.error('manifest.json 中未配置 mp-weixin.appid,无法上传微信小程序,请先在 manifest.json 的 mp-weixin 节点中配置 appid!');
16
+ }
12
17
  const project = new miniprogram_ci_1.Project({
13
- appid: manifest['mp-weixin']?.appid,
18
+ appid,
14
19
  type: config_1.CONFIG_DATA?.mp?.weixin?.type ?? 'miniProgram',
15
20
  projectPath: (0, path_1.join)(process.cwd(), const_1.HAS_SRC ? '' : 'unpackage', 'dist/build/mp-weixin'),
16
21
  privateKeyPath: (0, path_1.resolve)(config_1.CONFIG_DATA?.mp?.weixin?.privatekey ?? ''),
@@ -1,4 +1,12 @@
1
1
  export declare function readManifest(): Record<string, unknown>;
2
+ /**
3
+ * 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
4
+ */
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;
2
10
  export declare function objectToCommand(obj?: Record<string, any>): {};
3
11
  export declare function filterToArray(obj?: Record<string, any>): any[];
4
12
  export declare function spawnSync(command?: string): import("child_process").SpawnSyncReturns<Buffer>;
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readManifest = readManifest;
7
+ exports.isUniappXManifest = isUniappXManifest;
8
+ exports.normalizePlatform = normalizePlatform;
7
9
  exports.objectToCommand = objectToCommand;
8
10
  exports.filterToArray = filterToArray;
9
11
  exports.spawnSync = spawnSync;
@@ -26,6 +28,21 @@ function readManifest() {
26
28
  }
27
29
  return {};
28
30
  }
31
+ /**
32
+ * 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
33
+ */
34
+ function isUniappXManifest(manifest = readManifest()) {
35
+ return Object.prototype.hasOwnProperty.call(manifest, 'uni-app-x');
36
+ }
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
+ }
29
46
  function objectToCommand(obj = {}) {
30
47
  const object = (0, flat_1.flatten)(obj);
31
48
  const res = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmcb/cli",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "工茂草本前端命令行工具",
5
5
  "author": "yinjiazeng@163.com",
6
6
  "license": "MIT",