@gmcb/cli 0.8.11 → 0.8.12
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 +8 -0
- package/README.md +4 -0
- package/lib/actions/icon.js +9 -3
- package/lib/bin.js +1 -0
- package/lib/commands/option.d.ts +2 -0
- package/lib/commands/option.js +2 -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,14 @@
|
|
|
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.12](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.8.11...@gmcb/cli@0.8.12) (2026-08-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [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
15
|
|
|
8
16
|
**Note:** Version bump only for package @gmcb/cli
|
package/README.md
CHANGED
|
@@ -103,6 +103,7 @@ gmcb publish -p app --wgt -a
|
|
|
103
103
|
|---|---|
|
|
104
104
|
| `-s, --source <path>` | 源图片路径(必填,支持相对/绝对路径) |
|
|
105
105
|
| `-r, --radius <number>` | 圆角半径,默认 16 |
|
|
106
|
+
| `--size <number>` | 输出 PNG 尺寸(宽高相同),默认原尺寸 |
|
|
106
107
|
| `--ico` | 是否输出 ICO 文件 |
|
|
107
108
|
| `-d, --dest <path>` | 输出目录,默认为当前目录 |
|
|
108
109
|
|
|
@@ -112,6 +113,9 @@ gmcb publish -p app --wgt -a
|
|
|
112
113
|
# 生成带圆角的各尺寸 PNG
|
|
113
114
|
gmcb icon --source logo.png
|
|
114
115
|
|
|
116
|
+
# 输出 256x256 的圆角 PNG
|
|
117
|
+
gmcb icon --source logo.png --size 256
|
|
118
|
+
|
|
115
119
|
# 生成 ICO 文件,圆角半径 24,输出到 out 目录
|
|
116
120
|
gmcb icon --source logo.png --radius 24 --ico --dest out
|
|
117
121
|
```
|
package/lib/actions/icon.js
CHANGED
|
@@ -16,6 +16,11 @@ 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
|
+
const size = opts.size ? parseInt(opts.size, 10) : undefined;
|
|
20
|
+
if (opts.size && (!Number.isInteger(size) || size <= 0)) {
|
|
21
|
+
utils_1.log.error('--size 必须为正整数');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
19
24
|
if (!(0, fs_1.existsSync)(sourcePath)) {
|
|
20
25
|
utils_1.log.error(`源文件不存在: ${sourcePath}`);
|
|
21
26
|
return;
|
|
@@ -24,12 +29,13 @@ async function default_1(opts) {
|
|
|
24
29
|
(0, fs_1.mkdirSync)(destDir, { recursive: true });
|
|
25
30
|
}
|
|
26
31
|
const nameWithoutExt = (0, path_1.basename)(sourcePath, (0, path_1.extname)(sourcePath));
|
|
27
|
-
//
|
|
28
|
-
const roundedPng = await (0, utils_1.generateRoundedPng)(sourcePath, radius);
|
|
32
|
+
// 输出圆角 PNG,传 --size 时缩放到指定尺寸,否则保留原尺寸
|
|
33
|
+
const roundedPng = await (0, utils_1.generateRoundedPng)(sourcePath, size, radius);
|
|
29
34
|
const pngPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}.png`);
|
|
30
35
|
(0, fs_1.writeFileSync)(pngPath, roundedPng);
|
|
31
36
|
const pngKb = (roundedPng.length / 1024).toFixed(1);
|
|
32
|
-
|
|
37
|
+
const pngSizeText = size ? ` (${size}x${size})` : '';
|
|
38
|
+
console.log(`圆角 PNG 生成完成: ${pngPath}${pngSizeText} (${pngKb} KB)`);
|
|
33
39
|
// 传 --ico 时额外生成 ICO 文件
|
|
34
40
|
if (opts.ico) {
|
|
35
41
|
const pngBuffers = await (0, utils_1.generateRoundedPngs)(sourcePath, utils_1.ICO_SIZES, radius);
|
package/lib/bin.js
CHANGED
package/lib/commands/option.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ 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尺寸(宽高相同),默认原尺寸"];
|
|
31
32
|
export declare const ico: readonly ["--ico", "是否输出ICO文件"];
|
|
32
33
|
export declare const hbuilderxCli: readonly ["--cli.hbuilderx <cli-path>", "HbuilderX Cli路径"];
|
|
33
34
|
export declare const weixinCli: readonly ["--cli.weixin <cli-path>", "微信开发者工具 Cli路径"];
|
|
@@ -65,6 +66,7 @@ export interface Options {
|
|
|
65
66
|
restore?: boolean;
|
|
66
67
|
nobuild?: boolean;
|
|
67
68
|
radius?: string;
|
|
69
|
+
size?: string;
|
|
68
70
|
ico?: boolean;
|
|
69
71
|
'skill.repo'?: string;
|
|
70
72
|
'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.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,7 @@ 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尺寸(宽高相同),默认原尺寸'];
|
|
33
34
|
exports.ico = ['--ico', '是否输出ICO文件'];
|
|
34
35
|
exports.hbuilderxCli = ['--cli.hbuilderx <cli-path>', 'HbuilderX Cli路径'];
|
|
35
36
|
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.12",
|
|
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": "26edf845af9daec654c55c8d793213862f3b4bef"
|
|
63
63
|
}
|