@gmcb/cli 0.9.5 → 0.9.7

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.7](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.6...@gmcb/cli@0.9.7) (2026-11-05)
7
+
8
+ **Note:** Version bump only for package @gmcb/cli
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.9.6](http://10.10.10.16/caoben/front-end-tools/compare/@gmcb/cli@0.9.5...@gmcb/cli@0.9.6) (2026-11-04)
15
+
16
+ **Note:** Version bump only for package @gmcb/cli
17
+
18
+
19
+
20
+
21
+
6
22
  ## [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
23
 
8
24
  **Note:** Version bump only for package @gmcb/cli
package/README.md CHANGED
@@ -254,3 +254,5 @@ gmcb image -s ./logo.png --width 2050 --height 1538 --left 500 --top 200 --bg '#
254
254
  gmcb copy -s ./dist/build/h5 -d ../electron/out/renderer/{package.appId}/
255
255
  gmcb copy -s ./dist/build/app -d ../android/app/src/main/assets/apps/{manifest.appid}/www/
256
256
  ```
257
+
258
+ `copy` 不会改写工程根目录的 `index.html`。混合布局工程(根目录 + `src` 镜像)中,src 入口的 `src/` 前缀由 `@gmcb/vite` 的 `transformIndexHtml` 插件在构建期补全。
@@ -37,7 +37,6 @@ const https_1 = __importDefault(require("https"));
37
37
  const http_1 = __importDefault(require("http"));
38
38
  const fs_extra_1 = require("fs-extra");
39
39
  const simple_git_1 = __importDefault(require("simple-git"));
40
- const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
41
40
  const adm_zip_1 = __importDefault(require("adm-zip"));
42
41
  const ora_1 = __importDefault(require("ora"));
43
42
  const delay_1 = __importDefault(require("delay"));
@@ -77,7 +76,7 @@ async function syncLatestVersion() {
77
76
  const hasPackage = (0, fs_1.existsSync)(utils_1.PACKAGE_PATH);
78
77
  const pkg = hasPackage ? (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH) : {};
79
78
  const manifest = (0, utils_1.readManifest)();
80
- const appId = pkg.appId || ((0, utils_1.isUniappXManifest)(manifest) ? manifest.appid : undefined);
79
+ const appId = pkg.appId || manifest.appid;
81
80
  if (!appId) {
82
81
  spinner.warn('未在 package.json 或 manifest.json 中找到 appId/appid,跳过版本号同步');
83
82
  return;
@@ -122,7 +121,6 @@ async function getCommands(...args) {
122
121
  if (opts.platform === 'web') {
123
122
  opts.platform = 'h5';
124
123
  }
125
- const isUniappX = (0, utils_1.isUniappXManifest)();
126
124
  if (config_1.CONFIG_DATA.branch && config_1.CONFIG_DATA.branch !== 'false') {
127
125
  opts.branch = config_1.CONFIG_DATA.branch;
128
126
  }
@@ -152,6 +150,21 @@ async function getCommands(...args) {
152
150
  const currentName = (0, path_1.basename)(utils_1.COMMAND_PATH);
153
151
  const projectName = opts.project || currentName;
154
152
  if (opts.compiler === 'uni') {
153
+ let projectPath = utils_1.COMMAND_PATH;
154
+ if (projectName !== currentName) {
155
+ if (opts.source) {
156
+ projectPath = (0, path_1.join)(utils_1.COMMAND_PATH, opts.source);
157
+ }
158
+ envPath = (0, path_1.join)(projectPath, 'buildenv');
159
+ if (opts.source && opts.branch) {
160
+ const git = (0, simple_git_1.default)(projectPath);
161
+ const branch = await git.branch();
162
+ if (opts.branch !== branch.current) {
163
+ utils_1.log.error(`您当前构建分支为“${opts.branch}”,项目“${projectName}”构建分支为“${branch.current}”,分支不一致,无法完成构建,请更改后重试!`);
164
+ }
165
+ }
166
+ }
167
+ const isUniappX = (0, utils_1.isUniappXManifest)(projectPath);
155
168
  const isUniappXApp = isUniappX && opts.platform.startsWith('app');
156
169
  // 无 src、uni-app x 的 App 平台、-P 指定了不同的 HBuilderX 项目名时都必须由 HBuilderX 构建,统一归一到 opts.pack
157
170
  if (!utils_1.HAS_SRC || isUniappXApp || projectName !== currentName) {
@@ -167,20 +180,6 @@ async function getCommands(...args) {
167
180
  if (!(0, fs_1.existsSync)(utils_1.PACKAGE_PATH)) {
168
181
  commands = [];
169
182
  }
170
- let projectPath = utils_1.COMMAND_PATH;
171
- if (projectName !== currentName) {
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');
176
- if (opts.source && opts.branch) {
177
- const git = (0, simple_git_1.default)(projectPath);
178
- const branch = await git.branch();
179
- if (opts.branch !== branch.current) {
180
- utils_1.log.error(`您当前构建分支为“${opts.branch}”,项目“${projectName}”构建分支为“${branch.current}”,分支不一致,无法完成构建,请更改后重试!`);
181
- }
182
- }
183
- }
184
183
  let cmds = [];
185
184
  if (buildEnv) {
186
185
  (0, fs_extra_1.ensureFileSync)(envPath);
@@ -204,7 +203,7 @@ async function getCommands(...args) {
204
203
  }
205
204
  const wgtDist = app.wgt[index + 1];
206
205
  (0, fs_extra_1.ensureDirSync)(wgtDist);
207
- const manifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(utils_1.MAINFEST_PATH).toString()));
206
+ const manifest = (0, utils_1.readManifest)(projectPath);
208
207
  if (manifest.appid) {
209
208
  (0, fs_extra_1.removeSync)((0, path_1.join)(wgtDist, `${manifest.appid}.wgt`));
210
209
  }
@@ -241,7 +240,7 @@ async function getCommands(...args) {
241
240
  }
242
241
  else if (opts.platform.startsWith('mp')) {
243
242
  const mp = platform.mp();
244
- const manifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(utils_1.MAINFEST_PATH).toString()));
243
+ const manifest = (0, utils_1.readManifest)(projectPath);
245
244
  const appid = manifest[opts.platform]?.appid;
246
245
  cmds = [
247
246
  'publish',
@@ -375,28 +374,28 @@ async function pullRemoteResources(opts) {
375
374
  const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
376
375
  const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
377
376
  const appId = pkg.appId;
378
- // 1. 获取应用信息
377
+ // 获取应用信息
379
378
  const appInfo = await (0, apis_1.getAppInfo)(appId);
380
379
  const { appName, iconUrl, configJson } = appInfo;
381
- // 2. 确定仓库地址
380
+ // 确定仓库地址
382
381
  const repoUrl = configJson.repo || config_1.CONFIG_DATA.pull?.repo;
383
- // 3. 确定分支:使用 buildEnv,默认 master;prod 对应 master 分支
382
+ // 确定分支:使用 buildEnv,默认 master;prod 对应 master 分支
384
383
  const buildEnv = process.env.BUILD_ENV;
385
384
  const branch = buildEnv.startsWith('pro') || !buildEnv ? 'master' : buildEnv;
386
- // 4. 拉取代码到 COMMAND_PATH/.repo/{appId}
385
+ // 拉取代码到 COMMAND_PATH/.repo/{appId}
387
386
  const repoDir = (0, path_1.join)(utils_1.COMMAND_PATH, '.repo', appId);
388
387
  if ((0, fs_1.existsSync)((0, path_1.join)(repoDir, '.git'))) {
389
388
  try {
390
389
  // 已有目录:fetch 目标分支 + 校验远程分支 + 切换 + pull
391
390
  const repoGit = (0, simple_git_1.default)(repoDir);
392
- // 0. 撤销上次构建残留的本地修改,防止拉取冲突
391
+ // 撤销上次构建残留的本地修改,防止拉取冲突
393
392
  await repoGit.reset(['--hard']);
394
- // 1. 拉取目标分支(显式指定,不受 --single-branch refspec 限制)
395
- // --prune 确保远程已删除的分支不会残留在本地引用中
393
+ // 拉取目标分支(显式指定,不受 --single-branch refspec 限制)
394
+ // --prune 确保远程已删除的分支不会残留在本地引用中
396
395
  await repoGit.fetch('origin', `+refs/heads/${branch}:refs/remotes/origin/${branch}`, ['--prune']);
397
- // 2. 切换分支:-B 强制创建/重置本地分支指向 origin/{branch}
396
+ // 切换分支:-B 强制创建/重置本地分支指向 origin/{branch}
398
397
  await repoGit.checkout(['-B', branch, `origin/${branch}`, '-f']);
399
- // 3. 拉取最新代码
398
+ // 拉取最新代码
400
399
  await repoGit.pull('origin', branch);
401
400
  }
402
401
  catch (err) {
@@ -415,14 +414,17 @@ async function pullRemoteResources(opts) {
415
414
  }
416
415
  }
417
416
  spinner.stop();
418
- // 5. 修改仓库 src/manifest.json 的 versionName 和 versionCode
419
- const manifestPath = (0, path_1.join)(repoDir, 'src', 'manifest.json');
420
- let manifestContent = (0, fs_1.readFileSync)(manifestPath, 'utf-8');
421
- manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name": "${appName}"`);
422
- manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${pkg.version}"`);
423
- manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode": ${pkg.versionCode}`);
424
- (0, fs_1.writeFileSync)(manifestPath, manifestContent);
425
- // 6. 修改仓库 package.json scripts
417
+ const manifestPath = (0, utils_1.getManifestPath)(repoDir);
418
+ const repoManifest = (0, utils_1.readManifest)(repoDir);
419
+ const isUniappX = (0, utils_1.isUniappXManifest)(repoManifest);
420
+ if (manifestPath) {
421
+ let manifestContent = (0, utils_1.readManifest)(repoDir, false);
422
+ manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name": "${appName}"`);
423
+ manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${pkg.version}"`);
424
+ manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode": ${pkg.versionCode}`);
425
+ (0, fs_1.writeFileSync)(manifestPath, manifestContent);
426
+ }
427
+ // 修改仓库 package.json scripts
426
428
  const repoPkgPath = (0, path_1.join)(repoDir, 'package.json');
