@gmcb/cli 0.8.11 → 0.8.13
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 +16 -0
- package/README.md +11 -0
- package/lib/actions/icon.js +36 -7
- package/lib/bin.js +2 -0
- package/lib/commands/option.d.ts +4 -0
- package/lib/commands/option.js +6 -1
- package/lib/utils/png2ico.d.ts +3 -2
- package/lib/utils/png2ico.js +17 -6
- package/package.json +2 -2
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.13](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.12...@gmcb/cli@0.8.13) (2026-08-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.8.12](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.11...@gmcb/cli@0.8.12) (2026-08-17)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [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
23
|
|
|
8
24
|
**Note:** Version bump only for package @gmcb/cli
|
package/README.md
CHANGED
|
@@ -103,6 +103,8 @@ gmcb publish -p app --wgt -a
|
|
|
103
103
|
|---|---|
|
|
104
104
|
| `-s, --source <path>` | 源图片路径(必填,支持相对/绝对路径) |
|
|
105
105
|
| `-r, --radius <number>` | 圆角半径,默认 16 |
|
|
106
|
+
| `--size <number>` | 输出 PNG 尺寸(宽高相同),覆盖原图,默认原尺寸 |
|
|
107
|
+
| `--sizes <numbers>` | 输出 PNG 副本,可传一个或多个(逗号分隔),文件名为 原文件名_size |
|
|
106
108
|
| `--ico` | 是否输出 ICO 文件 |
|
|
107
109
|
| `-d, --dest <path>` | 输出目录,默认为当前目录 |
|
|
108
110
|
|
|
@@ -112,6 +114,15 @@ gmcb publish -p app --wgt -a
|
|
|
112
114
|
# 生成带圆角的各尺寸 PNG
|
|
113
115
|
gmcb icon --source logo.png
|
|
114
116
|
|
|
117
|
+
# 覆盖原图为 256x256 的圆角 PNG
|
|
118
|
+
gmcb icon --source logo.png --size 256
|
|
119
|
+
|
|
120
|
+
# 输出副本 logo_256.png,不覆盖原图
|
|
121
|
+
gmcb icon --source logo.png --sizes 256
|
|
122
|
+
|
|
123
|
+
# 一次输出多个尺寸副本 logo_64.png、logo_128.png、logo_256.png
|
|
124
|
+
gmcb icon --source logo.png --sizes 64,128,256
|
|
125
|
+
|
|
115
126
|
# 生成 ICO 文件,圆角半径 24,输出到 out 目录
|
|
116
127
|
gmcb icon --source logo.png --radius 24 --ico --dest out
|
|
117
128
|
```
|
package/lib/actions/icon.js
CHANGED
|
@@ -16,6 +16,23 @@ async function default_1(opts) {
|
|
|
16
16
|
const sourcePath = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.source);
|
|
17
17
|
const destDir = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.dest ?? '.');
|
|
18
18
|
const radius = parseInt(opts.radius ?? '16', 10);
|
|
19
|
+
if (opts.size && opts.sizes) {
|
|
20
|
+
utils_1.log.error('--size 与 --sizes 不能同时使用');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const size = opts.size ? parseInt(opts.size, 10) : undefined;
|
|
24
|
+
if (opts.size && (!Number.isInteger(size) || size <= 0)) {
|
|
25
|
+
utils_1.log.error('--size 必须为正整数');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let sizeList;
|
|
29
|
+
if (opts.sizes) {
|
|
30
|
+
sizeList = opts.sizes.split(',').map((s) => parseInt(s.trim(), 10));
|
|
31
|
+
if (sizeList.some((s) => !Number.isInteger(s) || s <= 0)) {
|
|
32
|
+
utils_1.log.error('--sizes 必须为正整数,多个用英文逗号分隔');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
19
36
|
if (!(0, fs_1.existsSync)(sourcePath)) {
|
|
20
37
|
utils_1.log.error(`源文件不存在: ${sourcePath}`);
|
|
21
38
|
return;
|
|
@@ -24,13 +41,7 @@ async function default_1(opts) {
|
|
|
24
41
|
(0, fs_1.mkdirSync)(destDir, { recursive: true });
|
|
25
42
|
}
|
|
26
43
|
const nameWithoutExt = (0, path_1.basename)(sourcePath, (0, path_1.extname)(sourcePath));
|
|
27
|
-
//
|
|
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 文件
|
|
44
|
+
// 传 --ico 时先生成 ICO 文件,避免 --size 覆盖原图后读取到缩放后的源文件
|
|
34
45
|
if (opts.ico) {
|
|
35
46
|
const pngBuffers = await (0, utils_1.generateRoundedPngs)(sourcePath, utils_1.ICO_SIZES, radius);
|
|
36
47
|
const icoBuffer = (0, utils_1.packIcoBuffer)(pngBuffers);
|
|
@@ -39,4 +50,22 @@ async function default_1(opts) {
|
|
|
39
50
|
const icoKb = (icoBuffer.length / 1024).toFixed(1);
|
|
40
51
|
console.log(`ICO 生成完成: ${icoPath} (${icoKb} KB, sizes: ${utils_1.ICO_SIZES.join(', ')})`);
|
|
41
52
|
}
|
|
53
|
+
// 未传尺寸时输出原尺寸圆角 PNG;--size 缩放后覆盖原图;--sizes 按 原文件名_size 命名生成副本
|
|
54
|
+
if (sizeList) {
|
|
55
|
+
for (const s of sizeList) {
|
|
56
|
+
const roundedPng = await (0, utils_1.generateRoundedPng)(sourcePath, s, radius);
|
|
57
|
+
const pngPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}_${s}.png`);
|
|
58
|
+
(0, fs_1.writeFileSync)(pngPath, roundedPng);
|
|
59
|
+
const pngKb = (roundedPng.length / 1024).toFixed(1);
|
|
60
|
+
console.log(`圆角 PNG 生成完成: ${pngPath} (${s}x${s}, ${pngKb} KB)`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const roundedPng = await (0, utils_1.generateRoundedPng)(sourcePath, size, radius);
|
|
65
|
+
const pngPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}.png`);
|
|
66
|
+
(0, fs_1.writeFileSync)(pngPath, roundedPng);
|
|
67
|
+
const pngKb = (roundedPng.length / 1024).toFixed(1);
|
|
68
|
+
const pngSizeText = size ? ` (${size}x${size})` : '';
|
|
69
|
+
console.log(`圆角 PNG 生成完成: ${pngPath}${pngSizeText} (${pngKb} KB)`);
|
|
70
|
+
}
|
|
42
71
|
}
|
package/lib/bin.js
CHANGED
|
@@ -103,6 +103,8 @@ program
|
|
|
103
103
|
.description('生成应用图标(圆角 PNG / ICO)')
|
|
104
104
|
.option(...commands_1.source)
|
|
105
105
|
.option(...commands_1.radius)
|
|
106
|
+
.option(...commands_1.size)
|
|
107
|
+
.option(...commands_1.sizes)
|
|
106
108
|
.option(...commands_1.ico)
|
|
107
109
|
.option(...commands_1.dest)
|
|
108
110
|
.action(icon_1.default);
|
package/lib/commands/option.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export declare const latest: readonly ["--latest", "是否获取最新版本数
|
|
|
28
28
|
export declare const restore: readonly ["--restore", "构建完成后是否还原远程写入的主项目文件"];
|
|
29
29
|
export declare const nobuild: readonly ["--nobuild", "跳过构建步骤"];
|
|
30
30
|
export declare const radius: readonly ["-r, --radius <number>", "圆角半径,默认16", "16"];
|
|
31
|
+
export declare const size: readonly ["--size <number>", "输出PNG尺寸(宽高相同),覆盖原图,默认原尺寸"];
|
|
32
|
+
export declare const sizes: readonly ["--sizes <numbers>", "输出PNG副本(宽高相同),可传一个或多个用英文逗号分隔,文件名为 原文件名_size"];
|
|
31
33
|
export declare const ico: readonly ["--ico", "是否输出ICO文件"];
|
|
32
34
|
export declare const hbuilderxCli: readonly ["--cli.hbuilderx <cli-path>", "HbuilderX Cli路径"];
|
|
33
35
|
export declare const weixinCli: readonly ["--cli.weixin <cli-path>", "微信开发者工具 Cli路径"];
|
|
@@ -65,6 +67,8 @@ export interface Options {
|
|
|
65
67
|
restore?: boolean;
|
|
66
68
|
nobuild?: boolean;
|
|
67
69
|
radius?: string;
|
|
70
|
+
size?: string;
|
|
71
|
+
sizes?: string;
|
|
68
72
|
ico?: boolean;
|
|
69
73
|
'skill.repo'?: string;
|
|
70
74
|
'template.repo'?: string;
|
package/lib/commands/option.js
CHANGED
|
@@ -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.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;
|
|
3
|
+
exports.templateRepo = exports.skillRepo = exports.cosSecretkey = exports.cosSecretid = exports.alipayCli = exports.weixinCli = exports.hbuilderxCli = exports.ico = exports.sizes = exports.size = 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'];
|
|
@@ -30,6 +30,11 @@ exports.latest = ['--latest', '是否获取最新版本数据'];
|
|
|
30
30
|
exports.restore = ['--restore', '构建完成后是否还原远程写入的主项目文件'];
|
|
31
31
|
exports.nobuild = ['--nobuild', '跳过构建步骤'];
|
|
32
32
|
exports.radius = ['-r, --radius <number>', '圆角半径,默认16', '16'];
|
|
33
|
+
exports.size = ['--size <number>', '输出PNG尺寸(宽高相同),覆盖原图,默认原尺寸'];
|
|
34
|
+
exports.sizes = [
|
|
35
|
+
'--sizes <numbers>',
|
|
36
|
+
'输出PNG副本(宽高相同),可传一个或多个用英文逗号分隔,文件名为 原文件名_size',
|
|
37
|
+
];
|
|
33
38
|
exports.ico = ['--ico', '是否输出ICO文件'];
|
|
34
39
|
exports.hbuilderxCli = ['--cli.hbuilderx <cli-path>', 'HbuilderX Cli路径'];
|
|
35
40
|
exports.weixinCli = ['--cli.weixin <cli-path>', '微信开发者工具 Cli路径'];
|
package/lib/utils/png2ico.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export declare const ICO_SIZES: number[];
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 生成单张带圆角的 PNG Buffer
|
|
4
4
|
* @param srcPath 源图片路径
|
|
5
|
+
* @param size 目标尺寸(宽高相同),不传则保留原始尺寸
|
|
5
6
|
* @param radius 圆角半径
|
|
6
7
|
*/
|
|
7
|
-
export declare function generateRoundedPng(srcPath: string, radius: number): Promise<Buffer>;
|
|
8
|
+
export declare function generateRoundedPng(srcPath: string, size: number | undefined, radius: number): Promise<Buffer>;
|
|
8
9
|
/**
|
|
9
10
|
* 生成各尺寸带圆角的 PNG Buffer
|
|
10
11
|
* @param srcPath 源图片路径
|
package/lib/utils/png2ico.js
CHANGED
|
@@ -12,16 +12,27 @@ const sharp_1 = __importDefault(require("sharp"));
|
|
|
12
12
|
const fs_1 = require("fs");
|
|
13
13
|
exports.ICO_SIZES = [16, 24, 32, 48, 64, 128, 256];
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* 生成单张带圆角的 PNG Buffer
|
|
16
16
|
* @param srcPath 源图片路径
|
|
17
|
+
* @param size 目标尺寸(宽高相同),不传则保留原始尺寸
|
|
17
18
|
* @param radius 圆角半径
|
|
18
19
|
*/
|
|
19
|
-
async function generateRoundedPng(srcPath, radius) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
async function generateRoundedPng(srcPath, size, radius) {
|
|
21
|
+
let w;
|
|
22
|
+
let h;
|
|
23
|
+
if (size) {
|
|
24
|
+
w = h = size;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const { width, height } = await (0, sharp_1.default)(srcPath).metadata();
|
|
28
|
+
w = width ?? 0;
|
|
29
|
+
h = height ?? 0;
|
|
30
|
+
}
|
|
23
31
|
const mask = Buffer.from(`<svg><rect x="0" y="0" width="${w}" height="${h}" rx="${radius}" ry="${radius}" fill="white"/></svg>`);
|
|
24
|
-
|
|
32
|
+
const pipeline = (0, sharp_1.default)(srcPath);
|
|
33
|
+
if (size)
|
|
34
|
+
pipeline.resize(size, size);
|
|
35
|
+
return pipeline.composite([{ input: mask, blend: 'dest-in' }]).png().toBuffer();
|
|
25
36
|
}
|
|
26
37
|
/**
|
|
27
38
|
* 生成各尺寸带圆角的 PNG Buffer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmcb/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.13",
|
|
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": "
|
|
62
|
+
"gitHead": "d2426e75b0edc8280476bec2bb357c5fe257504d"
|
|
63
63
|
}
|