@gmcb/cli 0.7.10 → 0.7.12

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.7.12](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.11...@gmcb/cli@0.7.12) (2026-07-14)
7
+
8
+ **Note:** Version bump only for package @gmcb/cli
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.7.11](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.10...@gmcb/cli@0.7.11) (2026-07-13)
15
+
16
+ **Note:** Version bump only for package @gmcb/cli
17
+
18
+
19
+
20
+
21
+
6
22
  ## [0.7.10](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.9...@gmcb/cli@0.7.10) (2026-07-12)
7
23
 
8
24
  **Note:** Version bump only for package @gmcb/cli
package/README.md CHANGED
@@ -34,6 +34,7 @@ npm i @gmcb/cli -g
34
34
  | `--wgt` | 构建移动应用热更新资源 |
35
35
  | `--zip` | 构建桌面应用热更新资源 |
36
36
  | `--apk` | 构建 Android 应用 |
37
+ | `--nobuild` | 跳过构建步骤,仅执行后续流程(打包、远程资源拉取等) |
37
38
 
38
39
  使用 `--wgt` 构建移动应用热更新资源时,会先通过 vite/uni 正常构建 app,再将构建产物(`dist/build/app` 或 `unpackage/dist/build/app-plus`)打包为 `.wgt` 文件,输出路径默认为 `unpackage/release`。
39
40
 
@@ -72,6 +73,7 @@ gmcb build -p app --wgt
72
73
  | `--zip` | 构建桌面应用热更新资源 |
73
74
  | `--apk` | 构建 Android 应用 |
74
75
  | `-a, --auto` | 自动发布,跳过所有确认提示 |
76
+ | `--nobuild` | 跳过构建步骤,仅执行后续流程(打包、远程资源拉取等) |
75
77
 
76
78
  示例:
77
79
 
@@ -269,7 +269,25 @@ function downloadFile(url, dest) {
269
269
  });
270
270
  }
