@gmcb/cli 0.8.8 → 0.8.10

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.10](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.9...@gmcb/cli@0.8.10) (2026-07-16)
7
+
8
+ **Note:** Version bump only for package @gmcb/cli
9
+
10
+
11
+
12
+
13
+
14
+ ## [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)
15
+
16
+ **Note:** Version bump only for package @gmcb/cli
17
+
18
+
19
+
20
+
21
+
6
22
  ## [0.8.8](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.7...@gmcb/cli@0.8.8) (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,37 @@ 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 appIdPkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
78
+ const appId = appIdPkg.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
+ let content = (0, fs_1.readFileSync)(utils_1.MAINFEST_PATH, 'utf-8');
90
+ content = content.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${versionName}"`);
91
+ content = content.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
92
+ backup(utils_1.MAINFEST_PATH);
93
+ (0, fs_1.writeFileSync)(utils_1.MAINFEST_PATH, content);
94
+ }
95
+ else {
96
+ // 回退到 package.json
97
+ let pkgContent = (0, fs_1.readFileSync)(utils_1.PACKAGE_PATH, 'utf-8');
98
+ pkgContent = pkgContent.replace(/"version"\s*:\s*"[^"]*"/, `"version": "${versionName}"`);
99
+ pkgContent = pkgContent.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
100
+ backup(utils_1.PACKAGE_PATH);
101
+ (0, fs_1.writeFileSync)(utils_1.PACKAGE_PATH, pkgContent);
102
+ }
103
+ }
104
+ spinner.stop();
105
+ }
69
106
  async function getCommands(...args) {
70
107
  const opts = args[0];
71
108
  if (config_1.CONFIG_DATA.branch && config_1.CONFIG_DATA.branch !== 'false') {
@@ -188,12 +225,11 @@ async function getCommands(...args) {
188
225
  }
189
226
  }
190
227
  else if (opts.compiler === 'electron-vite') {
191
- const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
192
228
  commands = [
193
229
  ...commands,
194
230
  bin,
195
231
  'build',
196
- `&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`} VERSION_CODE=${pkg.versionCode || ''} VERSION_NAME=${pkg.version || ''}`,
232
+ `&& cross-env CHANNEL=${String(buildEnv).startsWith('pro') ? '' : `-${buildEnv}`}`,
197
233
  ];
198
234
  if (opts.zip) {
199
235
  commands.push('electron-builder --dir');
@@ -290,46 +326,18 @@ function downloadFile(url, dest) {
290
326
  }).on('error', rej);
291
327
  });
292
328
  }
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
- };
329
+ async function pullRemoteResources(opts) {
300
330
  const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
301
- // 查询版本数据,更新 package.json
302
331
  const appIdPkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
303
332
  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
333
  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
- }
326
334
  // 1. 获取应用信息
327
335
  const appInfo = await (0, apis_1.getAppInfo)(appId);
328
336
  const { appName, iconUrl, configJson } = appInfo;
329
337
  // 2. 确定仓库地址
330
- const repoUrl = configJson.repo || config_1.CONFIG_DATA.render?.repo;
338
+ const repoUrl = configJson.repo || config_1.CONFIG_DATA.pull?.repo;
331
339
  // 3. 确定分支:使用 buildEnv,默认 master;prod 对应 master 分支
332
- const buildEnv = process.env.BUILD_ENV || 'master';
340
+ const buildEnv = process.env.BUILD_ENV || 'prod';
333
341
  const branch = buildEnv === 'prod' ? 'master' : buildEnv;
334
342
  // 4. 拉取代码到 COMMAND_PATH/.repo/{appId}
335
343
  const repoDir = (0, path_1.join)(utils_1.COMMAND_PATH, '.repo', appId);
@@ -337,6 +345,8 @@ async function fetchRemoteResources(opts) {
337
345
  try {
338
346
  // 已有目录:fetch 目标分支 + 校验远程分支 + 切换 + pull
339
347
  const repoGit = (0, simple_git_1.default)(repoDir);
348
+ // 0. 撤销上次构建残留的本地修改,防止拉取冲突
349
+ await repoGit.reset(['--hard']);
340
350
  // 1. 拉取目标分支(显式指定,不受 --single-branch refspec 限制)
341
351
  // --prune 确保远程已删除的分支不会残留在本地引用中
342
352
  await repoGit.fetch('origin', `+refs/heads/${branch}:refs/remotes/origin/${branch}`, ['--prune']);
@@ -456,10 +466,12 @@ async function default_1(...args) {
456
466
  const deferRestore = args[args.length - 1] === true;
457
467
  const commands = await getCommands(...args);
458
468
  const command = commands.join(' ');
459
- let hasRemote = false;
460
- if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
461
- await fetchRemoteResources(opts);
462
- hasRemote = true;
469
+ remoteBackups.clear();
470
+ if (opts.latest) {
471
+ await syncLatestVersion();
472
+ }
473
+ if (opts.pull && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
474
+ await pullRemoteResources(opts);
463
475
  }
464
476
  try {
465
477
  if (!opts.nobuild) {
@@ -487,8 +499,8 @@ async function default_1(...args) {
487
499
  return commands;
488
500
  }
489
501
  finally {
490
- if (hasRemote && !deferRestore) {
491
- await restoreRemoteResources(!!opts.restore);
502
+ if (!deferRestore) {
503
+ await restoreLocalResources(!!opts.restore);
492
504
  }
493
505
  }
494
506
  }
@@ -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',
@@ -231,7 +233,7 @@ async function default_1(...args) {
231
233
  if (!buildEnv || !['dev', 'sit', 'uat', 'pre', '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'];
@@ -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.8",
3
+ "version": "0.8.10",
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": "239c9a2a239c891975751e4fc19110fcded68fae"
62
+ "gitHead": "4c2eb5b872c3a70e3b89e7ed96259a5b62c1bdd8"
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
  },