427
429
  const repoPkg = (0, fs_extra_1.readJsonSync)(repoPkgPath);
428
430
  if (!repoPkg.scripts)
@@ -432,13 +434,19 @@ async function pullRemoteResources(opts) {
432
434
  repoPkg.scripts['copy:h5'] = 'gmcb copy -s ./dist/build/h5 -d ../../out/renderer/{package.appId}/ --clean';
433
435
  }
434
436
  if (opts.compiler === 'gradlew') {
435
- repoPkg.scripts['copy:android'] =
436
- 'gmcb copy -s ./dist/build/app -d ../../app/src/main/assets/apps/{manifest.appid}/www/ --clean';
437
+ if (isUniappX) {
438
+ repoPkg.scripts['copy:android'] =
439
+ 'gmcb copy -s ./unpackage/resources/app-android/{manifest.appid} -d ../../app/src/main/assets/apps/{manifest.appid}/ --clean';
440
+ }
441
+ else {
442
+ repoPkg.scripts['copy:android'] =
443
+ 'gmcb copy -s ./dist/build/app -d ../../app/src/main/assets/apps/{manifest.appid}/www/ --clean';
444
+ }
437
445
  }
438
446
  (0, fs_extra_1.writeJsonSync)(repoPkgPath, repoPkg, { spaces: 2 });
