@gmcb/cli 0.9.10 → 0.9.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 ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ <!-- release:insert -->
4
+
5
+ ## 0.9.11 [2026-11-14]
6
+ <!-- generated-by: specs -->
7
+ ### 优化
8
+ - npm 发布包包含 `CHANGELOG.md`,安装后可查看版本发布说明。
package/README.md CHANGED
@@ -1,48 +1,49 @@
1
- # @gmcb/cli
2
-
3
- 工茂草本前端命令行工具:创建、开发、构建、发布、资源复制、图标/启动图与技能同步。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm i @gmcb/cli -g
9
- ```
10
-
11
- ## 命令
12
-
13
- | 命令 | 描述 |
14
- | ------------------------------------- | ---------------------------------------------- |
15
- | `gmcb create` | 创建项目框架 |
16
- | `gmcb dev` | 应用程序开发 |
17
- | `gmcb build` | 应用程序构建 |
18
- | `gmcb publish` | 应用程序发布 |
19
- | `gmcb copy` | 复制资源到指定目录 |
20
- | `gmcb config` | 配置管理 |
21
- | `gmcb icon` | 生成应用图标(圆角 PNG / ICO) |
22
- | `gmcb image` | 按 LOGO 生成启动图(白底 + 可选 9-patch 边框) |
23
- | `gmcb skill sync` / `gmcb skill list` | 同步 / 列出项目技能 |
24
-
25
- ## 快速开始
26
-
27
- ```bash
28
- # H5 构建(web 为 h5 别名)
29
- gmcb build -p h5
30
-
31
- # App 热更新资源(uni-app x 蒸汽模式)
32
- gmcb build -p app --wgt
33
-
34
- # 自动发布(跳过确认)
35
- gmcb publish -p app --wgt -a
36
-
37
- # 生成圆角应用图标
38
- gmcb icon --source logo.png
39
- ```
40
-
41
- - 构建环境用 `-e <env>` 选择,默认 `prod`。
42
- - HBuilderX CLI 路径用 `gmcb config --cli.hbuilderx <path>` 配置。
43
- - `uni.build.json` 可配置 wgt 文件名/输出路径与发布参数。
44
- - 项目模板仓库与技能仓库需显式配置(无内置默认值):`gmcb config --template.repo <repo-url>`、`gmcb config --skill.repo <repo-url>`;未配置时 `gmcb create` / `gmcb skill sync` 会提示先添加。
45
-
46
- ## 文档
47
-
48
- - 完整命令选项、uni-app x 兼容、平台映射与 icon/image/copy 规则:[AGENTS.md](AGENTS.md)
1
+ # @gmcb/cli
2
+
3
+ 工茂草本前端命令行工具:创建、开发、构建、发布、资源复制、图标/启动图与技能同步。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm i @gmcb/cli -g
9
+ ```
10
+
11
+ ## 命令
12
+
13
+ | 命令 | 描述 |
14
+ | ------------------------------------- | ---------------------------------------------- |
15
+ | `gmcb create` | 创建项目框架 |
16
+ | `gmcb dev` | 应用程序开发 |
17
+ | `gmcb build` | 应用程序构建 |
18
+ | `gmcb publish` | 应用程序发布 |
19
+ | `gmcb copy` | 复制资源到指定目录 |
20
+ | `gmcb config` | 配置管理 |
21
+ | `gmcb icon` | 生成应用图标(圆角 PNG / ICO) |
22
+ | `gmcb image` | 按 LOGO 生成启动图(白底 + 可选 9-patch 边框) |
23
+ | `gmcb skill sync` / `gmcb skill list` | 同步 / 列出项目技能 |
24
+
25
+ ## 快速开始
26
+
27
+ ```bash
28
+ # H5 构建(web 为 h5 别名)
29
+ gmcb build -p h5
30
+
31
+ # App 热更新资源(uni-app x 蒸汽模式)
32
+ gmcb build -p app --wgt
33
+
34
+ # 自动发布(跳过确认)
35
+ gmcb publish -p app --wgt -a
36
+
37
+ # 生成圆角应用图标
38
+ gmcb icon --source logo.png
39
+ ```
40
+
41
+ - 构建环境用 `-e <env>` 选择,默认 `prod`。
42
+ - HBuilderX CLI 路径用 `gmcb config --cli.hbuilderx <path>` 配置。
43
+ - `uni.build.json` 可配置 wgt 文件名/输出路径与发布参数。
44
+ - 项目模板仓库与技能仓库需显式配置(无内置默认值):`gmcb config --template.repo <repo-url>`、`gmcb config --skill.repo <repo-url>`;未配置时 `gmcb create` / `gmcb skill sync` 会提示先添加。
45
+
46
+ ## 文档
47
+
48
+ - 操作约束与命令:[AGENTS.md](AGENTS.md)
49
+ - 完整命令选项、uni-app x 兼容、平台映射与 icon/image/copy 规则:[specs/implementation.md](specs/implementation.md)
@@ -45,7 +45,6 @@ const utils_1 = require("../utils");
45
45
  const config_1 = require("../utils/config");
46
46
  const apis_1 = require("../apis");
47
47
  let envPath = utils_1.BUILD_ENV_PATH;
48
- // 主项目文件快照:value 为 null 表示写入前该文件不存在,还原时应删除
49
48
  const remoteBackups = new Map();