271
271
  async function fetchRemoteResources(opts) {
272
- const spinner = (0, ora_1.default)(`正在拉取远程仓库...`).start();
272
+ const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
273
+ // 查询版本数据,更新 package.json
274
+ const appIdPkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
275
+ const appId = appIdPkg.appId;
276
+ const { versionName, versionCode, brandId } = await (0, apis_1.fetchLatestVersion)({
277
+ appId,
278
+ brandId: config_1.CONFIG_DATA.publish?.brandId,
279
+ brandName: config_1.CONFIG_DATA.publish?.brandName,
280
+ platform: config_1.CONFIG_DATA.publish?.platform,
281
+ });
282
+ if (brandId) {
283
+ config_1.CONFIG_DATA.publish.brandId = brandId;
284
+ }
285
+ if (versionName && versionCode) {
286
+ let pkgContent = (0, fs_1.readFileSync)(utils_1.PACKAGE_PATH, 'utf-8');
287
+ pkgContent = pkgContent.replace(/"version"\s*:\s*"[^"]*"/, `"version": "${versionName}"`);
288
+ pkgContent = pkgContent.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
289
+ (0, fs_1.writeFileSync)(utils_1.PACKAGE_PATH, pkgContent);
290
+ }
273
291
  const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
274
292
  // 校验 version 和 versionCode 必须存在
275
293
  if (!pkg.version) {
@@ -278,7 +296,6 @@ async function fetchRemoteResources(opts) {
278
296
  if (!pkg.versionCode) {
279
297
  utils_1.log.error('package.json 缺少 versionCode 字段');
280
298
  }
281
- const appId = pkg.appId;
282
299
  // 1. 获取应用信息
283
300
  const appInfo = await (0, apis_1.getAppInfo)(appId);
284
301
  const { appName, iconUrl, configJson } = appInfo;
@@ -315,9 +332,9 @@ async function fetchRemoteResources(opts) {
315
332
  // 5. 修改仓库 src/manifest.json 的 versionName 和 versionCode
316
333
  const manifestPath = (0, path_1.join)(repoDir, 'src', 'manifest.json');
317
334
  let manifestContent = (0, fs_1.readFileSync)(manifestPath, 'utf-8');
318
- manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name" : "${appName}"`);
319
- manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName" : "${pkg.version}"`);
320
- manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode" : ${pkg.versionCode}`);
335
+ manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name": "${appName}"`);
336
+ manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${pkg.version}"`);
337
+ manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode": ${pkg.versionCode}`);
321
338
  (0, fs_1.writeFileSync)(manifestPath, manifestContent);
322
339
  // 6. 修改仓库 package.json scripts
323
340
  const repoPkgPath = (0, path_1.join)(repoDir, 'package.json');
@@ -396,20 +413,22 @@ async function fetchRemoteResources(opts) {
396
413
  async function default_1(...args) {
397
414
  const opts = args[0];
398
415
  const commands = await getCommands(...args);
416
+ const command = commands.join(' ');
399
417
  if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
400
418
  await fetchRemoteResources(opts);
401
419
  }
402
- const command = commands.join(' ');
403
- const time = Date.now();
404
- (0, utils_1.spawnSync)(command);
420
+ if (!opts.nobuild) {
421
+ const time = Date.now();
422
+ (0, utils_1.spawnSync)(command);
423
+ if ((Date.now() - time) / 1000 <= 1) {
424
+ if (command.includes(config_1.CONFIG_DATA.cli.hbuilderx)) {
425
+ utils_1.log.error('检测到您的HbuilderX未启动或项目管理器中未发现构建项目,请检查后重试!');
426
+ }
427
+ }
428
+ }
405
429
  if ((0, fs_1.existsSync)(envPath)) {
406
430
  (0, fs_1.unlinkSync)(envPath);
407
431
  }
408
- if ((Date.now() - time) / 1000 <= 1) {
409
- if (command.includes(config_1.CONFIG_DATA.cli.hbuilderx)) {
410
- utils_1.log.error('检测到您的HbuilderX未启动或项目管理器中未发现构建项目,请检查后重试!');
411
- }
412
- }
413
432
  // H5 构建完成后立即生成 manifest.json
414
433
  if (opts.compiler === 'uni' && opts.platform === 'h5') {
415
434
  generateH5Manifest();
@@ -45,5 +45,6 @@ declare class Http {
45
45
  get(url: string, params?: HttpRequestParams, config?: HttpRequestConfig): Promise<ResponseData<any>>;
46
46
  }
47
47
  export declare function setToken(token?: string): void;
48
+ export declare function getToken(): string | undefined;
48
49
  export declare const http: Http;
49
50
  export {};
package/lib/apis/http.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.http = void 0;
4
4
  exports.setToken = setToken;
5
+ exports.getToken = getToken;
5
6
  const const_1 = require("../utils/const");
6
7
  class Http {
7
8
  _header = {
@@ -130,4 +131,7 @@ function setToken(token) {
130
131
  delete header['Authorization'];
131
132
  }
132
133
  }
134
+ function getToken() {
135
+ return exports.http.options.header['Authorization'];
136
+ }
133
137
  exports.http = new Http();
@@ -60,6 +60,8 @@ export declare function postVersion(data: any): Promise<{
60
60
  export declare function getVersionPage(params: {
61
61
  appId: string;
62
62
  publishType: number;
63
+ brandId?: number | string;
64
+ platform?: number;
63
65
  pageNo?: number;
64
66
  pageSize?: number;
65
67
  }): Promise<{
@@ -89,7 +91,7 @@ export declare function getVersionHistory(params: Record<string, any>): Promise<
89
91
  }>;
90
92
  export interface VersionParams {
91
93
  brand?: string;
92
- brandId?: number | string;
94
+ brandId?: string;
93
95
  brandName?: string;
94
96
  appId?: string;
95
97
  username?: string;
@@ -115,6 +117,19 @@ export declare function uploadVersion(params: VersionParams): Promise<void>;
115
117
  * 发布版本
116
118
  */
117
119
  export declare function publishVersion(params: VersionParams): Promise<void>;
120
+ /**
121
+ * 获取最新版本信息(自动登录)
122
+ */
123
+ export declare function fetchLatestVersion(params: {
124
+ appId: string;
125
+ brandId?: string;
126
+ brandName?: string;
127
+ platform?: number;
128
+ }): Promise<{
129
+ versionName: any;
130
+ versionCode: number;
131
+ brandId: string;
132
+ }>;
118
133
  /**
119
134
  * 获取应用信息(自动登录)
120
135
  */
package/lib/apis/index.js CHANGED
@@ -12,6 +12,7 @@ exports.getAppPage = getAppPage;
12
12
  exports.getVersionHistory = getVersionHistory;
13
13
  exports.uploadVersion = uploadVersion;
14
14
  exports.publishVersion = publishVersion;
15
+ exports.fetchLatestVersion = fetchLatestVersion;
15
16
  exports.getAppInfo = getAppInfo;
16
17
  const http_1 = require("./http");
17
18
  const const_1 = require("../utils/const");
@@ -23,6 +24,14 @@ const utils_1 = require("../utils");
23
24
  function login(data) {
24
25
  return http_1.http.post('/admin-api/system/auth/login', data);
25
26
  }
27
+ async function ensureLoggedIn() {
28
+ if ((0, http_1.getToken)())
29
+ return;
30
+ const web = config_1.CONFIG_DATA.web;
31
+ const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
32
+ const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
33
+ (0, http_1.setToken)(accessToken);
34
+ }
26
35
  /**
27
36
  * 获取品牌列表
28
37
  */
@@ -82,10 +91,9 @@ function getVersionHistory(params) {
82
91
  */
83
92
  async function uploadVersion(params) {
84
93
  try {
85
- const { brand, username, password, type, status, platform, path, remoteUrl, versionName, versionCode, } = params;
94
+ const { brand, type, status, platform, path, remoteUrl, versionName, versionCode, } = params;
86
95
  let brandId = '';
87
- const { data: { accessToken }, } = await login({ username, password });
88
- (0, http_1.setToken)(accessToken);
96
+ await ensureLoggedIn();
89
97
  const { data: brandList } = await getBrandList();
90
98
  const brandItem = brandList?.find(({ name, id }) => name === brand && Number(id) > 10000);
91
99
  brandId = brandItem?.id;
@@ -114,20 +122,19 @@ async function uploadVersion(params) {
114
122
  */
115
123
  async function publishVersion(params) {
116
124
  try {
117
- const { brandName, brandId, appId, username, password, remoteUrl, versionName, versionCode, channel, versionDesc, platform, ...rest } = params;
125
+ const { brandName, brandId, appId, remoteUrl, versionName, versionCode, channel, versionDesc, platform, ...rest } = params;
118
126
  const publishType = Number(rest.publishType || 3);
119
127
  const updateType = Number(rest.updateType || 2);
120
128
  const updateMode = Number(rest.updateMode || 0);
121
- const { data: { accessToken }, } = await login({ username, password });
122
- (0, http_1.setToken)(accessToken);
123
- const { data: pageData } = await getVersionPage({ appId, publishType, pageNo: 1, pageSize: 10 });
124
- const pageList = pageData?.list?.filter((item) => {
125
- if (publishType == 1) {
126
- return item.platformType === const_1.PLATFORM_TYPE[platform];
127
- }
128
- return true;
129
- }) || [];
130
- const existingVersion = pageList.find((item) => String(item.versionNum) === String(versionCode));
129
+ await ensureLoggedIn();
130
+ const pageParams = { appId, publishType, pageNo: 1, pageSize: 1 };
131
+ if (publishType == 1) {
132
+ pageParams.brandId = config_1.CONFIG_DATA.publish?.brandId;
133
+ pageParams.platform = platform;
134
+ }
135
+ const { data: pageData } = await getVersionPage(pageParams);
136
+ const pageList = pageData?.list || [];
137
+ const existingVersion = pageList.find((item) => item.status < 2 && String(item.versionNum) === String(versionCode));
131
138
  let latest;
132
139
  const firstPage = pageList[0];
133
140
  if (firstPage) {
@@ -158,22 +165,20 @@ async function publishVersion(params) {
158
165
  }
159
166
  else {
160
167
  let createData;
168
+ const { data: appList } = await getAppList();
169
+ const appItem = appList?.find((item) => item.appId === appId);
161
170
  if (publishType == 1) {
162
- const { data: brandList } = await getBrandList();
163
- const brandItem = brandList?.find(({ name, id }) => {
164
- if (Number(id) > 10000) {
165
- if (brandId && id === brandId) {
166
- return true;
167
- }
168
- if (brandName && name === brandName) {
169
- return true;
170
- }
171
- }
172
- return false;
173
- });
171
+ let resolvedBrandId = config_1.CONFIG_DATA.publish?.brandId || brandId;
172
+ if (!resolvedBrandId && brandName) {
173
+ const { data: brandList } = await getBrandList();
174
+ const matched = brandList?.find(({ name, id }) => {
175
+ return Number(id) > 10000 && name === brandName;
176
+ });
177
+ resolvedBrandId = matched?.id;
178
+ }
174
179
  createData = {
175
- brandId: brandItem?.id,
176
- appName: brandItem?.name,
180
+ brandId: resolvedBrandId,
181
+ appName: appItem?.name,
177
182
  channelType: const_1.CHANNEL_TYPE[channel],
178
183
  platformType: const_1.PLATFORM_TYPE[platform],
179
184
  updateType,
@@ -189,11 +194,9 @@ async function publishVersion(params) {
189
194
  };
190
195
  }
191
196
  else {
192
- const { data: appList } = await getAppList();
193
- const appItem = appList?.find((item) => item.appId === appId);
194
197
  createData = {
195
- appMofangId: appItem?.id,
196
198
  appId,
199
+ appMofangId: appItem?.id,
197
200
  appName: appItem?.name,
198
201
  updateType,
199
202
  updateMode,
@@ -219,8 +222,8 @@ async function publishVersion(params) {
219
222
  fullUrl = urls.find((u) => !/\.zip$/i.test(u)) || '';
220
223
  resUrl = urls.find((u) => /\.zip$/i.test(u)) || '';
221
224
  }
222
- let fallbackFullUrl = existingVersion?.fullPackageUrl || latest?.fullPackageUrl || '';
223
- let fallbackResUrl = existingVersion?.resourcePackageUrl || latest?.resourcePackageUrl || '';
225
+ let fallbackFullUrl = latest?.fullPackageUrl || '';
226
+ let fallbackResUrl = latest?.resourcePackageUrl || '';
224
227
  if (publishType == 1 && fullUrl) {
225
228
  fallbackFullUrl = '';
226
229
  fallbackResUrl = '';
@@ -236,15 +239,42 @@ async function publishVersion(params) {
236
239
  process.exit(1);
237
240
  }
238
241
  }
242
+ /**
243
+ * 获取最新版本信息(自动登录)
244
+ */
245
+ async function fetchLatestVersion(params) {
246
+ const { appId, brandId, brandName, platform } = params;
247
+ await ensureLoggedIn();
248
+ let resolvedBrandId = brandId;
249
+ if (!resolvedBrandId && brandName) {
250
+ const { data: brandList } = await getBrandList();
251
+ const matched = brandList?.find(({ name, id }) => {
252
+ return Number(id) > 10000 && name === brandName;
253
+ });
254
+ resolvedBrandId = matched?.id;
255
+ }
256
+ const { data: versionPage } = await getVersionPage({
257
+ appId,
258
+ publishType: 1,
259
+ brandId: resolvedBrandId,
260
+ platform,
261
+ pageNo: 1,
262
+ pageSize: 1,
263
+ });
264
+ const versionList = (versionPage?.list || []).filter((item) => item.status < 2);
265
+ const latestVersion = versionList[0];
266
+ return {
267
+ versionName: latestVersion?.versionName ?? '',
268
+ versionCode: Number(latestVersion?.versionNum ?? 0),
269
+ brandId: resolvedBrandId ?? '',
270
+ };
271
+ }
239
272
  /**
240
273
  * 获取应用信息(自动登录)
241
274
  */
242
275
  async function getAppInfo(appId) {
243
276
  try {
244
- const web = config_1.CONFIG_DATA.web;
245
- const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
246
- const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
247
- (0, http_1.setToken)(accessToken);
277
+ await ensureLoggedIn();
248
278
  const { data: pageData } = await getAppPage({ appId, pageNo: 1, pageSize: 10 });
249
279
  const appData = pageData?.list?.[0];
250
280
  if (!appData)
package/lib/bin.js CHANGED
@@ -51,6 +51,7 @@ program
51
51
  .option(...commands_1.linux)
52
52
  .option(...commands_1.apk)
53
53
  .option(...commands_1.remote)
54
+ .option(...commands_1.nobuild)
54
55
  .action(build_1.default);
55
56
  program
56
57
  .command('copy')
@@ -80,6 +81,7 @@ program
80
81
  .option(...commands_1.apk)
81
82
  .option(...commands_1.skip)
82
83
  .option(...commands_1.remote)
84
+ .option(...commands_1.nobuild)
83
85
  .action(publish_1.default);
84
86
  program
85
87
  .command('config [name]')
@@ -24,6 +24,7 @@ export declare const res: readonly ["--res", "是否构建移动应用本地资
24
24
  export declare const apk: readonly ["--apk", "是否构建Android应用"];
25
25
  export declare const skip: readonly ["--skip", "跳过所有确认,自动发布"];
26
26
  export declare const remote: readonly ["--remote", "是否从远程拉取资源构建"];
27
+ export declare const nobuild: readonly ["--nobuild", "跳过构建步骤"];
27
28
  export declare const hbuilderxCli: readonly ["--cli.hbuilderx <cli-path>", "HbuilderX Cli路径"];
28
29
  export declare const weixinCli: readonly ["--cli.weixin <cli-path>", "微信开发者工具 Cli路径"];
29
30
  export declare const alipayCli: readonly ["--cli.alipay <cli-path>", "支付宝开发者工具 Cli路径"];
@@ -56,6 +57,7 @@ export interface Options {
56
57
  linux: boolean;
57
58
  apk?: boolean;
58
59
  remote?: boolean;
60
+ nobuild?: boolean;
59
61
  'skill.repo'?: string;
60
62
  'template.repo'?: string;
61
63
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.templateRepo = exports.skillRepo = exports.cosSecretkey = exports.cosSecretid = exports.alipayCli = exports.weixinCli = exports.hbuilderxCli = exports.remote = 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;
3
+ exports.templateRepo = exports.skillRepo = exports.cosSecretkey = exports.cosSecretid = exports.alipayCli = exports.weixinCli = exports.hbuilderxCli = exports.nobuild = exports.remote = 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
6
  exports.platform = ['-p, --platform <platform-name>', '编译平台,默认h5', 'h5'];
@@ -26,6 +26,7 @@ exports.res = ['--res', '是否构建移动应用本地资源'];
26
26
  exports.apk = ['--apk', '是否构建Android应用'];
27
27
  exports.skip = ['--skip', '跳过所有确认,自动发布'];
28
28
  exports.remote = ['--remote', '是否从远程拉取资源构建'];
29
+ exports.nobuild = ['--nobuild', '跳过构建步骤'];
29
30
  exports.hbuilderxCli = ['--cli.hbuilderx <cli-path>', 'HbuilderX Cli路径'];
30
31
  exports.weixinCli = ['--cli.weixin <cli-path>', '微信开发者工具 Cli路径'];
31
32
  exports.alipayCli = ['--cli.alipay <cli-path>', '支付宝开发者工具 Cli路径'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmcb/cli",
3
- "version": "0.7.10",
3
+ "version": "0.7.12",
4
4
  "description": "工茂草本前端命令行工具",
5
5
  "author": "yinjiazeng@163.com",
6
6
  "license": "MIT",
@@ -59,5 +59,5 @@
59
59
  "@types/rimraf": "^4.0.5",
60
60
  "@types/user-home": "^2.0.2"
61
61
  },
62
- "gitHead": "71ce7aeb811bd6fd27030b981d3545fdab4276f1"
62
+ "gitHead": "03c7901a7dba2e7364e9eaabf7a6f0e5199064aa"
63
63
  }