@gmcb/cli 0.8.9 → 0.8.11

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.8.11](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.10...@gmcb/cli@0.8.11) (2026-07-16)
7
+
8
+ **Note:** Version bump only for package @gmcb/cli
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.8.10](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.9...@gmcb/cli@0.8.10) (2026-07-16)
15
+
16
+ **Note:** Version bump only for package @gmcb/cli
17
+
18
+
19
+
20
+
21
+
6
22
  ## [0.8.9](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.8...@gmcb/cli@0.8.9) (2026-07-16)
7
23
 
8
24
  **Note:** Version bump only for package @gmcb/cli
@@ -1,3 +1,4 @@
1
- export declare function restoreRemoteResources(restore: boolean): Promise<void>;
1
+ export declare function restoreLocalResources(restore: boolean): Promise<void>;
2
+ export declare function syncLatestVersion(): Promise<void>;
2
3
  export declare function getCommands(...args: any[]): Promise<string[]>;
3
4
  export default function (...args: any[]): Promise<string[]>;
@@ -26,7 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.restoreRemoteResources = restoreRemoteResources;
29
+ exports.restoreLocalResources = restoreLocalResources;
30
+ exports.syncLatestVersion = syncLatestVersion;
30
31
  exports.getCommands = getCommands;
31
32
  exports.default = default_1;
32
33
  const fs_1 = require("fs");
@@ -47,7 +48,12 @@ const apis_1 = require("../apis");
47
48
  let envPath = utils_1.BUILD_ENV_PATH;
48
49
  // 主项目文件快照:value 为 null 表示写入前该文件不存在,还原时应删除
49
50
  const remoteBackups = new Map();
