@gmcb/cli 0.7.12 → 0.8.1

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,25 @@
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.1](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.0...@gmcb/cli@0.8.1) (2026-07-14)
7
+
8
+ **Note:** Version bump only for package @gmcb/cli
9
+
10
+
11
+
12
+
13
+
14
+ # [0.8.0](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.12...@gmcb/cli@0.8.0) (2026-07-14)
15
+
16
+
17
+ ### Features
18
+
19
+ * 增加icon命令 ([243a52a](http://10.10.10.16/caoben/front-end/commits/243a52a05d4b35b5d73419d4b5e29ea48f242493))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [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
26
 
8
27
  **Note:** Version bump only for package @gmcb/cli
package/README.md CHANGED
@@ -18,6 +18,7 @@ npm i @gmcb/cli -g
18
18
  | `gmcb publish` | 应用程序发布 |
19
19
  | `gmcb copy` | 复制资源到指定目录 |
20
20
  | `gmcb config` | 配置管理 |
21
+ | `gmcb icon` | 生成应用图标(圆角 PNG / ICO) |
21
22
  | `gmcb skill sync` | 同步技能到本地项目 |
22
23
  | `gmcb skill list` | 列出当前项目所有技能 |
23
24
 
@@ -94,6 +95,27 @@ gmcb publish -p app --wgt -a
94
95
  - `pub`:基础发布配置(brand、type、status、platform、path)
95
96
  - `publish`:魔方发布配置(brandName、brandId、channel、updateType、versionDesc、publishType、platform、path),配置后走魔方发布流程
96
97
 
98
+ ## `gmcb icon`
99
+
100
+ 根据源图片生成带圆角的应用图标,可选输出 ICO 文件。
101
+
102
+ | 选项 | 描述 |
103
+ |---|---|
104
+ | `-s, --source <path>` | 源图片路径(必填,支持相对/绝对路径) |
105
+ | `-r, --radius <number>` | 圆角半径,默认 16 |
106
+ | `--ico` | 是否输出 ICO 文件 |
107
+ | `-d, --dest <path>` | 输出目录,默认为当前目录 |
108
+
109
+ 示例:
110
+
111
+ ```bash
112
+ # 生成带圆角的各尺寸 PNG
113
+ gmcb icon --source logo.png
114
+
115
+ # 生成 ICO 文件,圆角半径 24,输出到 out 目录
116
+ gmcb icon --source logo.png --radius 24 --ico --dest out
117
+ ```
118
+
97
119
  ## `gmcb copy`
98
120
 
99
121
  将资源从源目录复制到目标目录,支持 `{...}` 占位符自动解析:
@@ -0,0 +1,2 @@
1
+ import type { Options } from '../commands';
2
+ export default function (opts: Options): Promise<void>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const path_1 = require("path");
5
+ const fs_1 = require("fs");
6
+ const utils_1 = require("../utils");
7
+ async function default_1(opts) {
8
+ if (!opts.source) {
9
+ utils_1.log.error('请使用 -s 或 --source 设置源图片路径');
10
+ return;
11
+ }
12
+ if ((0, path_1.extname)(opts.source).toLowerCase() !== '.png') {
13
+ utils_1.log.error('源文件必须为 .png 格式');
14
+ return;
15
+ }
16
+ const sourcePath = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.source);
17
+ const destDir = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.dest ?? '.');
18
+ const radius = parseInt(opts.radius ?? '16', 10);
19
+ if (!(0, fs_1.existsSync)(sourcePath)) {
20
+ utils_1.log.error(`源文件不存在: ${sourcePath}`);
21
+ return;
22
+ }
23
+ if (!(0, fs_1.existsSync)(destDir)) {
24
+ (0, fs_1.mkdirSync)(destDir, { recursive: true });
25
+ }
26
+ const nameWithoutExt = (0, path_1.basename)(sourcePath, (0, path_1.extname)(sourcePath));
27
+ // 始终输出原尺寸的圆角 PNG
28
+ const roundedPng = await (0, utils_1.generateRoundedPng)(sourcePath, radius);
29
+ const pngPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}.png`);
30
+ (0, fs_1.writeFileSync)(pngPath, roundedPng);
31
+ const pngKb = (roundedPng.length / 1024).toFixed(1);
32
+ console.log(`圆角 PNG 生成完成: ${pngPath} (${pngKb} KB)`);
33
+ // 传 --ico 时额外生成 ICO 文件
34
+ if (opts.ico) {
35
+ const pngBuffers = await (0, utils_1.generateRoundedPngs)(sourcePath, utils_1.ICO_SIZES, radius);
36
+ const icoBuffer = (0, utils_1.packIcoBuffer)(pngBuffers);
37
+ const icoPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}.ico`);
38
+ (0, fs_1.writeFileSync)(icoPath, icoBuffer);
39
+ const icoKb = (icoBuffer.length / 1024).toFixed(1);
40
+ console.log(`ICO 生成完成: ${icoPath} (${icoKb} KB, sizes: ${utils_1.ICO_SIZES.join(', ')})`);
41
+ }
42
+ }
package/lib/bin.js CHANGED
@@ -12,6 +12,7 @@ const build_1 = __importDefault(require("./actions/build"));
12
12
  const publish_1 = __importDefault(require("./actions/publish"));
