@gmcb/cli 0.8.0 → 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 +8 -0
- package/lib/actions/icon.js +14 -13
- package/lib/utils/png2ico.d.ts +6 -0
- package/lib/utils/png2ico.js +13 -0
- package/package.json +2 -3
- package/LICENSE +0 -21
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.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
|
+
|
|
6
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)
|
|
7
15
|
|
|
8
16
|
|
package/lib/actions/icon.js
CHANGED
|
@@ -9,6 +9,10 @@ async function default_1(opts) {
|
|
|
9
9
|
utils_1.log.error('请使用 -s 或 --source 设置源图片路径');
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
+
if ((0, path_1.extname)(opts.source).toLowerCase() !== '.png') {
|
|
13
|
+
utils_1.log.error('源文件必须为 .png 格式');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
12
16
|
const sourcePath = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.source);
|
|
13
17
|
const destDir = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.dest ?? '.');
|
|
14
18
|
const radius = parseInt(opts.radius ?? '16', 10);
|
|
@@ -20,22 +24,19 @@ async function default_1(opts) {
|
|
|
20
24
|
(0, fs_1.mkdirSync)(destDir, { recursive: true });
|
|
21
25
|
}
|
|
22
26
|
const nameWithoutExt = (0, path_1.basename)(sourcePath, (0, path_1.extname)(sourcePath));
|
|
23
|
-
//
|
|
24
|
-
const
|
|
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 文件
|
|
25
34
|
if (opts.ico) {
|
|
26
|
-
|
|
35
|
+
const pngBuffers = await (0, utils_1.generateRoundedPngs)(sourcePath, utils_1.ICO_SIZES, radius);
|
|
27
36
|
const icoBuffer = (0, utils_1.packIcoBuffer)(pngBuffers);
|
|
28
37
|
const icoPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}.ico`);
|
|
29
38
|
(0, fs_1.writeFileSync)(icoPath, icoBuffer);
|
|
30
|
-
const
|
|
31
|
-
console.log(`ICO 生成完成: ${icoPath} (${
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// 仅输出各尺寸 PNG
|
|
35
|
-
for (const { size, data } of pngBuffers) {
|
|
36
|
-
const pngPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}-${size}.png`);
|
|
37
|
-
(0, fs_1.writeFileSync)(pngPath, data);
|
|
38
|
-
console.log(`PNG 生成完成: ${pngPath}`);
|
|
39
|
-
}
|
|
39
|
+
const icoKb = (icoBuffer.length / 1024).toFixed(1);
|
|
40
|
+
console.log(`ICO 生成完成: ${icoPath} (${icoKb} KB, sizes: ${utils_1.ICO_SIZES.join(', ')})`);
|
|
40
41
|
}
|
|
41
42
|
}
|
package/lib/utils/png2ico.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
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>;
|
|
2
8
|
/**
|
|
3
9
|
* 生成各尺寸带圆角的 PNG Buffer
|
|
4
10
|
* @param srcPath 源图片路径
|
package/lib/utils/png2ico.js
CHANGED
|
@@ -4,12 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ICO_SIZES = void 0;
|
|
7
|
+
exports.generateRoundedPng = generateRoundedPng;
|
|
7
8
|
exports.generateRoundedPngs = generateRoundedPngs;
|
|
8
9
|
exports.packIcoBuffer = packIcoBuffer;
|
|
9
10
|
exports.png2ico = png2ico;
|
|
10
11
|
const sharp_1 = __importDefault(require("sharp"));
|
|
11
12
|
const fs_1 = require("fs");
|
|
12
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
|
+
}
|
|
13
26
|
/**
|
|
14
27
|
* 生成各尺寸带圆角的 PNG Buffer
|
|
15
28
|
* @param srcPath 源图片路径
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmcb/cli",
|
|
3
|
-
"version": "0.8.
|
|
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": "a899a5c6c8a29b67811d87f27f632c0812650988"
|
|
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.
|