439
- // 7. 执行 npm install
447
+ // 执行 npm install
440
448
  (0, child_process_1.execSync)('npm install', { cwd: repoDir, stdio: 'inherit' });
441
- // 8. 构建 + 拷贝 + 修改主项目配置(根据 compiler 类型)
449
+ // 构建 + 拷贝 + 修改主项目配置(根据 compiler 类型)
442
450
  if (opts.compiler === 'electron-vite') {
443
451
  // 构建 H5 并拷贝
444
452
  (0, child_process_1.execSync)(`npm run build:h5:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
@@ -488,9 +496,8 @@ async function pullRemoteResources(opts) {
488
496
  (0, fs_1.copyFileSync)(iconPath, pushPath);
489
497
  }
490
498
  }
491
- // 9. updateMode=2 时打包资源为 zip/wgt
499
+ // updateMode=2 时打包资源为 zip/wgt
492
500
  if (config_1.CONFIG_DATA.publish?.updateMode == 2) {
493
- const repoManifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)((0, path_1.join)(repoDir, 'src', 'manifest.json'), 'utf-8')));
494
501
  const releaseDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'unpackage', 'release');
495
502
  (0, fs_extra_1.ensureDirSync)(releaseDir);
496
503
  if (opts.compiler === 'electron-vite') {
@@ -37,8 +37,6 @@ async function default_1(...args) {
37
37
  const resolvedDest = (0, utils_1.resolvePlaceholder)(opts.dest, data);
38
38
  const sourcePath = (0, path_1.join)(utils_1.COMMAND_PATH, resolvedSource);
39
39
  const destPath = (0, path_1.join)(utils_1.COMMAND_PATH, resolvedDest);
40
- const srcPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'src');
41
- const indexPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'index.html');
42
40
  let ignore = [];
43
41
  if (opts.clean) {
44
42
  (0, fs_extra_1.removeSync)(destPath);
@@ -63,8 +61,10 @@ async function default_1(...args) {
63
61
  'buildenv',
64
62
  'license',
65
63
  'readme.md',
64
+ 'agents.md',
66
65
  'vite.config.js',
67
66
  'vite.config.ts',
67
+ 'uni.build.json',
68
68
  'tsconfig.json',
69
69
  'package.json',
70
70
  'package-lock.json',
@@ -88,12 +88,5 @@ async function default_1(...args) {
88
88
  }
89
89
  }
90
90
  });
91
- if (srcPath === destPath && utils_1.COMMAND_PATH === sourcePath) {
92
- if ((0, fs_1.existsSync)(indexPath)) {
93
- (0, fs_extra_1.writeFileSync)(indexPath, (0, fs_extra_1.readFileSync)(indexPath)
94
- .toString()
95
- .replace(/(=['"])\.?(\/main\.)/i, '$1/src$2'));
96
- }
97
- }
98
91
  spinner.stop();
99
92
  }
@@ -1,19 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.default = default_1;
7
4
  const fs_1 = require("fs");
8
5
  const path_1 = require("path");
9
6
  const fs_extra_1 = require("fs-extra");
10
- const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
11
- const const_1 = require("../utils/const");
7
+ const utils_1 = require("../utils");
12
8
  const publish_1 = require("./publish");
13
9
  async function default_1() {
14
- const pkg = (0, fs_extra_1.readJsonSync)(const_1.PACKAGE_PATH);
15
- const repoManifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)((0, path_1.join)(const_1.COMMAND_PATH, '.repo', pkg.appId, 'src', 'manifest.json'), 'utf-8')));
16
- const gradleContent = (0, fs_1.readFileSync)((0, path_1.join)(const_1.COMMAND_PATH, 'app', 'build.gradle'), 'utf-8');
10
+ const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
11
+ const repoManifest = (0, utils_1.readManifest)((0, path_1.join)(utils_1.COMMAND_PATH, '.repo', pkg.appId));
12
+ const gradleContent = (0, fs_1.readFileSync)((0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle'), 'utf-8');
17
13
  const versionName = gradleContent.match(/versionName\s+"([^"]*)"/)?.[1];
18
14
  const versionCode = gradleContent.match(/versionCode\s+(\d+)/)?.[1];
19
15
  await (0, publish_1.publish)({
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.default = default_1;
7
- const fs_1 = require("fs");
8
4
  const path_1 = require("path");
9
5
  const fs_extra_1 = require("fs-extra");
10
- const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
11
- const const_1 = require("../utils/const");
6
+ const utils_1 = require("../utils");
12
7
  const publish_1 = require("./publish");
13
8
  async function default_1() {
14
- const pkg = (0, fs_extra_1.readJsonSync)(const_1.PACKAGE_PATH);
15
- const repoManifest = JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)((0, path_1.join)(const_1.COMMAND_PATH, '.repo', pkg.appId, 'src', 'manifest.json'), 'utf-8')));
9
+ const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
10
+ const repoManifest = (0, utils_1.readManifest)((0, path_1.join)(utils_1.COMMAND_PATH, '.repo', pkg.appId));
16
11
  await (0, publish_1.publish)({
17
12
  files: [
18
13
  { ext: 'zip', name: repoManifest.appid, path: 'unpackage/release' },
@@ -1,8 +1,12 @@
1
- export declare function readManifest(): Record<string, unknown>;
1
+ /** 工程 manifest 实际路径:src/manifest.json 优先,其次根目录;不存在返回 undefined */
2
+ export declare function getManifestPath(path?: string): string | undefined;
3
+ export declare function readManifest(path?: string): Record<string, unknown>;
4
+ export declare function readManifest(path: string | undefined, parse: false): string;
2
5
  /**
3
6
  * 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
7
+ * @param pathOrManifest 工程目录(自动读取 manifest.json)或已解析的 manifest 对象
4
8
  */
5
- export declare function isUniappXManifest(manifest?: Record<string, unknown>): boolean;
9
+ export declare function isUniappXManifest(pathOrManifest?: string | Record<string, unknown>): boolean;
6
10
  export declare function objectToCommand(obj?: Record<string, any>): {};
7
11
  export declare function filterToArray(obj?: Record<string, any>): any[];
8
12
  export declare function spawnSync(command?: string): import("child_process").SpawnSyncReturns<Buffer>;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getManifestPath = getManifestPath;
6
7
  exports.readManifest = readManifest;
7
8
  exports.isUniappXManifest = isUniappXManifest;
8
9
  exports.objectToCommand = objectToCommand;
@@ -18,19 +19,29 @@ const cross_spawn_1 = __importDefault(require("cross-spawn"));
18
19
  const flat_1 = require("flat");
19
20
  const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
20
21
  const const_1 = require("./const");
21
- function readManifest() {
22
- const candidates = [(0, path_1.join)(const_1.COMMAND_PATH, 'src', 'manifest.json'), (0, path_1.join)(const_1.COMMAND_PATH, 'manifest.json')];
23
- for (const p of candidates) {
24
- if (!(0, fs_1.existsSync)(p))
25
- continue;
26
- return JSON.parse((0, strip_json_comments_1.default)((0, fs_1.readFileSync)(p, 'utf-8')));
27
- }
28
- return {};
22
+ /** 工程 manifest 实际路径:src/manifest.json 优先,其次根目录;不存在返回 undefined */
23
+ function getManifestPath(path = const_1.COMMAND_PATH) {
24
+ const candidates = [(0, path_1.join)(path, 'src', 'manifest.json'), (0, path_1.join)(path, 'manifest.json')];
25
+ return candidates.find((p) => (0, fs_1.existsSync)(p));
26
+ }
27
+ /**
28
+ * 读取指定工程目录的 manifest.json
29
+ * @param path 工程目录,默认当前工程
30
+ * @param parse 是否解析为对象(默认 true);false 时返回原始文本(保留注释,便于回写),文件不存在时返回空字符串
31
+ */
32
+ function readManifest(path = const_1.COMMAND_PATH, parse = true) {
33
+ const manifestPath = getManifestPath(path);
34
+ if (!manifestPath)
35
+ return parse ? {} : '';
36
+ const content = (0, fs_1.readFileSync)(manifestPath, 'utf-8');
37
+ return parse ? JSON.parse((0, strip_json_comments_1.default)(content)) : content;
29
38
  }
30
39
  /**
31
40
  * 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
41
+ * @param pathOrManifest 工程目录(自动读取 manifest.json)或已解析的 manifest 对象
32
42
  */
33
- function isUniappXManifest(manifest = readManifest()) {
43
+ function isUniappXManifest(pathOrManifest = const_1.COMMAND_PATH) {
44
+ const manifest = typeof pathOrManifest === 'string' ? readManifest(pathOrManifest) : pathOrManifest;
34
45
  return Object.prototype.hasOwnProperty.call(manifest, 'uni-app-x');
35
46
  }
36
47
  function objectToCommand(obj = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmcb/cli",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
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": "9035e1ec3a89eb7d2c864ce0c0280e48759e2d04"
61
+ "gitHead": "f956db3be94b1fe42f1d313f27593f2eec5cb0e2"
62
62
  }