@gmcb/cli 0.7.11 → 0.8.0
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 +19 -0
- package/README.md +22 -0
- package/lib/actions/build.js +25 -8
- package/lib/actions/icon.d.ts +2 -0
- package/lib/actions/icon.js +41 -0
- package/lib/apis/http.d.ts +1 -0
- package/lib/apis/http.js +4 -0
- package/lib/apis/index.d.ts +16 -1
- package/lib/apis/index.js +67 -37
- package/lib/bin.js +9 -0
- package/lib/commands/option.d.ts +4 -0
- package/lib/commands/option.js +3 -1
- package/lib/utils/png2ico.d.ts +21 -0
- package/lib/utils/png2ico.js +35 -13
- package/package.json +2 -2
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.0](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.12...@gmcb/cli@0.8.0) (2026-07-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* 增加icon命令 ([243a52a](http://10.10.10.16/caoben/front-end/commits/243a52a05d4b35b5d73419d4b5e29ea48f242493))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [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)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @gmcb/cli
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.7.11](http://10.10.10.16/caoben/front-end/compare/@gmcb/cli@0.7.10...@gmcb/cli@0.7.11) (2026-07-13)
|
|
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
|
将资源从源目录复制到目标目录,支持 `{...}` 占位符自动解析:
|
package/lib/actions/build.js
CHANGED
|
@@ -269,7 +269,25 @@ function downloadFile(url, dest) {
|
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
async function fetchRemoteResources(opts) {
|
|
272
|
-
const spinner = (0, ora_1.default)(
|
|
272
|
+
const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
|
|
273
|
+
// 查询版本数据,更新 package.json
|
|
274
|
+
const appIdPkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
275
|
+
const appId = appIdPkg.appId;
|
|
276
|
+
const { versionName, versionCode, brandId } = await (0, apis_1.fetchLatestVersion)({
|
|
277
|
+
appId,
|
|
278
|
+
brandId: config_1.CONFIG_DATA.publish?.brandId,
|
|
279
|
+
brandName: config_1.CONFIG_DATA.publish?.brandName,
|
|
280
|
+
platform: config_1.CONFIG_DATA.publish?.platform,
|
|
281
|
+
});
|
|
282
|
+
if (brandId) {
|
|
283
|
+
config_1.CONFIG_DATA.publish.brandId = brandId;
|
|
284
|
+
}
|
|
285
|
+
if (versionName && versionCode) {
|
|
286
|
+
let pkgContent = (0, fs_1.readFileSync)(utils_1.PACKAGE_PATH, 'utf-8');
|
|
287
|
+
pkgContent = pkgContent.replace(/"version"\s*:\s*"[^"]*"/, `"version": "${versionName}"`);
|
|
288
|
+
pkgContent = pkgContent.replace(/"versionCode"\s*:\s*"?[^",]*"?/, `"versionCode": ${versionCode}`);
|
|
289
|
+
(0, fs_1.writeFileSync)(utils_1.PACKAGE_PATH, pkgContent);
|
|
290
|
+
}
|
|
273
291
|
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
274
292
|
// 校验 version 和 versionCode 必须存在
|
|
275
293
|
if (!pkg.version) {
|
|
@@ -278,7 +296,6 @@ async function fetchRemoteResources(opts) {
|
|
|
278
296
|
if (!pkg.versionCode) {
|
|
279
297
|
utils_1.log.error('package.json 缺少 versionCode 字段');
|
|
280
298
|
}
|
|
281
|
-
const appId = pkg.appId;
|
|
282
299
|
// 1. 获取应用信息
|
|
283
300
|
const appInfo = await (0, apis_1.getAppInfo)(appId);
|
|
284
301
|
const { appName, iconUrl, configJson } = appInfo;
|
|
@@ -315,9 +332,9 @@ async function fetchRemoteResources(opts) {
|
|
|
315
332
|
// 5. 修改仓库 src/manifest.json 的 versionName 和 versionCode
|
|
316
333
|
const manifestPath = (0, path_1.join)(repoDir, 'src', 'manifest.json');
|
|
317
334
|
let manifestContent = (0, fs_1.readFileSync)(manifestPath, 'utf-8');
|
|
318
|
-
manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name"
|
|
319
|
-
manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName"
|
|
320
|
-
manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode"
|
|
335
|
+
manifestContent = manifestContent.replace(/"name"\s*:\s*"[^"]*"/, `"name": "${appName}"`);
|
|
336
|
+
manifestContent = manifestContent.replace(/"versionName"\s*:\s*"[^"]*"/, `"versionName": "${pkg.version}"`);
|
|
337
|
+
manifestContent = manifestContent.replace(/"versionCode"\s*:\s*\d+/, `"versionCode": ${pkg.versionCode}`);
|
|
321
338
|
(0, fs_1.writeFileSync)(manifestPath, manifestContent);
|
|
322
339
|
// 6. 修改仓库 package.json scripts
|
|
323
340
|
const repoPkgPath = (0, path_1.join)(repoDir, 'package.json');
|
|
@@ -397,6 +414,9 @@ async function default_1(...args) {
|
|
|
397
414
|
const opts = args[0];
|
|
398
415
|
const commands = await getCommands(...args);
|
|
399
416
|
const command = commands.join(' ');
|
|
417
|
+
if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
|
|
418
|
+
await fetchRemoteResources(opts);
|
|
419
|
+
}
|
|
400
420
|
if (!opts.nobuild) {
|
|
401
421
|
const time = Date.now();
|
|
402
422
|
(0, utils_1.spawnSync)(command);
|
|
@@ -409,9 +429,6 @@ async function default_1(...args) {
|
|
|
409
429
|
if ((0, fs_1.existsSync)(envPath)) {
|
|
410
430
|
(0, fs_1.unlinkSync)(envPath);
|
|
411
431
|
}
|
|
412
|
-
if (opts.remote && ['electron-vite', 'gradlew'].includes(opts.compiler)) {
|
|
413
|
-
await fetchRemoteResources(opts);
|
|
414
|
-
}
|
|
415
432
|
// H5 构建完成后立即生成 manifest.json
|
|
416
433
|
if (opts.compiler === 'uni' && opts.platform === 'h5') {
|
|
417
434
|
generateH5Manifest();
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
const sourcePath = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.source);
|
|
13
|
+
const destDir = (0, path_1.resolve)(utils_1.COMMAND_PATH, opts.dest ?? '.');
|
|
14
|
+
const radius = parseInt(opts.radius ?? '16', 10);
|
|
15
|
+
if (!(0, fs_1.existsSync)(sourcePath)) {
|
|
16
|
+
utils_1.log.error(`源文件不存在: ${sourcePath}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!(0, fs_1.existsSync)(destDir)) {
|
|
20
|
+
(0, fs_1.mkdirSync)(destDir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
const nameWithoutExt = (0, path_1.basename)(sourcePath, (0, path_1.extname)(sourcePath));
|
|
23
|
+
// 生成各尺寸的带圆角 PNG
|
|
24
|
+
const pngBuffers = await (0, utils_1.generateRoundedPngs)(sourcePath, utils_1.ICO_SIZES, radius);
|
|
25
|
+
if (opts.ico) {
|
|
26
|
+
// 打包为 ICO 格式
|
|
27
|
+
const icoBuffer = (0, utils_1.packIcoBuffer)(pngBuffers);
|
|
28
|
+
const icoPath = (0, path_1.resolve)(destDir, `${nameWithoutExt}.ico`);
|
|
29
|
+
(0, fs_1.writeFileSync)(icoPath, icoBuffer);
|
|
30
|
+
const kb = (icoBuffer.length / 1024).toFixed(1);
|
|
31
|
+
console.log(`ICO 生成完成: ${icoPath} (${kb} KB, sizes: ${utils_1.ICO_SIZES.join(', ')})`);
|
|
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
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/lib/apis/http.d.ts
CHANGED
|
@@ -45,5 +45,6 @@ declare class Http {
|
|
|
45
45
|
get(url: string, params?: HttpRequestParams, config?: HttpRequestConfig): Promise<ResponseData<any>>;
|
|
46
46
|
}
|
|
47
47
|
export declare function setToken(token?: string): void;
|
|
48
|
+
export declare function getToken(): string | undefined;
|
|
48
49
|
export declare const http: Http;
|
|
49
50
|
export {};
|
package/lib/apis/http.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.http = void 0;
|
|
4
4
|
exports.setToken = setToken;
|
|
5
|
+
exports.getToken = getToken;
|
|
5
6
|
const const_1 = require("../utils/const");
|
|
6
7
|
class Http {
|
|
7
8
|
_header = {
|
|
@@ -130,4 +131,7 @@ function setToken(token) {
|
|
|
130
131
|
delete header['Authorization'];
|
|
131
132
|
}
|
|
132
133
|
}
|
|
134
|
+
function getToken() {
|
|
135
|
+
return exports.http.options.header['Authorization'];
|
|
136
|
+
}
|
|
133
137
|
exports.http = new Http();
|
package/lib/apis/index.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export declare function postVersion(data: any): Promise<{
|
|
|
60
60
|
export declare function getVersionPage(params: {
|
|
61
61
|
appId: string;
|
|
62
62
|
publishType: number;
|
|
63
|
+
brandId?: number | string;
|
|
64
|
+
platform?: number;
|
|
63
65
|
pageNo?: number;
|
|
64
66
|
pageSize?: number;
|
|
65
67
|
}): Promise<{
|
|
@@ -89,7 +91,7 @@ export declare function getVersionHistory(params: Record<string, any>): Promise<
|
|
|
89
91
|
}>;
|
|
90
92
|
export interface VersionParams {
|
|
91
93
|
brand?: string;
|
|
92
|
-
brandId?:
|
|
94
|
+
brandId?: string;
|
|
93
95
|
brandName?: string;
|
|
94
96
|
appId?: string;
|
|
95
97
|
username?: string;
|
|
@@ -115,6 +117,19 @@ export declare function uploadVersion(params: VersionParams): Promise<void>;
|
|
|
115
117
|
* 发布版本
|
|
116
118
|
*/
|
|
117
119
|
export declare function publishVersion(params: VersionParams): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* 获取最新版本信息(自动登录)
|
|
122
|
+
*/
|
|
123
|
+
export declare function fetchLatestVersion(params: {
|
|
124
|
+
appId: string;
|
|
125
|
+
brandId?: string;
|
|
126
|
+
brandName?: string;
|
|
127
|
+
platform?: number;
|
|
128
|
+
}): Promise<{
|
|
129
|
+
versionName: any;
|
|
130
|
+
versionCode: number;
|
|
131
|
+
brandId: string;
|
|
132
|
+
}>;
|
|
118
133
|
/**
|
|
119
134
|
* 获取应用信息(自动登录)
|
|
120
135
|
*/
|
package/lib/apis/index.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.getAppPage = getAppPage;
|
|
|
12
12
|
exports.getVersionHistory = getVersionHistory;
|
|
13
13
|
exports.uploadVersion = uploadVersion;
|
|
14
14
|
exports.publishVersion = publishVersion;
|
|
15
|
+
exports.fetchLatestVersion = fetchLatestVersion;
|
|
15
16
|
exports.getAppInfo = getAppInfo;
|
|
16
17
|
const http_1 = require("./http");
|
|
17
18
|
const const_1 = require("../utils/const");
|
|
@@ -23,6 +24,14 @@ const utils_1 = require("../utils");
|
|
|
23
24
|
function login(data) {
|
|
24
25
|
return http_1.http.post('/admin-api/system/auth/login', data);
|
|
25
26
|
}
|
|
27
|
+
async function ensureLoggedIn() {
|
|
28
|
+
if ((0, http_1.getToken)())
|
|
29
|
+
return;
|
|
30
|
+
const web = config_1.CONFIG_DATA.web;
|
|
31
|
+
const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
|
|
32
|
+
const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
|
|
33
|
+
(0, http_1.setToken)(accessToken);
|
|
34
|
+
}
|
|
26
35
|
/**
|
|
27
36
|
* 获取品牌列表
|
|
28
37
|
*/
|
|
@@ -82,10 +91,9 @@ function getVersionHistory(params) {
|
|
|
82
91
|
*/
|
|
83
92
|
async function uploadVersion(params) {
|
|
84
93
|
try {
|
|
85
|
-
const { brand,
|
|
94
|
+
const { brand, type, status, platform, path, remoteUrl, versionName, versionCode, } = params;
|
|
86
95
|
let brandId = '';
|
|
87
|
-
|
|
88
|
-
(0, http_1.setToken)(accessToken);
|
|
96
|
+
await ensureLoggedIn();
|
|
89
97
|
const { data: brandList } = await getBrandList();
|
|
90
98
|
const brandItem = brandList?.find(({ name, id }) => name === brand && Number(id) > 10000);
|
|
91
99
|
brandId = brandItem?.id;
|
|
@@ -114,20 +122,19 @@ async function uploadVersion(params) {
|
|
|
114
122
|
*/
|
|
115
123
|
async function publishVersion(params) {
|
|
116
124
|
try {
|
|
117
|
-
const { brandName, brandId, appId,
|
|
125
|
+
const { brandName, brandId, appId, remoteUrl, versionName, versionCode, channel, versionDesc, platform, ...rest } = params;
|
|
118
126
|
const publishType = Number(rest.publishType || 3);
|
|
119
127
|
const updateType = Number(rest.updateType || 2);
|
|
120
128
|
const updateMode = Number(rest.updateMode || 0);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const existingVersion = pageList.find((item) => String(item.versionNum) === String(versionCode));
|
|
129
|
+
await ensureLoggedIn();
|
|
130
|
+
const pageParams = { appId, publishType, pageNo: 1, pageSize: 1 };
|
|
131
|
+
if (publishType == 1) {
|
|
132
|
+
pageParams.brandId = config_1.CONFIG_DATA.publish?.brandId;
|
|
133
|
+
pageParams.platform = platform;
|
|
134
|
+
}
|
|
135
|
+
const { data: pageData } = await getVersionPage(pageParams);
|
|
136
|
+
const pageList = pageData?.list || [];
|
|
137
|
+
const existingVersion = pageList.find((item) => item.status < 2 && String(item.versionNum) === String(versionCode));
|
|
131
138
|
let latest;
|
|
132
139
|
const firstPage = pageList[0];
|
|
133
140
|
if (firstPage) {
|
|
@@ -158,22 +165,20 @@ async function publishVersion(params) {
|
|
|
158
165
|
}
|
|
159
166
|
else {
|
|
160
167
|
let createData;
|
|
168
|
+
const { data: appList } = await getAppList();
|
|
169
|
+
const appItem = appList?.find((item) => item.appId === appId);
|
|
161
170
|
if (publishType == 1) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
});
|
|
171
|
+
let resolvedBrandId = config_1.CONFIG_DATA.publish?.brandId || brandId;
|
|
172
|
+
if (!resolvedBrandId && brandName) {
|
|
173
|
+
const { data: brandList } = await getBrandList();
|
|
174
|
+
const matched = brandList?.find(({ name, id }) => {
|
|
175
|
+
return Number(id) > 10000 && name === brandName;
|
|
176
|
+
});
|
|
177
|
+
resolvedBrandId = matched?.id;
|
|
178
|
+
}
|
|
174
179
|
createData = {
|
|
175
|
-
brandId:
|
|
176
|
-
appName:
|
|
180
|
+
brandId: resolvedBrandId,
|
|
181
|
+
appName: appItem?.name,
|
|
177
182
|
channelType: const_1.CHANNEL_TYPE[channel],
|
|
178
183
|
platformType: const_1.PLATFORM_TYPE[platform],
|
|
179
184
|
updateType,
|
|
@@ -189,11 +194,9 @@ async function publishVersion(params) {
|
|
|
189
194
|
};
|
|
190
195
|
}
|
|
191
196
|
else {
|
|
192
|
-
const { data: appList } = await getAppList();
|
|
193
|
-
const appItem = appList?.find((item) => item.appId === appId);
|
|
194
197
|
createData = {
|
|
195
|
-
appMofangId: appItem?.id,
|
|
196
198
|
appId,
|
|
199
|
+
appMofangId: appItem?.id,
|
|
197
200
|
appName: appItem?.name,
|
|
198
201
|
updateType,
|
|
199
202
|
updateMode,
|
|
@@ -219,8 +222,8 @@ async function publishVersion(params) {
|
|
|
219
222
|
fullUrl = urls.find((u) => !/\.zip$/i.test(u)) || '';
|
|
220
223
|
resUrl = urls.find((u) => /\.zip$/i.test(u)) || '';
|
|
221
224
|
}
|
|
222
|
-
let fallbackFullUrl =
|
|
223
|
-
let fallbackResUrl =
|
|
225
|
+
let fallbackFullUrl = latest?.fullPackageUrl || '';
|
|
226
|
+
let fallbackResUrl = latest?.resourcePackageUrl || '';
|
|
224
227
|
if (publishType == 1 && fullUrl) {
|
|
225
228
|
fallbackFullUrl = '';
|
|
226
229
|
fallbackResUrl = '';
|
|
@@ -236,15 +239,42 @@ async function publishVersion(params) {
|
|
|
236
239
|
process.exit(1);
|
|
237
240
|
}
|
|
238
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* 获取最新版本信息(自动登录)
|
|
244
|
+
*/
|
|
245
|
+
async function fetchLatestVersion(params) {
|
|
246
|
+
const { appId, brandId, brandName, platform } = params;
|
|
247
|
+
await ensureLoggedIn();
|
|
248
|
+
let resolvedBrandId = brandId;
|
|
249
|
+
if (!resolvedBrandId && brandName) {
|
|
250
|
+
const { data: brandList } = await getBrandList();
|
|
251
|
+
const matched = brandList?.find(({ name, id }) => {
|
|
252
|
+
return Number(id) > 10000 && name === brandName;
|
|
253
|
+
});
|
|
254
|
+
resolvedBrandId = matched?.id;
|
|
255
|
+
}
|
|
256
|
+
const { data: versionPage } = await getVersionPage({
|
|
257
|
+
appId,
|
|
258
|
+
publishType: 1,
|
|
259
|
+
brandId: resolvedBrandId,
|
|
260
|
+
platform,
|
|
261
|
+
pageNo: 1,
|
|
262
|
+
pageSize: 1,
|
|
263
|
+
});
|
|
264
|
+
const versionList = (versionPage?.list || []).filter((item) => item.status < 2);
|
|
265
|
+
const latestVersion = versionList[0];
|
|
266
|
+
return {
|
|
267
|
+
versionName: latestVersion?.versionName ?? '',
|
|
268
|
+
versionCode: Number(latestVersion?.versionNum ?? 0),
|
|
269
|
+
brandId: resolvedBrandId ?? '',
|
|
270
|
+
};
|
|
271
|
+
}
|
|
239
272
|
/**
|
|
240
273
|
* 获取应用信息(自动登录)
|
|
241
274
|
*/
|
|
242
275
|
async function getAppInfo(appId) {
|
|
243
276
|
try {
|
|
244
|
-
|
|
245
|
-
const creds = (web?.[process.env.BUILD_ENV || ''] || web || {});
|
|
246
|
-
const { data: { accessToken }, } = await login({ username: creds.username, password: creds.password });
|
|
247
|
-
(0, http_1.setToken)(accessToken);
|
|
277
|
+
await ensureLoggedIn();
|
|
248
278
|
const { data: pageData } = await getAppPage({ appId, pageNo: 1, pageSize: 10 });
|
|
249
279
|
const appData = pageData?.list?.[0];
|
|
250
280
|
if (!appData)
|
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')
|
package/lib/commands/option.d.ts
CHANGED
|
@@ -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
|
}
|
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.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路径'];
|
package/lib/utils/png2ico.d.ts
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
+
export declare const ICO_SIZES: number[];
|
|
2
|
+
/**
|
|
3
|
+
* 生成各尺寸带圆角的 PNG Buffer
|
|
4
|
+
* @param srcPath 源图片路径
|
|
5
|
+
* @param sizes 目标尺寸数组
|
|
6
|
+
* @param radius 圆角半径:传入数字为固定值,传入函数则按尺寸比例计算
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateRoundedPngs(srcPath: string, sizes: number[], radius: number | ((size: number) => number)): Promise<{
|
|
9
|
+
size: number;
|
|
10
|
+
data: Buffer;
|
|
11
|
+
}[]>;
|
|
12
|
+
/**
|
|
13
|
+
* 将 PNG Buffer 数组打包为 ICO Buffer
|
|
14
|
+
*/
|
|
15
|
+
export declare function packIcoBuffer(pngBuffers: {
|
|
16
|
+
size: number;
|
|
17
|
+
data: Buffer;
|
|
18
|
+
}[]): Buffer;
|
|
19
|
+
/**
|
|
20
|
+
* 将源 PNG 转换为带圆角的 ICO 文件(保留原有接口,兼容 build.ts 调用)
|
|
21
|
+
*/
|
|
1
22
|
export declare function png2ico(srcPath: string, outPath: string): Promise<void>;
|
package/lib/utils/png2ico.js
CHANGED
|
@@ -3,16 +3,24 @@ 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.generateRoundedPngs = generateRoundedPngs;
|
|
8
|
+
exports.packIcoBuffer = packIcoBuffer;
|
|
6
9
|
exports.png2ico = png2ico;
|
|
7
10
|
const sharp_1 = __importDefault(require("sharp"));
|
|
8
11
|
const fs_1 = require("fs");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
exports.ICO_SIZES = [16, 24, 32, 48, 64, 128, 256];
|
|
13
|
+
/**
|
|
14
|
+
* 生成各尺寸带圆角的 PNG Buffer
|
|
15
|
+
* @param srcPath 源图片路径
|
|
16
|
+
* @param sizes 目标尺寸数组
|
|
17
|
+
* @param radius 圆角半径:传入数字为固定值,传入函数则按尺寸比例计算
|
|
18
|
+
*/
|
|
19
|
+
async function generateRoundedPngs(srcPath, sizes, radius) {
|
|
12
20
|
const pngBuffers = [];
|
|
13
21
|
for (const size of sizes) {
|
|
14
|
-
const
|
|
15
|
-
const mask = Buffer.from(`<svg><rect x="0" y="0" width="${size}" height="${size}" rx="${
|
|
22
|
+
const r = typeof radius === 'function' ? radius(size) : radius;
|
|
23
|
+
const mask = Buffer.from(`<svg><rect x="0" y="0" width="${size}" height="${size}" rx="${r}" ry="${r}" fill="white"/></svg>`);
|
|
16
24
|
const buf = await (0, sharp_1.default)(srcPath)
|
|
17
25
|
.resize(size, size)
|
|
18
26
|
.composite([{ input: mask, blend: 'dest-in' }])
|
|
@@ -20,29 +28,43 @@ async function png2ico(srcPath, outPath) {
|
|
|
20
28
|
.toBuffer();
|
|
21
29
|
pngBuffers.push({ size, data: buf });
|
|
22
30
|
}
|
|
31
|
+
return pngBuffers;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 将 PNG Buffer 数组打包为 ICO Buffer
|
|
35
|
+
*/
|
|
36
|
+
function packIcoBuffer(pngBuffers) {
|
|
23
37
|
const count = pngBuffers.length;
|
|
24
38
|
const headerSize = 6;
|
|
25
39
|
const dirEntrySize = 16;
|
|
26
40
|
let offset = headerSize + dirEntrySize * count;
|
|
27
41
|
const header = Buffer.alloc(headerSize);
|
|
28
|
-
header.writeUInt16LE(0, 0);
|
|
29
|
-
header.writeUInt16LE(1, 2);
|
|
42
|
+
header.writeUInt16LE(0, 0); // reserved
|
|
43
|
+
header.writeUInt16LE(1, 2); // type: ICO
|
|
30
44
|
header.writeUInt16LE(count, 4);
|
|
31
45
|
const dirEntries = pngBuffers.map(({ size, data }) => {
|
|
32
46
|
const entry = Buffer.alloc(dirEntrySize);
|
|
33
47
|
entry.writeUInt8(size >= 256 ? 0 : size, 0);
|
|
34
48
|
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);
|
|
49
|
+
entry.writeUInt8(0, 2); // color palette
|
|
50
|
+
entry.writeUInt8(0, 3); // reserved
|
|
51
|
+
entry.writeUInt16LE(1, 4); // color planes
|
|
52
|
+
entry.writeUInt16LE(32, 6); // bits per pixel
|
|
39
53
|
entry.writeUInt32LE(data.length, 8);
|
|
40
54
|
entry.writeUInt32LE(offset, 12);
|
|
41
55
|
offset += data.length;
|
|
42
56
|
return entry;
|
|
43
57
|
});
|
|
44
|
-
|
|
58
|
+
return Buffer.concat([header, ...dirEntries, ...pngBuffers.map((p) => p.data)]);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 将源 PNG 转换为带圆角的 ICO 文件(保留原有接口,兼容 build.ts 调用)
|
|
62
|
+
*/
|
|
63
|
+
async function png2ico(srcPath, outPath) {
|
|
64
|
+
const cornerRadiusRatio = 0.18; // 18%
|
|
65
|
+
const pngBuffers = await generateRoundedPngs(srcPath, exports.ICO_SIZES, (size) => Math.round(size * cornerRadiusRatio));
|
|
66
|
+
const icoBuffer = packIcoBuffer(pngBuffers);
|
|
45
67
|
(0, fs_1.writeFileSync)(outPath, icoBuffer);
|
|
46
68
|
const kb = (icoBuffer.length / 1024).toFixed(1);
|
|
47
|
-
console.log(`Done: ${outPath} (${kb} KB, sizes: ${
|
|
69
|
+
console.log(`Done: ${outPath} (${kb} KB, sizes: ${exports.ICO_SIZES.join(', ')})`);
|
|
48
70
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmcb/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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": "a899a5c6c8a29b67811d87f27f632c0812650988"
|
|
63
63
|
}
|