13
13
  const config_1 = __importDefault(require("./utils/config"));
14
14
  const copy_1 = __importDefault(require("./actions/copy"));
15
+ const icon_1 = __importDefault(require("./actions/icon"));
15
16
  const skill_1 = require("./actions/skill");
16
17
  const commands_1 = require("./commands");
17
18
  const utils_1 = require("./utils");
@@ -93,6 +94,14 @@ program
93
94
  .option(...commands_1.cosSecretkey)
94
95
  .option(...commands_1.branch)
95
96
  .action(config_1.default);
97
+ program
98
+ .command('icon')
99
+ .description('生成应用图标(圆角 PNG / ICO)')
100
+ .option(...commands_1.source)
101
+ .option(...commands_1.radius)
102
+ .option(...commands_1.ico)
103
+ .option(...commands_1.dest)
104
+ .action(icon_1.default);
96
105
  const skillCmd = program.command('skill').description('技能管理');
97
106
  skillCmd
98
107
  .command('sync')
@@ -25,6 +25,8 @@ export declare const apk: readonly ["--apk", "是否构建Android应用"];
25
25
  export declare const skip: readonly ["--skip", "跳过所有确认,自动发布"];
26
26
  export declare const remote: readonly ["--remote", "是否从远程拉取资源构建"];
27
27
  export declare const nobuild: readonly ["--nobuild", "跳过构建步骤"];
28
+ export declare const radius: readonly ["-r, --radius <number>", "圆角半径,默认16", "16"];
29
+ export declare const ico: readonly ["--ico", "是否输出ICO文件"];
28
30
  export declare const hbuilderxCli: readonly ["--cli.hbuilderx <cli-path>", "HbuilderX Cli路径"];
29
31
  export declare const weixinCli: readonly ["--cli.weixin <cli-path>", "微信开发者工具 Cli路径"];
30
32
  export declare const alipayCli: readonly ["--cli.alipay <cli-path>", "支付宝开发者工具 Cli路径"];
@@ -58,6 +60,8 @@ export interface Options {
58
60
  apk?: boolean;
59
61
  remote?: boolean;
60
62
  nobuild?: boolean;
63
+ radius?: string;
64
+ ico?: boolean;
61
65
  'skill.repo'?: string;
62
66
  'template.repo'?: string;
63
67
  }
@@ -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.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;
3
+ exports.templateRepo = exports.skillRepo = exports.cosSecretkey = exports.cosSecretid = exports.alipayCli = exports.weixinCli = exports.hbuilderxCli = exports.ico = exports.radius = 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'];
@@ -27,6 +27,8 @@ exports.apk = ['--apk', '是否构建Android应用'];
27
27
  exports.skip = ['--skip', '跳过所有确认,自动发布'];
28
28
  exports.remote = ['--remote', '是否从远程拉取资源构建'];
29
29
  exports.nobuild = ['--nobuild', '跳过构建步骤'];