50
- async function restoreRemoteResources(restore) {
51
+ function backup(p) {
52
+ if (remoteBackups.has(p))
53
+ return;
54
+ remoteBackups.set(p, (0, fs_1.existsSync)(p) ? (0, fs_1.readFileSync)(p) : null);
55
+ }
56
+ async function restoreLocalResources(restore) {
51
57
  if (restore) {
52
58
  for (const [p, data] of remoteBackups) {
53
59
  try {
@@ -66,6 +72,42 @@ async function restoreRemoteResources(restore) {
66
72
  }
67
73
  remoteBackups.clear();
68
74
  }
75
+ async function syncLatestVersion() {
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;
79
+ const { versionName, versionCode, updateMode } = await (0, apis_1.fetchLatestVersion)({
80
+ appId,
81
+ platform: config_1.CONFIG_DATA.publish?.platform,
82
+ publishType: config_1.CONFIG_DATA.publish?.publishType,
83
+ });
84
+ if (updateMode) {
85
+ config_1.CONFIG_DATA.publish.updateMode = updateMode;
86
+ }
87
+ if (versionName && versionCode) {
88
+ if ((0, fs_1.existsSync)(utils_1.MAINFEST_PATH)) {
89
+ const localVersionCode = Number((0, utils_1.readManifest)().versionCode || 0);
90
+ if (localVersionCode < versionCode) {
91
+ let content = (0, fs_1.readFileSync)(utils_1.MAINFEST_PATH, 'utf-8');
92
+ content = content.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${versionName}"`);
93
+ content = content.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
94
+ backup(utils_1.MAINFEST_PATH);
95
+ (0, fs_1.writeFileSync)(utils_1.MAINFEST_PATH, content);
96
+ }
97
+ }
98
+ else {
99
+ const localVersionCode = Number(pkg.versionCode || 0);
100
+ if (localVersionCode < versionCode) {
101
+ let pkgContent = (0, fs_1.readFileSync)(utils_1.PACKAGE_PATH, 'utf-8');
102
+ pkgContent = pkgContent.replace(/"version"\s*:\s*"[^"]*"/, `"version": "${versionName}"`);
103
+ pkgContent = pkgContent.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
104
+ backup(utils_1.PACKAGE_PATH);
105
+ (0, fs_1.writeFileSync)(utils_1.PACKAGE_PATH, pkgContent);
106
+ }
107
+ }
108
+ }
109
+ spinner.stop();
110
+ }
69
111
  async function getCommands(...args) {
70
112
  const opts = args[0];
71
113
  if (config_1.CONFIG_DATA.branch && config_1.CONFIG_DATA.branch !== 'false') {
@@ -188,12 +230,11 @@ async function getCommands(...args) {
188
230
  }
189
231
  }
190
232
  else if (opts.compiler === 'electron-vite') {
191
- const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
192
233
  commands = [
193
234
  ...commands,
194
235
  bin,
195
236
  'build',
196
- `&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`} VERSION_CODE=${pkg.versionCode || ''} VERSION_NAME=${pkg.version || ''}`,
237
+ `&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`}`,
197
238
  ];
198
239
  if (opts.zip) {
199
240
  commands.push('electron-builder --dir');
@@ -290,47 +331,18 @@ function downloadFile(url, dest) {
290
331
  }).on('error', rej);
291
332
  });
292
333
  }
293
- async function fetchRemoteResources(opts) {
294
- remoteBackups.clear();
295
- const backup = (p) => {
296
- if (remoteBackups.has(p))
297
- return;
298
- remoteBackups.set(p, (0, fs_1.existsSync)(p) ? (0, fs_1.readFileSync)(p) : null);
299
- };
334
+ async function pullRemoteResources(opts) {
300
335
  const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
301
- // 查询版本数据,更新 package.json
302
- const appIdPkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
303
- const appId = appIdPkg.appId;
304
- const { versionName, versionCode, updateMode } = await (0, apis_1.fetchLatestVersion)({
305
- appId,
306
- platform: config_1.CONFIG_DATA.publish?.platform,
307
- });
308
- if (updateMode) {
309
- config_1.CONFIG_DATA.publish.updateMode = updateMode;
310
- }
311
- if (versionName && versionCode) {
312
- let pkgContent = (0, fs_1.readFileSync)(utils_1.PACKAGE_PATH, 'utf-8');
313
- pkgContent = pkgContent.replace(/"version"\s*:\s*"[^"]*"/, `"version": "${versionName}"`);
314
- pkgContent = pkgContent.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
315
- backup(utils_1.PACKAGE_PATH);
316
- (0, fs_1.writeFileSync)(utils_1.PACKAGE_PATH, pkgContent);
317
- }
318
336
  const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
319
- // 校验 version 和 versionCode 必须存在
320
- if (!pkg.version) {
321
- utils_1.log.error('package.json 缺少 version 字段');
322
- }
323
- if (!pkg.versionCode) {
324
- utils_1.log.error('package.json 缺少 versionCode 字段');
325
- }
337
+ const appId = pkg.appId;
326
338
  // 1. 获取应用信息
327
339
  const appInfo = await (0, apis_1.getAppInfo)(appId);
328
340
  const { appName, iconUrl, configJson } = appInfo;
329
341
  // 2. 确定仓库地址
330
- const repoUrl = configJson.repo || config_1.CONFIG_DATA.render?.repo;
342
+ const repoUrl = configJson.repo || config_1.CONFIG_DATA.pull?.repo;
331
343
  // 3. 确定分支:使用 buildEnv,默认 master;prod 对应 master 分支
332
- const buildEnv = process.env.BUILD_ENV || 'master';
333
- const branch = buildEnv === 'prod' ? 'master' : buildEnv;
344
+ const buildEnv = process.env.BUILD_ENV;
345
+ const branch = buildEnv.startsWith('pro') || !buildEnv ? 'master' : buildEnv;
334
346
  // 4. 拉取代码到 COMMAND_PATH/.repo/{appId}
335
347
  const repoDir = (0, path_1.join)(utils_1.COMMAND_PATH, '.repo', appId);
336
348
  if ((0, fs_1.existsSync)((0, path_1.join)(repoDir, '.git'))) {
@@ -458,10 +470,12 @@ async function default_1(...args) {
458
470
  const deferRestore = args[args.length - 1] === true;
459
471
  const commands = await getCommands(...args);
460
472
  const command = commands.join(' ');
461
- let hasRemote = false;
462
- if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
463
- await fetchRemoteResources(opts);
464
- hasRemote = true;
473
+ remoteBackups.clear();
474
+ if (opts.latest) {
475
+ await syncLatestVersion();
476
+ }
477
+ if (opts.pull && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
478
+ await pullRemoteResources(opts);
465
479
  }
466
480
  try {
467
481
  if (!opts.nobuild) {
@@ -489,8 +503,8 @@ async function default_1(...args) {
489
503
  return commands;
490
504
  }
491
505
  finally {
492
- if (hasRemote && !deferRestore) {
493
- await restoreRemoteResources(!!opts.restore);
506
+ if (!deferRestore) {
507
+ await restoreLocalResources(!!opts.restore);
494
508
  }
495
509
  }
496
510
  }
@@ -50,7 +50,7 @@ async function default_1(...args) {
50
50
  if (/^(app|h5)/.test(opts.platform)) {
51
51
  if (isPublishFlow) {
52
52
  // publish 流程
53
- if (!config_1.CONFIG_DATA.publish?.platform && config_1.CONFIG_DATA.publish?.publishType == 1 && !(opts.wgt && opts.zip)) {
53
+ if (!config_1.CONFIG_DATA.publish?.platform && config_1.CONFIG_DATA.publish?.publishType == 1) {
54
54
  const { platform } = await inquirer_1.default.prompt([
55
55
  {
56
56
  type: 'list',
@@ -89,10 +89,10 @@ async function default_1(...args) {
89
89
  }
90
90
  // --wgt/--zip 一律热更新
91
91
  // --win/--apk 一律整包更新
92
- // --remote 则提示热更新还是整包更新
92
+ // --pull 则提示热更新还是整包更新
93
93
  if (opts.win || opts.apk) {
94
94
  pub.updateMode = 1;
95
- if (opts.remote && !config_1.CONFIG_DATA.publish?.updateMode) {
95
+ if (opts.pull && !config_1.CONFIG_DATA.publish?.updateMode) {
96
96
  const { updateMode } = await inquirer_1.default.prompt([
97
97
  {
98
98
  type: 'list',
@@ -149,14 +149,16 @@ async function default_1(...args) {
149
149
  }
150
150
  }
151
151
  }
152
- const { update } = await inquirer_1.default.prompt({
153
- type: 'confirm',
154
- message: '是否已更新版本号?',
155
- name: 'update',
156
- default: true,
157
- });
158
- if (!update) {
159
- process.exit(1);
152
+ if (!opts.latest) {
153
+ const { update } = await inquirer_1.default.prompt({
154
+ type: 'confirm',
155
+ message: '是否已更新版本号?',
156
+ name: 'update',
157
+ default: true,
158
+ });
159
+ if (!update) {
160
+ process.exit(1);
161
+ }
160
162
  }
161
163
  const result = await inquirer_1.default.prompt({
162
164
  type: 'confirm',
@@ -228,10 +230,10 @@ async function default_1(...args) {
228
230
  }
229
231
  // 从 cmds 提取 buildEnv
230
232
  const buildEnv = cmds[2]?.split('=')[1];
231
- if (!buildEnv || !['dev', 'sit', 'uat', 'pre', 'prod'].includes(buildEnv)) {
233
+ if (!buildEnv || !['dev', 'sit', 'uat', 'pre', 'pro', 'prod'].includes(buildEnv)) {
232
234
  utils_1.log.error('没有检测到需要发布的环境,无法完成上传,请切换到dev/sit/uat/pre/master分支再次执行脚本,或者您可以选择手动上传!');
233
235
  }
234
- const isHotUpdate = opts.remote && config_1.CONFIG_DATA.publish?.updateMode == 2;
236
+ const isHotUpdate = opts.pull && config_1.CONFIG_DATA.publish?.updateMode == 2;
235
237
  if (opts.compiler === 'electron-vite') {
236
238
  if (isHotUpdate) {
237
239
  await require('../scripts/zip-exe').default();
@@ -274,6 +276,6 @@ async function default_1(...args) {
274
276
  }
275
277
  }
276
278
  finally {
277
- await (0, build_1.restoreRemoteResources)(!!opts.restore);
279
+ await (0, build_1.restoreLocalResources)(!!opts.restore);
278
280
  }
279
281
  }
@@ -124,6 +124,7 @@ export declare function publishVersion(params: VersionParams): Promise<void>;
124
124
  export declare function fetchLatestVersion(params: {
125
125
  appId: string;
126
126
  platform?: number;
127
+ publishType?: number;
127
128
  }): Promise<{
128
129
  versionName: any;
129
130
  versionCode: number;
package/lib/apis/index.js CHANGED
@@ -205,11 +205,11 @@ async function publishVersion(params) {
205
205
  */
206
206
  async function fetchLatestVersion(params) {
207
207
  try {
208
- const { appId, platform } = params;
208
+ const { appId, platform, publishType } = params;
209
209
  await ensureLoggedIn();
210
210
  const { data: versionPage } = await getVersionPage({
211
211
  appId,
212
- publishType: 1,
212
+ publishType,
213
213
  platform,
214
214
  pageNo: 1,
215
215
  pageSize: 1,
package/lib/bin.js CHANGED
@@ -51,7 +51,8 @@ program
51
51
  .option(...commands_1.mac)
52
52
  .option(...commands_1.linux)
53
53
  .option(...commands_1.apk)
54
- .option(...commands_1.remote)
54
+ .option(...commands_1.pull)
55
+ .option(...commands_1.latest)
55
56
  .option(...commands_1.restore)
56
57
  .option(...commands_1.nobuild)
57
58
  .action(build_1.default);
@@ -82,7 +83,8 @@ program
82
83
  .option(...commands_1.linux)
83
84
  .option(...commands_1.apk)
84
85
  .option(...commands_1.skip)
85
- .option(...commands_1.remote)
86
+ .option(...commands_1.pull)
87
+ .option(...commands_1.latest)
86
88
  .option(...commands_1.restore)
87
89
  .option(...commands_1.nobuild)
88
90
  .action(publish_1.default);
@@ -23,7 +23,8 @@ export declare const wgt: readonly ["--wgt", "是否构建移动应用热更新
23
23
  export declare const res: readonly ["--res", "是否构建移动应用本地资源"];
24
24
  export declare const apk: readonly ["--apk", "是否构建Android应用"];
25
25
  export declare const skip: readonly ["--skip", "跳过所有确认,自动发布"];
26
- export declare const remote: readonly ["--remote", "是否从远程拉取资源构建"];
26
+ export declare const pull: readonly ["--pull", "是否拉取远程代码构建"];
27
+ export declare const latest: readonly ["--latest", "是否获取最新版本数据"];
27
28
  export declare const restore: readonly ["--restore", "构建完成后是否还原远程写入的主项目文件"];
28
29
  export declare const nobuild: readonly ["--nobuild", "跳过构建步骤"];
29
30
  export declare const radius: readonly ["-r, --radius <number>", "圆角半径,默认16", "16"];
@@ -59,7 +60,8 @@ export interface Options {
59
60
  mac: boolean;
60
61
  linux: boolean;
61
62
  apk?: boolean;
62
- remote?: boolean;
63
+ pull?: boolean;
64
+ latest?: boolean;
63
65
  restore?: boolean;
64
66
  nobuild?: boolean;
65
67
  radius?: string;
@@ -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.ico = exports.radius = exports.nobuild = exports.restore = 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.ico = 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
6
  exports.platform = ['-p, --platform <platform-name>', '编译平台,默认h5', 'h5'];
@@ -25,7 +25,8 @@ exports.wgt = ['--wgt', '是否构建移动应用热更新资源'];
25
25
  exports.res = ['--res', '是否构建移动应用本地资源'];
26
26
  exports.apk = ['--apk', '是否构建Android应用'];
27
27
  exports.skip = ['--skip', '跳过所有确认,自动发布'];
28
- exports.remote = ['--remote', '是否从远程拉取资源构建'];
28
+ exports.pull = ['--pull', '是否拉取远程代码构建'];
29
+ exports.latest = ['--latest', '是否获取最新版本数据'];
29
30
  exports.restore = ['--restore', '构建完成后是否还原远程写入的主项目文件'];
30
31
  exports.nobuild = ['--nobuild', '跳过构建步骤'];
31
32
  exports.radius = ['-r, --radius <number>', '圆角半径,默认16', '16'];
@@ -26,7 +26,7 @@ async function publish(options) {
26
26
  const pkg = (0, fs_extra_1.readJsonSync)(const_1.PACKAGE_PATH, { throws: false }) || {};
27
27
  const versionName = options.versionName;
28
28
  const versionCode = (0, function_1.getEnvVersionCode)() || options.versionCode;
29
- const bucket = `${buildEnv === 'prod' ? '' : `${buildEnv}-`}${config_1.CONFIG_DATA.cos.bucket ?? ''}`;
29
+ const bucket = `${buildEnv.startsWith('pro') ? '' : `${buildEnv}-`}${config_1.CONFIG_DATA.cos.bucket ?? ''}`;
30
30
  const region = config_1.CONFIG_DATA.cos?.region ?? '';
31
31
  const secretId = config_1.CONFIG_DATA.cos?.secretid ?? '';
32
32
  const secretKey = config_1.CONFIG_DATA.cos?.secretkey ?? '';
@@ -90,7 +90,7 @@ export interface WebCredentials {
90
90
  username?: string;
91
91
  password?: string;
92
92
  }
93
- interface Render {
93
+ interface Pull {
94
94
  repo?: string;
95
95
  }
96
96
  export interface BaseConfig {
@@ -100,7 +100,7 @@ export interface BaseConfig {
100
100
  skill?: Skill;
101
101
  template?: Template;
102
102
  web?: Record<string, WebCredentials> | WebCredentials;
103
- render?: Render;
103
+ pull?: Pull;
104
104
  }
105
105
  export interface Config extends BaseConfig {
106
106
  skip?: boolean | number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmcb/cli",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
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": "bbab898cd0854797c1dc2e52d3821b99a15890ac"
62
+ "gitHead": "8a591baa3f70e74c76989b15cec93d34b4734d0d"
63
63
  }
package/schema.json CHANGED
@@ -39,13 +39,13 @@
39
39
  },
40
40
  "required": ["username", "password"]
41
41
  },
42
- "render": {
42
+ "pull": {
43
43
  "type": "object",
44
- "description": "渲染端资源配置",
44
+ "description": "拉取资源配置",
45
45
  "properties": {
46
46
  "repo": {
47
47
  "type": "string",
48
- "description": "远程渲染端仓库地址,--remote 拉取代码时使用"
48
+ "description": "远程仓库地址,--pull 拉取代码时使用"
49
49
  }
50
50
  }
51
51
  },