50
49
  function backup(p) {
51
50
  if (remoteBackups.has(p))
@@ -166,7 +165,6 @@ async function getCommands(...args) {
166
165
  }
167
166
  const isUniappX = (0, utils_1.isUniappXManifest)(projectPath);
168
167
  const isUniappXApp = isUniappX && opts.platform.startsWith('app');
169
- // 无 src、uni-app x 的 App 平台、-P 指定了不同的 HBuilderX 项目名时都必须由 HBuilderX 构建,统一归一到 opts.pack
170
168
  if (!utils_1.HAS_SRC || isUniappXApp || projectName !== currentName) {
171
169
  opts.pack = true;
172
170
  }
@@ -195,7 +193,6 @@ async function getCommands(...args) {
195
193
  const isHarmony = opts.platform === 'app-harmony';
196
194
  if (opts.wgt) {
197
195
  if (opts.pack) {
198
- // HBuilderX CLI publish 流程
199
196
  let index = app.wgt.indexOf('--path');
200
197
  if (index === -1) {
201
198
  index = app.wgt.length;
@@ -215,7 +212,6 @@ async function getCommands(...args) {
215
212
  ];
216
213
  }
217
214
  else {
218
- // 普通构建,后续由 generatePackage 打包 wgt
219
215
  commands = [...commands, bin, 'build -p', opts.platform];
220
216
  cmds = null;
221
217
  }
@@ -258,7 +254,6 @@ async function getCommands(...args) {
258
254
  utils_1.log.error(`不支持的平台:${opts.platform}`);
259
255
  }
260
256
  if (cmds) {
261
- // HBuilderX CLI 的 --project 支持绝对路径:统一传工程目录(--source 时为源码工程目录),无需先 project open
262
257
  commands = [...commands, config_1.CONFIG_DATA?.cli?.hbuilderx, ...cmds, '--project', projectPath];
263
258
  }
264
259
  }
@@ -374,28 +369,18 @@ async function pullRemoteResources(opts) {
374
369
  const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
375
370
  const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
376
371
  const appId = pkg.appId;
377
- // 获取应用信息
378
372
  const appInfo = await (0, apis_1.getAppInfo)(appId);
379
373
  const { appName, iconUrl, configJson } = appInfo;
380
- // 确定仓库地址
381
374
  const repoUrl = configJson.repo || config_1.CONFIG_DATA.pull?.repo;
382
- // 确定分支:使用 buildEnv,默认 master;prod 对应 master 分支
383
375
  const buildEnv = process.env.BUILD_ENV;
384
376
  const branch = buildEnv.startsWith('pro') || !buildEnv ? 'master' : buildEnv;
385
- // 拉取代码到 COMMAND_PATH/.repo/{appId}
386
377
  const repoDir = (0, path_1.join)(utils_1.COMMAND_PATH, '.repo', appId);
387
378
  if ((0, fs_1.existsSync)((0, path_1.join)(repoDir, '.git'))) {
388
379
  try {
389
- // 已有目录:fetch 目标分支 + 校验远程分支 + 切换 + pull
390
380
  const repoGit = (0, simple_git_1.default)(repoDir);
391
- // 撤销上次构建残留的本地修改,防止拉取冲突
392
381
  await repoGit.reset(['--hard']);
393
- // 拉取目标分支(显式指定,不受 --single-branch refspec 限制)
394
- // --prune 确保远程已删除的分支不会残留在本地引用中
395
382
  await repoGit.fetch('origin', `+refs/heads/${branch}:refs/remotes/origin/${branch}`, ['--prune']);
396
- // 切换分支:-B 强制创建/重置本地分支指向 origin/{branch}
397
383
  await repoGit.checkout(['-B', branch, `origin/${branch}`, '-f']);
398
- // 拉取最新代码
399
384
  await repoGit.pull('origin', branch);
400
385
  }
401
386
  catch (err) {
@@ -403,7 +388,6 @@ async function pullRemoteResources(opts) {
403
388
  }
404
389
  }
405
390
  else {
406
- // 新克隆:直接使用 branch 分支,失败则抛出异常
407
391
  (0, fs_extra_1.ensureDirSync)((0, path_1.join)(utils_1.COMMAND_PATH, '.repo'));
408
392
  const cloneGit = (0, simple_git_1.default)();
409
393
  try {
@@ -424,7 +408,6 @@ async function pullRemoteResources(opts) {
424
408
  manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode": ${pkg.versionCode}`);
425
409
  (0, fs_1.writeFileSync)(manifestPath, manifestContent);
426
410
  }
427
- // 修改仓库 package.json scripts
428
411
  const repoPkgPath = (0, path_1.join)(repoDir, 'package.json');
429
412
  const repoPkg = (0, fs_extra_1.readJsonSync)(repoPkgPath);
430
413
  if (!repoPkg.scripts)
@@ -444,20 +427,15 @@ async function pullRemoteResources(opts) {
444
427
  }
445
428
  }
446
429
  (0, fs_extra_1.writeJsonSync)(repoPkgPath, repoPkg, { spaces: 2 });
447
- // 执行 npm install
448
430
  (0, child_process_1.execSync)('npm install', { cwd: repoDir, stdio: 'inherit' });
449
- // 构建 + 拷贝 + 修改主项目配置(根据 compiler 类型)
450
431
  if (opts.compiler === 'electron-vite') {
451
- // 构建 H5 并拷贝
452
432
  (0, child_process_1.execSync)(`npm run build:h5:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
453
433
  (0, child_process_1.execSync)('npm run copy:h5', { cwd: repoDir, stdio: 'inherit' });
454
- // 修改主项目 package.json 中的应用名称
455
434
  const pkgPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'package.json');
456
435
  let pkgContent = (0, fs_1.readFileSync)(pkgPath, 'utf-8');
457
436
  pkgContent = pkgContent.replace(/"productName":\s*"[^"]*"/, `"productName": "${appName}"`);
458
437
  backup(pkgPath);
459
438
  (0, fs_1.writeFileSync)(pkgPath, pkgContent);
460
- // 下载图标
461
439
  if (iconUrl) {
462
440
  (0, fs_extra_1.ensureDirSync)((0, path_1.join)(utils_1.COMMAND_PATH, 'res'));
463
441
  const iconPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'res', 'icon.png');
@@ -471,20 +449,17 @@ async function pullRemoteResources(opts) {
471
449
  if (opts.compiler === 'gradlew') {
472
450
  (0, child_process_1.execSync)(`npm run build:android:${buildEnv}`, { cwd: repoDir, stdio: 'inherit' });
473
451
  (0, child_process_1.execSync)('npm run copy:android', { cwd: repoDir, stdio: 'inherit' });
474
- // 修改主项目 strings.xml 中的应用名称
475
452
  const stringsPath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'values', 'strings.xml');
476
453
  let stringsContent = (0, fs_1.readFileSync)(stringsPath, 'utf-8');
477
454
  stringsContent = stringsContent.replace(/<string name="app_name">[^<]*<\/string>/, `<string name="app_name">${appName}</string>`);
478
455
  backup(stringsPath);
479
456
  (0, fs_1.writeFileSync)(stringsPath, stringsContent);
480
- // 修改主项目 build.gradle(versionName/versionCode 取 COMMAND_PATH/package.json 对应值)
481
457
  const gradlePath = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'build.gradle');
482
458
  let gradleContent = (0, fs_1.readFileSync)(gradlePath, 'utf-8');
483
459
  gradleContent = gradleContent.replace(/versionName\s+"[^"]*"/, `versionName "${pkg.version}"`);
484
460
  gradleContent = gradleContent.replace(/versionCode\s+\d+/, `versionCode ${pkg.versionCode}`);
485
461
  backup(gradlePath);
486
462
  (0, fs_1.writeFileSync)(gradlePath, gradleContent);
487
- // 下载图标
488
463
  if (iconUrl) {
489
464
  const drawableDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'app', 'src', 'main', 'res', 'drawable-xxhdpi');
490
465
  (0, fs_extra_1.ensureDirSync)(drawableDir);
@@ -496,7 +471,6 @@ async function pullRemoteResources(opts) {
496
471
  (0, fs_1.copyFileSync)(iconPath, pushPath);
497
472
  }
498
473
  }
499
- // updateMode=2 时打包资源为 zip/wgt
500
474
  if (config_1.CONFIG_DATA.publish?.updateMode == 2) {
501
475
  const releaseDir = (0, path_1.join)(utils_1.COMMAND_PATH, 'unpackage', 'release');
502
476
  (0, fs_extra_1.ensureDirSync)(releaseDir);
@@ -542,7 +516,6 @@ async function default_1(...args) {
542
516
  if ((0, fs_1.existsSync)(envPath)) {
543
517
  (0, fs_1.unlinkSync)(envPath);
544
518
  }
545
- // H5 构建完成后立即生成 manifest.json
546
519
  if (opts.compiler === 'uni' && opts.platform === 'h5') {
547
520
  generateH5Manifest();
548
521
  }
@@ -41,7 +41,6 @@ async function default_1(opts) {
41
41
  (0, fs_1.mkdirSync)(destDir, { recursive: true });
42
42
  }
43
43
  const nameWithoutExt = (0, path_1.basename)(sourcePath, (0, path_1.extname)(sourcePath));
44
- // 传 --ico 时先生成 ICO 文件,避免 --size 覆盖原图后读取到缩放后的源文件
45
44
  if (opts.ico) {
46
45
  const pngBuffers = await (0, utils_1.generateRoundedPngs)(sourcePath, utils_1.ICO_SIZES, radius);
47
46
  const icoBuffer = (0, utils_1.packIcoBuffer)(pngBuffers);
@@ -50,7 +49,6 @@ async function default_1(opts) {
50
49
  const icoKb = (icoBuffer.length / 1024).toFixed(1);
51
50
  console.log(`ICO 生成完成: ${icoPath} (${icoKb} KB, sizes: ${utils_1.ICO_SIZES.join(', ')})`);
52
51
  }
53
- // 未传尺寸时输出原尺寸圆角 PNG;--size 缩放后覆盖原图;--sizes 按 原文件名_size 命名生成副本
54
52
  if (sizeList) {
55
53
  for (const s of sizeList) {
56
54
  const roundedPng = await (0, utils_1.generateRoundedPng)(sourcePath, s, radius);
@@ -53,7 +53,6 @@ async function default_1(...args) {
53
53
  }
54
54
  if (/^(app|h5)/.test(opts.platform)) {
55
55
  if (isPublishFlow) {
56
- // publish 流程
57
56
  if (!config_1.CONFIG_DATA.publish?.platform && config_1.CONFIG_DATA.publish?.publishType == 1) {
58
57
  const { platform } = await inquirer_1.default.prompt([
59
58
  {
@@ -91,9 +90,6 @@ async function default_1(...args) {
91
90
  ]);
92
91
  pub.updateType = updateType;
93
92
  }
94
- // --wgt/--zip 一律热更新
95
- // --win/--apk 一律整包更新
96
- // --pull 则提示热更新还是整包更新
97
93
  if (opts.win || opts.apk) {
98
94
  pub.updateMode = 1;
99
95
  if (opts.pull && !config_1.CONFIG_DATA.publish?.updateMode) {
@@ -113,7 +109,6 @@ async function default_1(...args) {
113
109
  }
114
110
  }
115
111
  else {
116
- // pub 流程
117
112
  if (!config_1.CONFIG_DATA.pub?.platform) {
118
113
  const { platform } = await inquirer_1.default.prompt([
119
114
  {
@@ -189,11 +184,9 @@ async function default_1(...args) {
189
184
  (0, utils_1.spawnSync)(config_1.CONFIG_DATA.install || 'npm install');
190
185
  }
191
186
  else {
192
- // uni-app x 的 HBuilderX 工程通常没有 package.json,无需安装依赖
193
187
  utils_1.log.warning('未检测到 package.json,跳过依赖安装');
194
188
  }
195
189
  }
196
- // 更新 CONFIG_DATA(build 之前,确保 fetchRemoteResources 能读取到)
197
190
  if (isPublishFlow) {
198
191
  if (!config_1.CONFIG_DATA.publish) {
199
192
  config_1.CONFIG_DATA.publish = {};
@@ -228,7 +221,6 @@ async function default_1(...args) {
228
221
  else {
229
222
  cmds = await (0, build_1.default)(opts, true);
230
223
  }
231
- // 从 cmds 提取 buildEnv:无 package.json 的 uni-app x 工程命令中没有 cross-env/BUILD_ENV,回退到进程环境变量
232
224
  const buildEnv = cmds.find((cmd) => cmd.startsWith('BUILD_ENV='))?.split('=')[1] || process.env.BUILD_ENV;
233
225
  if (!buildEnv || !['dev', 'sit', 'uat', 'pre', 'pro', 'prod'].includes(buildEnv)) {
234
226
  utils_1.log.error('没有检测到需要发布的环境,无法完成上传,请切换到dev/sit/uat/pre/master分支再次执行脚本,或者您可以选择手动上传!');
@@ -119,7 +119,7 @@ export declare function uploadVersion(params: VersionParams): Promise<void>;
119
119
  */
120
120
  export declare function publishVersion(params: VersionParams): Promise<void>;
121
121
  /**
122
- * 获取最新版本信息(自动登录)
122
+ * 获取最新版本信息
123
123
  */
124
124
  export declare function fetchLatestVersion(params: {
125
125
  appId: string;
@@ -131,7 +131,7 @@ export declare function fetchLatestVersion(params: {
131
131
  updateMode: any;
132
132
  }>;
133
133
  /**
134
- * 获取应用信息(自动登录)
134
+ * 获取应用信息
135
135
  */
136
136
  export declare function getAppInfo(appId: string): Promise<{
137
137
  appName: any;
package/lib/apis/index.js CHANGED
@@ -91,7 +91,7 @@ function getVersionHistory(params) {
91
91
  */
92
92
  async function uploadVersion(params) {
93
93
  try {
94
- const { brand, type, status, platform, path, remoteUrl, versionName, versionCode, } = params;
94
+ const { brand, type, status, platform, path, remoteUrl, versionName, versionCode } = params;
95
95
  let brandId = '';
96
96
  await ensureLoggedIn();
97
97
  const { data: brandList } = await getBrandList();
@@ -201,7 +201,7 @@ async function publishVersion(params) {
201
201
  }
202
202
  }
203
203
  /**
204
- * 获取最新版本信息(自动登录)
204
+ * 获取最新版本信息
205
205
  */
206
206
  async function fetchLatestVersion(params) {
207
207
  try {
@@ -231,7 +231,7 @@ async function fetchLatestVersion(params) {
231
231
  }
232
232
  }
233
233
  /**
234
- * 获取应用信息(自动登录)
234
+ * 获取应用信息
235
235
  */
236
236
  async function getAppInfo(appId) {
237
237
  try {
@@ -10,7 +10,6 @@ async function default_1() {
10
10
  const buildEnv = process.env.BUILD_ENV || '';
11
11
  const manifest = (0, utils_1.readManifest)();
12
12
  const appid = manifest['mp-weixin']?.appid;
13
- // uni-app x 的 appid 为空时 miniprogram-ci 报错难以理解,这里提前给出明确提示(经典 uni-app 保持原有行为)
14
13
  if (!appid && (0, utils_1.isUniappXManifest)(manifest)) {
15
14
  utils_1.log.error('manifest.json 中未配置 mp-weixin.appid,无法上传微信小程序,请先在 manifest.json 的 mp-weixin 节点中配置 appid!');
16
15
  }
@@ -23,19 +23,19 @@ export declare const BASE_URL: {
23
23
  prod: string;
24
24
  };
25
25
  export declare enum APP_TYPE {
26
- '医生端' = 1,
27
- '门店端' = 2,
28
- '患者端' = 3
26
+ 医生端 = 1,
27
+ 门店端 = 2,
28
+ 患者端 = 3
29
29
  }
30
30
  export declare enum CHANNEL_TYPE {
31
- '患者端' = 1,
32
- '医生端' = 2,
33
- '门店端' = 3
31
+ 患者端 = 1,
32
+ 医生端 = 2,
33
+ 门店端 = 3
34
34
  }
35
35
  export declare enum PLATFORM_TYPE {
36
- 'Android' = 1,
37
- 'iOS' = 2,
38
- 'Harmony' = 3,
39
- 'Windows' = 4,
40
- 'macOS' = 5
36
+ Android = 1,
37
+ iOS = 2,
38
+ Harmony = 3,
39
+ Windows = 4,
40
+ macOS = 5
41
41
  }
@@ -48,14 +48,12 @@ exports.BASE_URL = {
48
48
  pre: 'https://pre-api.shewenzhongyi.com',
49
49
  prod: 'https://api.shewenzhongyi.com',
50
50
  };
51
- // 旧版
52
51
  var APP_TYPE;
53
52
  (function (APP_TYPE) {
54
53
  APP_TYPE[APP_TYPE["\u533B\u751F\u7AEF"] = 1] = "\u533B\u751F\u7AEF";
55
54
  APP_TYPE[APP_TYPE["\u95E8\u5E97\u7AEF"] = 2] = "\u95E8\u5E97\u7AEF";
56
55
  APP_TYPE[APP_TYPE["\u60A3\u8005\u7AEF"] = 3] = "\u60A3\u8005\u7AEF";
57
56
  })(APP_TYPE || (exports.APP_TYPE = APP_TYPE = {}));
58
- // 新版
59
57
  var CHANNEL_TYPE;
60
58
  (function (CHANNEL_TYPE) {
61
59
  CHANNEL_TYPE[CHANNEL_TYPE["\u60A3\u8005\u7AEF"] = 1] = "\u60A3\u8005\u7AEF";
@@ -1,10 +1,10 @@
1
- /** 工程 manifest 实际路径:src/manifest.json 优先,其次根目录;不存在返回 undefined */
1
+ /** 获取工程 manifest.json 路径,不存在时返回 undefined */
2
2
  export declare function getManifestPath(path?: string): string | undefined;
3
3
  export declare function readManifest(path?: string): Record<string, unknown>;
4
4
  export declare function readManifest(path: string | undefined, parse: false): string;
5
5
  /**
6
- * 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
7
- * @param pathOrManifest 工程目录(自动读取 manifest.json)或已解析的 manifest 对象
6
+ * 判断是否 uni-app x 工程。
7
+ * @param pathOrManifest 工程目录或已解析的 manifest 对象
8
8
  */
9
9
  export declare function isUniappXManifest(pathOrManifest?: string | Record<string, unknown>): boolean;
10
10
  export declare function objectToCommand(obj?: Record<string, any>): {};
@@ -19,15 +19,15 @@ const cross_spawn_1 = __importDefault(require("cross-spawn"));
19
19
  const flat_1 = require("flat");
20
20
  const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
21
21
  const const_1 = require("./const");
22
- /** 工程 manifest 实际路径:src/manifest.json 优先,其次根目录;不存在返回 undefined */
22
+ /** 获取工程 manifest.json 路径,不存在时返回 undefined */
23
23
  function getManifestPath(path = const_1.COMMAND_PATH) {
24
24
  const candidates = [(0, path_1.join)(path, 'src', 'manifest.json'), (0, path_1.join)(path, 'manifest.json')];
25
25
  return candidates.find((p) => (0, fs_1.existsSync)(p));
26
26
  }
27
27
  /**
28
- * 读取指定工程目录的 manifest.json
28
+ * 读取指定工程目录的 manifest.json。
29
29
  * @param path 工程目录,默认当前工程
30
- * @param parse 是否解析为对象(默认 true);false 时返回原始文本(保留注释,便于回写),文件不存在时返回空字符串
30
+ * @param parse 是否解析为对象,默认 true;false 时返回原始文本
31
31
  */
32
32
  function readManifest(path = const_1.COMMAND_PATH, parse = true) {
33
33
  const manifestPath = getManifestPath(path);
@@ -37,8 +37,8 @@ function readManifest(path = const_1.COMMAND_PATH, parse = true) {
37
37
  return parse ? JSON.parse((0, strip_json_comments_1.default)(content)) : content;
38
38
  }
39
39
  /**
40
- * 是否 uni-app x 工程(manifest.json 含 uni-app-x 字段,空对象也算)
41
- * @param pathOrManifest 工程目录(自动读取 manifest.json)或已解析的 manifest 对象
40
+ * 判断是否 uni-app x 工程。
41
+ * @param pathOrManifest 工程目录或已解析的 manifest 对象
42
42
  */
43
43
  function isUniappXManifest(pathOrManifest = const_1.COMMAND_PATH) {
44
44
  const manifest = typeof pathOrManifest === 'string' ? readManifest(pathOrManifest) : pathOrManifest;
@@ -15,13 +15,13 @@ export interface SplashBox {
15
15
  export interface SplashGenerateOptions {
16
16
  /** 品牌 LOGO 图片 Buffer */
17
17
  logo: Buffer;
18
- /** 画布宽度(含 .9 的 1px 边框) */
18
+ /** 画布宽度 */
19
19
  width: number;
20
- /** 画布高度(含 .9 的 1px 边框) */
20
+ /** 画布高度 */
21
21
  height: number;
22
- /** LOGO 左右边距(右 = 左,水平居中) */
22
+ /** LOGO 左右边距 */
23
23
  left: number;
24
- /** LOGO 可见内容区距画布顶部距离 */
24
+ /** LOGO 距画布顶部距离 */
25
25
  top: number;
26
26
  /** 背景色 */
27
27
  background: SplashRgba;
@@ -31,28 +31,31 @@ export interface SplashGenerateOptions {
31
31
  export interface SplashGenerateInfo {
32
32
  width: number;
33
33
  height: number;
34
- /** 背景色,如 #ffffff */
34
+ /** 背景色 */
35
35
  background: string;
36
36
  ninePatch: boolean;
37
- /** LOGO 可见内容区在输出图中的位置 */
37
+ /** LOGO 在输出图中的位置 */
38
38
  logoBox: SplashBox;
39
- /** LOGO 自身不透明背景色(透明底为 null) */
39
+ /** LOGO 自身背景色,透明底为 null */
40
40
  logoBackground: string | null;
41
41
  logoScale: number;
42
- /** LOGO 源图可见内容区 */
42
+ /** LOGO 源图内容区 */
43
43
  logoSource: SplashBox;
44
44
  }
45
- /** 默认画布尺寸,与现有启动图一致 */
45
+ /** 默认画布尺寸 */
46
46
  export declare const DEFAULT_SPLASH_WIDTH = 1082;
47
47
  export declare const DEFAULT_SPLASH_HEIGHT = 1884;
48
- /** 现有设计稿(1082×1884)中 LOGO 的左右边距与顶部距离 */
48
+ /** 默认 LOGO 左右边距与顶部距离 */
49
49
  export declare const DEFAULT_SPLASH_LEFT = 421;
50
50
  export declare const DEFAULT_SPLASH_TOP = 451;
51
51
  /** 解析正整数选项 */
52
52
  export declare function parsePositiveInt(value: string, label: string): number;
53
53
  /**
54
- * 解析长度选项:支持像素整数与百分比(相对 base 换算)
55
- * 例如:parseLength('421', 1082) => 421;parseLength('40%', 1082) => 433
54
+ * 解析长度选项,支持像素整数与百分比。
55
+ * @param value 长度文本,如 `421`、`40%`
56
+ * @param base 百分比换算基准
57
+ * @param label 错误信息中的选项名
58
+ * @returns 换算后的像素值
56
59
  */
57
60
  export declare function parseLength(value: string, base: number, label: string): number;
58
61
  /** 解析 #rgb / #rrggbb 颜色 */
@@ -60,20 +63,19 @@ export declare function parseHexColor(value: string): SplashRgba;
60
63
  /** 颜色转 #rrggbb */
61
64
  export declare function colorToHex(color: SplashRgba): string;
62
65
  /**
63
- * 解析输出文件名:
64
- * - 默认 splash.9 => splash.9.png(9-patch)
65
- * - splash => splash.png(普通 PNG)
66
- * - 兼容传入 splash.9.png
66
+ * 解析启动图输出文件名。
67
+ * @param value 文件名,默认 `splash.9`;以 `.9` 结尾生成 9-patch
68
+ * @returns 文件名与是否 9-patch
67
69
  */
68
70
  export declare function normalizeSplashName(value?: string): {
69
71
  fileName: string;
70
72
  ninePatch: boolean;
71
73
  };
72
- /** 按现有设计稿比例换算默认左右边距 */
74
+ /** 按画布宽度换算默认左右边距 */
73
75
  export declare function defaultSplashLeft(width: number): number;
74
- /** 按现有设计稿比例换算默认顶部距离 */
76
+ /** 按画布高度换算默认顶部距离 */
75
77
  export declare function defaultSplashTop(height: number): number;
76
- /** 查找输出目录中已有的启动图(依次:目标文件、splash.9.png、splash.png) */
78
+ /** 查找输出目录中已有的启动图,不存在时返回 null */
77
79
  export declare function findReferenceSplash(destDir: string, fileName: string): string | null;
78
80
  /** 读取图片尺寸 */
79
81
  export declare function readImageSize(input: string | Buffer): Promise<{
@@ -81,17 +83,16 @@ export declare function readImageSize(input: string | Buffer): Promise<{
81
83
  height: number;
82
84
  }>;
83
85
  /**
84
- * 从 RGBA 原始像素中识别可见内容区(排除透明与白底留白)
86
+ * 从 RGBA 原始像素中识别可见内容区
85
87
  * @returns 内容包围盒;无内容返回 null
86
88
  */
87
89
  export declare function detectContentBox(data: Buffer, width: number, height: number): SplashBox | null;
88
90
  /** 识别 LOGO 可见内容区 */
89
91
  export declare function detectLogoContentBox(logo: Buffer): Promise<SplashBox>;
90
92
  /**
91
- * 按 LOGO 生成启动图
92
- * - LOGO 可见宽度 = 画布宽 - 2 × left,高度按 LOGO 内容宽高比等比计算
93
- * - 水平居中(右间距 = 左间距),顶部距离为 top
94
- * - ninePatch 为 true 时生成与现有 splash.9.png 一致的边框与拉伸标记
93
+ * 按 LOGO 生成启动图。
94
+ * @param options 画布与 LOGO 生成选项
95
+ * @returns PNG Buffer 及生成信息
95
96
  */
96
97
  export declare function generateSplash(options: SplashGenerateOptions): Promise<{
97
98
  buffer: Buffer;
@@ -19,10 +19,10 @@ exports.generateSplash = generateSplash;
19
19
  const fs_1 = require("fs");
20
20
  const path_1 = require("path");
21
21
  const sharp_1 = __importDefault(require("sharp"));
22
- /** 默认画布尺寸,与现有启动图一致 */
22
+ /** 默认画布尺寸 */
23
23
  exports.DEFAULT_SPLASH_WIDTH = 1082;
24
24
  exports.DEFAULT_SPLASH_HEIGHT = 1884;
25
- /** 现有设计稿(1082×1884)中 LOGO 的左右边距与顶部距离 */
25
+ /** 默认 LOGO 左右边距与顶部距离 */
26
26
  exports.DEFAULT_SPLASH_LEFT = 421;
27
27
  exports.DEFAULT_SPLASH_TOP = 451;
28
28
  const ALPHA_OPAQUE = 200;
@@ -43,8 +43,11 @@ function parsePositiveInt(value, label) {
43
43
  return num;
44
44
  }
45
45
  /**
46
- * 解析长度选项:支持像素整数与百分比(相对 base 换算)
47
- * 例如:parseLength('421', 1082) => 421;parseLength('40%', 1082) => 433
46
+ * 解析长度选项,支持像素整数与百分比。
47
+ * @param value 长度文本,如 `421`、`40%`
48
+ * @param base 百分比换算基准
49
+ * @param label 错误信息中的选项名
50
+ * @returns 换算后的像素值
48
51
  */
49
52
  function parseLength(value, base, label) {
50
53
  const text = String(value).trim();
@@ -92,10 +95,9 @@ function colorToHex(color) {
92
95
  return `#${hex}`;
93
96
  }
94
97
  /**
95
- * 解析输出文件名:
96
- * - 默认 splash.9 => splash.9.png(9-patch)
97
- * - splash => splash.png(普通 PNG)
98
- * - 兼容传入 splash.9.png
98
+ * 解析启动图输出文件名。
99
+ * @param value 文件名,默认 `splash.9`;以 `.9` 结尾生成 9-patch
100
+ * @returns 文件名与是否 9-patch
99
101
  */
100
102
  function normalizeSplashName(value = 'splash.9') {
101
103
  let name = String(value || '').trim();
@@ -115,15 +117,15 @@ function normalizeSplashName(value = 'splash.9') {
115
117
  }
116
118
  return { fileName: `${name}.png`, ninePatch };
117
119
  }
118
- /** 按现有设计稿比例换算默认左右边距 */
120
+ /** 按画布宽度换算默认左右边距 */
119
121
  function defaultSplashLeft(width) {
120
122
  return Math.round((width * exports.DEFAULT_SPLASH_LEFT) / exports.DEFAULT_SPLASH_WIDTH);
121
123
  }
122
- /** 按现有设计稿比例换算默认顶部距离 */
124
+ /** 按画布高度换算默认顶部距离 */
123
125
  function defaultSplashTop(height) {
124
126
  return Math.round((height * exports.DEFAULT_SPLASH_TOP) / exports.DEFAULT_SPLASH_HEIGHT);
125
127
  }
126
- /** 查找输出目录中已有的启动图(依次:目标文件、splash.9.png、splash.png) */
128
+ /** 查找输出目录中已有的启动图,不存在时返回 null */
127
129
  function findReferenceSplash(destDir, fileName) {
128
130
  const candidates = [(0, path_1.join)(destDir, fileName), (0, path_1.join)(destDir, 'splash.9.png'), (0, path_1.join)(destDir, 'splash.png')];
129
131
  const visited = new Set();
@@ -149,7 +151,7 @@ async function readImageSize(input) {
149
151
  return { width: meta.width, height: meta.height };
150
152
  }
151
153
  /**
152
- * 从 RGBA 原始像素中识别可见内容区(排除透明与白底留白)
154
+ * 从 RGBA 原始像素中识别可见内容区
153
155
  * @returns 内容包围盒;无内容返回 null
154
156
  */
155
157
  function detectContentBox(data, width, height) {
@@ -218,7 +220,7 @@ function compositeRaw(canvas, width, height, source, sourceWidth, sourceHeight,
218
220
  }
219
221
  }
220
222
  }
221
- /** 按现有 splash.9.png 约定绘制 9-patch 边框标记 */
223
+ /** 绘制 9-patch 边框与拉伸标记 */
222
224
  function drawNinePatchBorder(canvas, width, height) {
223
225
  const setPixel = (x, y, r, g, b, a) => {
224
226
  const idx = (y * width + x) * 4;
@@ -246,11 +248,7 @@ function boxDistance(a, b) {
246
248
  function colorDistance(a, b) {
247
249
  return Math.abs(a.r - b.r) + Math.abs(a.g - b.g) + Math.abs(a.b - b.b);
248
250
  }
249
- /**
250
- * 识别 LOGO 自身的不透明背景色(内容区以外的众数颜色)
251
- * - 内容区以外几乎全透明 => 视为透明底,返回 null
252
- * - 内容区覆盖整张图 => 返回 null
253
- */
251
+ /** 识别 LOGO 自身的不透明背景色,无法判定时返回 null */
254
252
  function detectLogoBackgroundColor(data, width, height, content) {
255
253
  const counts = new Map();
256
254
  let outsideCount = 0;
@@ -277,7 +275,6 @@ function detectLogoBackgroundColor(data, width, height, content) {
277
275
  }
278
276
  if (outsideCount === 0 || opaqueCount === 0)
279
277
  return null;
280
- // 内容区以外不透明像素占比很低时,视为透明底(仅边缘抗锯齿)
281
278
  if (opaqueCount < outsideCount * 0.1)
282
279
  return null;
283
280
  let best = null;
@@ -369,7 +366,6 @@ async function validateOutput(buffer, options, expected, tolerance, strictBox, p
369
366
  if (options.ninePatch) {
370
367
  assertNinePatchBorder(raw.data, raw.width, raw.height);
371
368
  }
372
- // 期望区域内必须存在 LOGO 像素
373
369
  let hasContent = false;
374
370
  for (let y = expected.y; y < expected.y + expected.height && !hasContent; y++) {
375
371
  for (let x = expected.x; x < expected.x + expected.width; x++) {
@@ -388,7 +384,6 @@ async function validateOutput(buffer, options, expected, tolerance, strictBox, p
388
384
  if (!hasContent) {
389
385
  throw new Error('启动图生成结果校验失败:未找到 LOGO 内容');
390
386
  }
391
- // LOGO 背景可融入画布背景时,做严格的包围盒校验
392
387
  if (strictBox) {
393
388
  const box = findBoxByBackground(raw.data, raw.width, raw.height, options.background, border);
394
389
  if (!box) {
@@ -398,7 +393,6 @@ async function validateOutput(buffer, options, expected, tolerance, strictBox, p
398
393
  throw new Error('启动图生成结果校验失败:LOGO 位置或尺寸异常');
399
394
  }
400
395
  }
401
- // 未被 LOGO 画布覆盖的角落必须是背景色
402
396
  const samplePoints = [
403
397
  [border, border],
404
398
  [options.width - 1 - border, border],
@@ -420,10 +414,9 @@ async function validateOutput(buffer, options, expected, tolerance, strictBox, p
420
414
  }
421
415
  }
422
416
  /**
423
- * 按 LOGO 生成启动图
424
- * - LOGO 可见宽度 = 画布宽 - 2 × left,高度按 LOGO 内容宽高比等比计算
425
- * - 水平居中(右间距 = 左间距),顶部距离为 top
426
- * - ninePatch 为 true 时生成与现有 splash.9.png 一致的边框与拉伸标记
417
+ * 按 LOGO 生成启动图。
418
+ * @param options 画布与 LOGO 生成选项
419
+ * @returns PNG Buffer 及生成信息
427
420
  */
428
421
  async function generateSplash(options) {
429
422
  const { logo, width, height, left, top, background, ninePatch } = options;
@@ -496,9 +489,7 @@ async function generateSplash(options) {
496
489
  .png({ compressionLevel: PNG_COMPRESSION_LEVEL })
497
490
  .toBuffer();
498
491
  const expectedBox = { x: left, y: top, width: logoWidth, height: logoHeight };
499
- // 缩放重采样会在内容边缘产生 1~2px 抗锯齿光晕,按缩放比例放宽容差
500
492
  const validationTolerance = Math.max(VALIDATE_TOLERANCE, Math.ceil(logoScale * 2) + 1);
501
- // LOGO 自身背景与画布背景接近(或为透明底)时,LOGO 背景不可见,可做严格包围盒校验
502
493
  const strictBox = !logoBackground || colorDistance(logoBackground, background) <= INK_DISTANCE;
503
494
  await validateOutput(buffer, options, expectedBox, validationTolerance, strictBox, {
504
495
  x: pasteX,
@@ -23,7 +23,5 @@ export declare function packIcoBuffer(pngBuffers: {
23
23
  size: number;
24
24
  data: Buffer;
25
25
  }[]): Buffer;
26
- /**
27
- * 将源 PNG 转换为带圆角的 ICO 文件(保留原有接口,兼容 build.ts 调用)
28
- */
26
+ /** 将源 PNG 转换为带圆角的 ICO 文件 */
29
27
  export declare function png2ico(srcPath: string, outPath: string): Promise<void>;
@@ -66,17 +66,17 @@ function packIcoBuffer(pngBuffers) {
66
66
  const dirEntrySize = 16;
67
67
  let offset = headerSize + dirEntrySize * count;
68
68
  const header = Buffer.alloc(headerSize);
69
- header.writeUInt16LE(0, 0); // reserved
70
- header.writeUInt16LE(1, 2); // type: ICO
69
+ header.writeUInt16LE(0, 0);
70
+ header.writeUInt16LE(1, 2);
71
71
  header.writeUInt16LE(count, 4);
72
72
  const dirEntries = pngBuffers.map(({ size, data }) => {
73
73
  const entry = Buffer.alloc(dirEntrySize);
74
74
  entry.writeUInt8(size >= 256 ? 0 : size, 0);
75
75
  entry.writeUInt8(size >= 256 ? 0 : size, 1);
76
- entry.writeUInt8(0, 2); // color palette
77
- entry.writeUInt8(0, 3); // reserved
78
- entry.writeUInt16LE(1, 4); // color planes
79
- entry.writeUInt16LE(32, 6); // bits per pixel
76
+ entry.writeUInt8(0, 2);
77
+ entry.writeUInt8(0, 3);
78
+ entry.writeUInt16LE(1, 4);
79
+ entry.writeUInt16LE(32, 6);
80
80
  entry.writeUInt32LE(data.length, 8);
81
81
  entry.writeUInt32LE(offset, 12);
82
82
  offset += data.length;
@@ -84,11 +84,9 @@ function packIcoBuffer(pngBuffers) {
84
84
  });
85
85
  return Buffer.concat([header, ...dirEntries, ...pngBuffers.map((p) => p.data)]);
86
86
  }
87
- /**
88
- * 将源 PNG 转换为带圆角的 ICO 文件(保留原有接口,兼容 build.ts 调用)
89
- */
87
+ /** 将源 PNG 转换为带圆角的 ICO 文件 */
90
88
  async function png2ico(srcPath, outPath) {
91
- const cornerRadiusRatio = 0.18; // 18%
89
+ const cornerRadiusRatio = 0.18;
92
90
  const pngBuffers = await generateRoundedPngs(srcPath, exports.ICO_SIZES, (size) => Math.round(size * cornerRadiusRatio));
93
91
  const icoBuffer = packIcoBuffer(pngBuffers);
94
92
  (0, fs_1.writeFileSync)(outPath, icoBuffer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmcb/cli",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "工茂草本前端命令行工具",
5
5
  "author": "yinjiazeng@163.com",
6
6
  "license": "UNLICENSED",
@@ -22,7 +22,8 @@
22
22
  "files": [
23
23
  "lib",
24
24
  "schema.json",
25
- "README.md"
25
+ "README.md",
26
+ "CHANGELOG.md"
26
27
  ],
27
28
  "dependencies": {
28
29
  "adm-zip": "^0.5.16",
@@ -57,5 +58,5 @@
57
58
  "@types/rimraf": "^4.0.5",
58
59
  "@types/user-home": "^2.0.2"
59
60
  },
60
- "gitHead": "2aaabac698008fb9a12b18b3a86f0c2fe90ca366"
61
+ "gitHead": "6d73cae02f6a090c013660439f697066db426d4b"
61
62
  }