30
+ exports.radius = ['-r, --radius <number>', '圆角半径,默认16', '16'];
31
+ exports.ico = ['--ico', '是否输出ICO文件'];
30
32
  exports.hbuilderxCli = ['--cli.hbuilderx <cli-path>', 'HbuilderX Cli路径'];
31
33
  exports.weixinCli = ['--cli.weixin <cli-path>', '微信开发者工具 Cli路径'];
32
34
  exports.alipayCli = ['--cli.alipay <cli-path>', '支付宝开发者工具 Cli路径'];
@@ -1 +1,28 @@
1
+ export declare const ICO_SIZES: number[];
2
+ /**
3
+ * 生成单张原尺寸的带圆角 PNG Buffer(不缩放,保留原始尺寸)
4
+ * @param srcPath 源图片路径
5
+ * @param radius 圆角半径
6
+ */
7
+ export declare function generateRoundedPng(srcPath: string, radius: number): Promise<Buffer>;
8
+ /**
9
+ * 生成各尺寸带圆角的 PNG Buffer
10
+ * @param srcPath 源图片路径
11
+ * @param sizes 目标尺寸数组
12
+ * @param radius 圆角半径:传入数字为固定值,传入函数则按尺寸比例计算
13
+ */
14
+ export declare function generateRoundedPngs(srcPath: string, sizes: number[], radius: number | ((size: number) => number)): Promise<{
15
+ size: number;
16
+ data: Buffer;
17
+ }[]>;
18
+ /**
19
+ * 将 PNG Buffer 数组打包为 ICO Buffer
20
+ */
21
+ export declare function packIcoBuffer(pngBuffers: {
22
+ size: number;
23
+ data: Buffer;
24
+ }[]): Buffer;
25
+ /**
26
+ * 将源 PNG 转换为带圆角的 ICO 文件(保留原有接口,兼容 build.ts 调用)
27
+ */
1
28
  export declare function png2ico(srcPath: string, outPath: string): Promise<void>;
@@ -3,16 +3,37 @@ 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.ICO_SIZES = void 0;
7
+ exports.generateRoundedPng = generateRoundedPng;
8
+ exports.generateRoundedPngs = generateRoundedPngs;
9
+ exports.packIcoBuffer = packIcoBuffer;
6
10
  exports.png2ico = png2ico;
7
11
  const sharp_1 = __importDefault(require("sharp"));
8
12
  const fs_1 = require("fs");
9
- const sizes = [16, 24, 32, 48, 64, 128, 256];
10
- const cornerRadiusRatio = 0.18; // 18%
11
- async function png2ico(srcPath, outPath) {
13
+ exports.ICO_SIZES = [16, 24, 32, 48, 64, 128, 256];
14
+ /**
15
+ * 生成单张原尺寸的带圆角 PNG Buffer(不缩放,保留原始尺寸)
16
+ * @param srcPath 源图片路径
17
+ * @param radius 圆角半径
18
+ */
19
+ async function generateRoundedPng(srcPath, radius) {
20
+ const { width, height } = await (0, sharp_1.default)(srcPath).metadata();
21
+ const w = width ?? 0;
22
+ const h = height ?? 0;
23
+ const mask = Buffer.from(`<svg><rect x="0" y="0" width="${w}" height="${h}" rx="${radius}" ry="${radius}" fill="white"/></svg>`);
24
+ return (0, sharp_1.default)(srcPath).composite([{ input: mask, blend: 'dest-in' }]).png().toBuffer();
25
+ }
26
+ /**
27
+ * 生成各尺寸带圆角的 PNG Buffer
28
+ * @param srcPath 源图片路径
29
+ * @param sizes 目标尺寸数组
30
+ * @param radius 圆角半径:传入数字为固定值,传入函数则按尺寸比例计算
31
+ */
32
+ async function generateRoundedPngs(srcPath, sizes, radius) {
12
33
  const pngBuffers = [];
13
34
  for (const size of sizes) {
14
- const radius = Math.round(size * cornerRadiusRatio);
15
- const mask = Buffer.from(`<svg><rect x="0" y="0" width="${size}" height="${size}" rx="${radius}" ry="${radius}" fill="white"/></svg>`);
35
+ const r = typeof radius === 'function' ? radius(size) : radius;
36
+ const mask = Buffer.from(`<svg><rect x="0" y="0" width="${size}" height="${size}" rx="${r}" ry="${r}" fill="white"/></svg>`);
16
37
  const buf = await (0, sharp_1.default)(srcPath)
17
38
  .resize(size, size)
18
39
  .composite([{ input: mask, blend: 'dest-in' }])
@@ -20,29 +41,43 @@ async function png2ico(srcPath, outPath) {
20
41
  .toBuffer();
21
42
  pngBuffers.push({ size, data: buf });
22
43
  }
44
+ return pngBuffers;
45
+ }
46
+ /**
47
+ * 将 PNG Buffer 数组打包为 ICO Buffer
48
+ */
49
+ function packIcoBuffer(pngBuffers) {
23
50
  const count = pngBuffers.length;
24
51
  const headerSize = 6;
25
52
  const dirEntrySize = 16;
26
53
  let offset = headerSize + dirEntrySize * count;
27
54
  const header = Buffer.alloc(headerSize);
28
- header.writeUInt16LE(0, 0);
29
- header.writeUInt16LE(1, 2);
55
+ header.writeUInt16LE(0, 0); // reserved
56
+ header.writeUInt16LE(1, 2); // type: ICO
30
57
  header.writeUInt16LE(count, 4);
31
58
  const dirEntries = pngBuffers.map(({ size, data }) => {
32
59
  const entry = Buffer.alloc(dirEntrySize);
33
60
  entry.writeUInt8(size >= 256 ? 0 : size, 0);
34
61
  entry.writeUInt8(size >= 256 ? 0 : size, 1);
35
- entry.writeUInt8(0, 2);
36
- entry.writeUInt8(0, 3);
37
- entry.writeUInt16LE(1, 4);
38
- entry.writeUInt16LE(32, 6);
62
+ entry.writeUInt8(0, 2); // color palette
63
+ entry.writeUInt8(0, 3); // reserved
64
+ entry.writeUInt16LE(1, 4); // color planes
65
+ entry.writeUInt16LE(32, 6); // bits per pixel
39
66
  entry.writeUInt32LE(data.length, 8);
40
67
  entry.writeUInt32LE(offset, 12);
41
68
  offset += data.length;
42
69
  return entry;
43
70
  });
44
- const icoBuffer = Buffer.concat([header, ...dirEntries, ...pngBuffers.map((p) => p.data)]);
71
+ return Buffer.concat([header, ...dirEntries, ...pngBuffers.map((p) => p.data)]);
72
+ }
73
+ /**
74
+ * 将源 PNG 转换为带圆角的 ICO 文件(保留原有接口,兼容 build.ts 调用)
75
+ */
76
+ async function png2ico(srcPath, outPath) {
77
+ const cornerRadiusRatio = 0.18; // 18%
78
+ const pngBuffers = await generateRoundedPngs(srcPath, exports.ICO_SIZES, (size) => Math.round(size * cornerRadiusRatio));
79
+ const icoBuffer = packIcoBuffer(pngBuffers);
45
80
  (0, fs_1.writeFileSync)(outPath, icoBuffer);
46
81
  const kb = (icoBuffer.length / 1024).toFixed(1);
47
- console.log(`Done: ${outPath} (${kb} KB, sizes: ${sizes.join(', ')})`);
82
+ console.log(`Done: ${outPath} (${kb} KB, sizes: ${exports.ICO_SIZES.join(', ')})`);
48
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmcb/cli",
3
- "version": "0.7.12",
3
+ "version": "0.8.1",
4
4
  "description": "工茂草本前端命令行工具",
5
5
  "author": "yinjiazeng@163.com",
6
6
  "license": "MIT",
@@ -58,6 +58,5 @@
58
58
  "@types/inquirer": "^9.0.7",
59
59
  "@types/rimraf": "^4.0.5",
60
60
  "@types/user-home": "^2.0.2"
61
- },
62
- "gitHead": "03c7901a7dba2e7364e9eaabf7a6f0e5199064aa"
61
+ }
63
62
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 aniu
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.