@gmcb/cli 0.10.3 → 0.10.5
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 +17 -0
- package/lib/actions/build.js +21 -5
- package/lib/actions/image.js +2 -5
- package/lib/apis/index.d.ts +0 -5
- package/lib/apis/index.js +6 -19
- package/lib/commands/option.d.ts +1 -1
- package/lib/commands/option.js +1 -1
- package/lib/scripts/publish.js +5 -14
- package/lib/utils/function.d.ts +1 -2
- package/lib/utils/function.js +1 -2
- package/lib/utils/image.d.ts +7 -0
- package/lib/utils/image.js +51 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- release:insert -->
|
|
4
4
|
|
|
5
|
+
## 0.10.5 [2026-12-01]
|
|
6
|
+
<!-- generated-by: specs -->
|
|
7
|
+
### 修复
|
|
8
|
+
- H5 发布 zip 改为扁平结构(不再包含 `package.appId` 根目录),Electron 子应用解压到 `apps/<env>/<appId>/` 后可直接识别 `manifest.json`。
|
|
9
|
+
- 发布提交时应用列表中找不到 `appId` 对应应用会给出明确错误,不再只看到后端的“请选择关联应用”。
|
|
10
|
+
### 优化
|
|
11
|
+
- 未配置上传路径(`publish.path` / `pub.path`)时,发布上传目录统一使用业务应用 ID(`/app/{appId}/{versionName}.{versionCode}/...`),不再反查应用标识 `identifier`;缺少应用 ID 时直接提示检查 `package.json.appId` / `manifest.appid` 并退出。
|
|
12
|
+
- `--pull` 拉取远程 electron-vite 工程时,`copy:electron` 的复制目标改为业务应用 ID 目录 `out/renderer/{package.appId}/`。
|
|
13
|
+
|
|
14
|
+
## 0.10.4 [2026-11-29]
|
|
15
|
+
<!-- generated-by: specs -->
|
|
16
|
+
### 新增
|
|
17
|
+
- Android `--pull` 通过 `gmcb image` 自动生成 `splash_icon.png`(768×768,内部 360px 图标居中)。
|
|
18
|
+
- `gmcb image --bg 255,255,255,0` 支持透明底启动图,`--bg 255,255,255` 等价白色不透明。
|
|
19
|
+
### 优化
|
|
20
|
+
- Android `icon.png` / `push.png` 保持下载原尺寸,不再强制 512。
|
|
21
|
+
|
|
5
22
|
## 0.10.3 [2026-11-23]
|
|
6
23
|
<!-- generated-by: specs -->
|
|
7
24
|
### 优化
|
package/lib/actions/build.js
CHANGED
|
@@ -40,6 +40,7 @@ const simple_git_1 = __importDefault(require("simple-git"));
|
|
|
40
40
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
41
41
|
const ora_1 = __importDefault(require("ora"));
|
|
42
42
|
const delay_1 = __importDefault(require("delay"));
|
|
43
|
+
const image_1 = __importDefault(require("./image"));
|
|
43
44
|
const platform = __importStar(require("../commands/platform"));
|
|
44
45
|
const utils_1 = require("../utils");
|
|
45
46
|
const config_1 = require("../utils/config");
|
|
@@ -357,13 +358,12 @@ async function generatePackage(opts) {
|
|
|
357
358
|
if ((0, fs_1.existsSync)(dest)) {
|
|
358
359
|
(0, fs_1.unlinkSync)(dest);
|
|
359
360
|
}
|
|
360
|
-
const zipRoot = compiler === 'uni' && platform === 'h5' && pkg.appId ? String(pkg.appId) : '';
|
|
361
361
|
if (compiler === 'uni' && platform === 'h5') {
|
|
362
362
|
const h5ManifestPath = (0, path_1.join)(source, 'manifest.json');
|
|
363
363
|
const h5Manifest = (0, fs_extra_1.readJsonSync)(h5ManifestPath, { throws: false }) || {};
|
|
364
364
|
(0, fs_extra_1.writeJsonSync)(h5ManifestPath, { ...h5Manifest, appid: (0, utils_1.resolveAppId)(manifest, pkg) });
|
|
365
365
|
}
|
|
366
|
-
zip.addLocalFolder(source
|
|
366
|
+
zip.addLocalFolder(source);
|
|
367
367
|
zip.writeZip(dest);
|
|
368
368
|
}
|
|
369
369
|
spinner.stop();
|
|
@@ -392,7 +392,11 @@ function downloadFile(url, dest) {
|
|
|
392
392
|
async function pullRemoteResources(opts) {
|
|
393
393
|
const spinner = (0, ora_1.default)(`正在拉取远程资源...`).start();
|
|
394
394
|
const pkg = (0, fs_extra_1.readJsonSync)(utils_1.PACKAGE_PATH);
|
|
395
|
-
const appId = pkg.appId;
|
|
395
|
+
const appId = String(pkg.appId || '').trim();
|
|
396
|
+
if (!appId) {
|
|
397
|
+
utils_1.log.error('未找到应用ID,请在 package.json 中配置 appId(业务应用ID)后重试');
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
396
400
|
const appInfo = await (0, apis_1.getAppInfo)(appId);
|
|
397
401
|
const { appName, iconUrl, configJson } = appInfo;
|
|
398
402
|
const repoUrl = configJson.repo || config_1.CONFIG_DATA.pull?.repo;
|
|
@@ -437,7 +441,7 @@ async function pullRemoteResources(opts) {
|
|
|
437
441
|
if (!repoPkg.scripts)
|
|
438
442
|
repoPkg.scripts = {};
|
|
439
443
|
if (opts.compiler === 'electron-vite') {
|
|
440
|
-
repoPkg.scripts['copy:electron'] = 'gmcb copy -s ./dist/build/h5 -d ../../out/renderer/{
|
|
444
|
+
repoPkg.scripts['copy:electron'] = 'gmcb copy -s ./dist/build/h5 -d ../../out/renderer/{package.appId}/ --clean';
|
|
441
445
|
}
|
|
442
446
|
if (opts.compiler === 'gradlew') {
|
|
443
447
|
if (isUniappX) {
|
|
@@ -488,10 +492,22 @@ async function pullRemoteResources(opts) {
|
|
|
488
492
|
(0, fs_extra_1.ensureDirSync)(drawableDir);
|
|
489
493
|
const iconPath = (0, path_1.join)(drawableDir, 'icon.png');
|
|
490
494
|
const pushPath = (0, path_1.join)(drawableDir, 'push.png');
|
|
495
|
+
const splashIconPath = (0, path_1.join)(drawableDir, 'splash_icon.png');
|
|
491
496
|
backup(iconPath);
|
|
492
|
-
await downloadFile(iconUrl, iconPath);
|
|
493
497
|
backup(pushPath);
|
|
498
|
+
backup(splashIconPath);
|
|
499
|
+
await downloadFile(iconUrl, iconPath);
|
|
494
500
|
(0, fs_1.copyFileSync)(iconPath, pushPath);
|
|
501
|
+
await (0, image_1.default)({
|
|
502
|
+
source: iconPath,
|
|
503
|
+
dest: drawableDir,
|
|
504
|
+
name: 'splash_icon',
|
|
505
|
+
width: '768',
|
|
506
|
+
height: '768',
|
|
507
|
+
left: '204',
|
|
508
|
+
top: '204',
|
|
509
|
+
bg: '255,255,255,0',
|
|
510
|
+
});
|
|
495
511
|
}
|
|
496
512
|
}
|
|
497
513
|
if (config_1.CONFIG_DATA.publish?.updateMode == 2) {
|
package/lib/actions/image.js
CHANGED
|
@@ -48,7 +48,7 @@ async function default_1(...args) {
|
|
|
48
48
|
: referenceSize?.height || utils_1.DEFAULT_SPLASH_HEIGHT;
|
|
49
49
|
const left = opts.left ? (0, utils_1.parseLength)(opts.left, width, '--left') : (0, utils_1.defaultSplashLeft)(width);
|
|
50
50
|
const top = opts.top ? (0, utils_1.parseLength)(opts.top, height, '--top') : (0, utils_1.defaultSplashTop)(height);
|
|
51
|
-
const background =
|
|
51
|
+
const background = (0, utils_1.parseBackgroundColor)(opts.bg);
|
|
52
52
|
const { buffer, info } = await (0, utils_1.generateSplash)({
|
|
53
53
|
logo: (0, fs_1.readFileSync)(sourcePath),
|
|
54
54
|
width,
|
|
@@ -59,12 +59,9 @@ async function default_1(...args) {
|
|
|
59
59
|
ninePatch,
|
|
60
60
|
});
|
|
61
61
|
(0, fs_1.writeFileSync)(destPath, buffer);
|
|
62
|
-
console.log(`画布:${info.width}×${info.height},背景 ${info.background}`);
|
|
62
|
+
console.log(`画布:${info.width}×${info.height},背景 ${info.transparent ? '透明' : info.background}`);
|
|
63
63
|
console.log(`LOGO:可见区 ${info.logoBox.width}×${info.logoBox.height},left=${info.logoBox.x}, top=${info.logoBox.y}`);
|
|
64
64
|
console.log(`输出:${destPath}(${(buffer.length / 1024).toFixed(1)} KB,${ninePatch ? '9-patch' : '普通 PNG'})`);
|
|
65
|
-
if (info.logoBackground && info.logoBackground.toLowerCase() !== info.background.toLowerCase()) {
|
|
66
|
-
utils_1.log.warning(`LOGO 自带不透明背景色 ${info.logoBackground},与画布背景 ${info.background} 不一致,输出会保留 LOGO 自身背景`);
|
|
67
|
-
}
|
|
68
65
|
utils_1.log.success('启动图生成完成');
|
|
69
66
|
}
|
|
70
67
|
catch (err) {
|
package/lib/apis/index.d.ts
CHANGED
|
@@ -130,11 +130,6 @@ export declare function fetchLatestVersion(params: {
|
|
|
130
130
|
versionCode: number;
|
|
131
131
|
updateMode: any;
|
|
132
132
|
}>;
|
|
133
|
-
/**
|
|
134
|
-
* 按 manifest appId 查询应用详情(含 identifier),用于拼 COS 上传目录。
|
|
135
|
-
* 未查询到或请求失败时返回 null 并告警,由调用方回退 appId,不中断发布。
|
|
136
|
-
*/
|
|
137
|
-
export declare function fetchAppDetail(appId: string): Promise<Record<string, any> | null>;
|
|
138
133
|
/**
|
|
139
134
|
* 获取应用信息
|
|
140
135
|
*/
|
package/lib/apis/index.js
CHANGED
|
@@ -13,7 +13,6 @@ exports.getVersionHistory = getVersionHistory;
|
|
|
13
13
|
exports.uploadVersion = uploadVersion;
|
|
14
14
|
exports.publishVersion = publishVersion;
|
|
15
15
|
exports.fetchLatestVersion = fetchLatestVersion;
|
|
16
|
-
exports.fetchAppDetail = fetchAppDetail;
|
|
17
16
|
exports.getAppInfo = getAppInfo;
|
|
18
17
|
const http_1 = require("./http");
|
|
19
18
|
const const_1 = require("../utils/const");
|
|
@@ -157,6 +156,10 @@ async function publishVersion(params) {
|
|
|
157
156
|
else {
|
|
158
157
|
const { data: appList } = await getAppList();
|
|
159
158
|
const appItem = appList?.find((item) => item.appId === appId);
|
|
159
|
+
// 后端在 appMofangId 缺失时只报“请选择关联应用”,这里提前给出可定位的提示
|
|
160
|
+
if (!appItem) {
|
|
161
|
+
throw new Error(`未找到应用ID为 ${appId} 的应用,请检查 package.json.appId`);
|
|
162
|
+
}
|
|
160
163
|
const createData = {
|
|
161
164
|
appId,
|
|
162
165
|
appMofangId: appItem?.id,
|
|
@@ -207,7 +210,8 @@ async function publishVersion(params) {
|
|
|
207
210
|
});
|
|
208
211
|
}
|
|
209
212
|
catch (err) {
|
|
210
|
-
|
|
213
|
+
// Error 经 JSON.stringify 会变成 '{}',优先输出 message,避免丢失“未找到应用ID”等可定位提示
|
|
214
|
+
utils_1.log.error(err instanceof Error ? err.message : JSON.stringify(err));
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
/**
|
|
@@ -240,23 +244,6 @@ async function fetchLatestVersion(params) {
|
|
|
240
244
|
utils_1.log.error(JSON.stringify(err));
|
|
241
245
|
}
|
|
242
246
|
}
|
|
243
|
-
/**
|
|
244
|
-
* 按 manifest appId 查询应用详情(含 identifier),用于拼 COS 上传目录。
|
|
245
|
-
* 未查询到或请求失败时返回 null 并告警,由调用方回退 appId,不中断发布。
|
|
246
|
-
*/
|
|
247
|
-
async function fetchAppDetail(appId) {
|
|
248
|
-
if (!appId)
|
|
249
|
-
return null;
|
|
250
|
-
try {
|
|
251
|
-
await ensureLoggedIn();
|
|
252
|
-
const { data } = await http_1.http.get('/admin-api/system/app-mofang/app/get', { appId });
|
|
253
|
-
return data || null;
|
|
254
|
-
}
|
|
255
|
-
catch (err) {
|
|
256
|
-
utils_1.log.warning(`获取应用详情失败,将使用应用ID:${appId}`);
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
247
|
/**
|
|
261
248
|
* 获取应用信息
|
|
262
249
|
*/
|
package/lib/commands/option.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare const width: readonly ["--width <number>", "宽度(px)"];
|
|
|
36
36
|
export declare const height: readonly ["--height <number>", "高度(px)"];
|
|
37
37
|
export declare const left: readonly ["--left <value>", "左边距,支持 px 或百分比(如 421、38.9%)"];
|
|
38
38
|
export declare const top: readonly ["--top <value>", "顶部距离,支持 px 或百分比(如 451、23.9%)"];
|
|
39
|
-
export declare const bg: readonly ["--bg <color>", "
|
|
39
|
+
export declare const bg: readonly ["--bg <color>", "背景色(#ffffff 或 255,255,255,0)"];
|
|
40
40
|
export declare const hbuilderxCli: readonly ["--cli.hbuilderx <cli-path>", "HbuilderX Cli路径"];
|
|
41
41
|
export declare const weixinCli: readonly ["--cli.weixin <cli-path>", "微信开发者工具 Cli路径"];
|
|
42
42
|
export declare const alipayCli: readonly ["--cli.alipay <cli-path>", "支付宝开发者工具 Cli路径"];
|
package/lib/commands/option.js
CHANGED
|
@@ -44,7 +44,7 @@ exports.width = ['--width <number>', '宽度(px)'];
|
|
|
44
44
|
exports.height = ['--height <number>', '高度(px)'];
|
|
45
45
|
exports.left = ['--left <value>', '左边距,支持 px 或百分比(如 421、38.9%)'];
|
|
46
46
|
exports.top = ['--top <value>', '顶部距离,支持 px 或百分比(如 451、23.9%)'];
|
|
47
|
-
exports.bg = ['--bg <color>', '
|
|
47
|
+
exports.bg = ['--bg <color>', '背景色(#ffffff 或 255,255,255,0)'];
|
|
48
48
|
exports.hbuilderxCli = ['--cli.hbuilderx <cli-path>', 'HbuilderX Cli路径'];
|
|
49
49
|
exports.weixinCli = ['--cli.weixin <cli-path>', '微信开发者工具 Cli路径'];
|
|
50
50
|
exports.alipayCli = ['--cli.alipay <cli-path>', '支付宝开发者工具 Cli路径'];
|
package/lib/scripts/publish.js
CHANGED
|
@@ -21,17 +21,6 @@ const PUBLISH_APP_CFG = {
|
|
|
21
21
|
exe: config_1.CONFIG_DATA.h5?.windows,
|
|
22
22
|
apk: config_1.CONFIG_DATA.app?.android,
|
|
23
23
|
};
|
|
24
|
-
/** appId → 远端应用目录名,同一次构建的多次上传(wgt + zip)只查询一次 */
|
|
25
|
-
const remoteAppKeyCache = new Map();
|
|
26
|
-
/** 未配置上传路径时以应用标识作为 COS 应用目录,取不到时回退 appId */
|
|
27
|
-
async function resolveRemoteAppKey(appId) {
|
|
28
|
-
if (!remoteAppKeyCache.has(appId)) {
|
|
29
|
-
const detail = await (0, apis_1.fetchAppDetail)(appId);
|
|
30
|
-
const identifier = String(detail?.identifier || '').trim();
|
|
31
|
-
remoteAppKeyCache.set(appId, identifier || appId);
|
|
32
|
-
}
|
|
33
|
-
return remoteAppKeyCache.get(appId);
|
|
34
|
-
}
|
|
35
24
|
async function publish(options) {
|
|
36
25
|
const buildEnv = process.env.BUILD_ENV || '';
|
|
37
26
|
const pkg = (0, fs_extra_1.readJsonSync)(const_1.PACKAGE_PATH, { throws: false }) || {};
|
|
@@ -44,9 +33,11 @@ async function publish(options) {
|
|
|
44
33
|
const secretKey = config_1.CONFIG_DATA.cos?.secretkey || '';
|
|
45
34
|
const dir = options.dir || '';
|
|
46
35
|
const configPath = config_1.CONFIG_DATA.publish?.path || config_1.CONFIG_DATA.pub?.path || '';
|
|
47
|
-
// 只看配置路径:未配置 path
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
// 只看配置路径:未配置 path 时用业务应用 ID 作为 COS 应用目录(发布动作会补空 publish 对象,不能按 publish 是否存在判断)
|
|
37
|
+
if (!configPath && !appId) {
|
|
38
|
+
utils_1.log.error('未找到应用ID,请检查 package.json 的 appId 或 manifest.json 的 appid 配置');
|
|
39
|
+
}
|
|
40
|
+
const appPath = configPath || `/app/${appId}`;
|
|
50
41
|
// 接口 path 语义保持不变:默认带平台目录,配置路径时不追加
|
|
51
42
|
const platformPath = !configPath && dir ? `/${dir}` : '';
|
|
52
43
|
const remotePath = `${appPath}${platformPath}`;
|
package/lib/utils/function.d.ts
CHANGED
|
@@ -8,8 +8,7 @@ export declare function readManifest(path: string | undefined, parse: false): st
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function isUniappXManifest(pathOrManifest?: string | Record<string, unknown>): boolean;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* 存量项目可继续使用 package.appId;新项目可删除该字段后依赖 manifest.appid。
|
|
11
|
+
* 解析应用ID:package.json.appId(业务应用ID)优先,缺失时回退 manifest.appid(Uni 应用标识/uniId,仅旧项目兜底;服务端可能匹配不到应用)。
|
|
13
12
|
* @param manifest manifest.json 内容
|
|
14
13
|
* @param pkg package.json 内容
|
|
15
14
|
*/
|
package/lib/utils/function.js
CHANGED
|
@@ -53,8 +53,7 @@ function isUniappXManifest(pathOrManifest = const_1.COMMAND_PATH) {
|
|
|
53
53
|
return Object.prototype.hasOwnProperty.call(manifest, 'uni-app-x');
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
* 存量项目可继续使用 package.appId;新项目可删除该字段后依赖 manifest.appid。
|
|
56
|
+
* 解析应用ID:package.json.appId(业务应用ID)优先,缺失时回退 manifest.appid(Uni 应用标识/uniId,仅旧项目兜底;服务端可能匹配不到应用)。
|
|
58
57
|
* @param manifest manifest.json 内容
|
|
59
58
|
* @param pkg package.json 内容
|
|
60
59
|
*/
|
package/lib/utils/image.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface SplashGenerateInfo {
|
|
|
33
33
|
height: number;
|
|
34
34
|
/** 背景色 */
|
|
35
35
|
background: string;
|
|
36
|
+
/** 是否透明背景 */
|
|
37
|
+
transparent: boolean;
|
|
36
38
|
ninePatch: boolean;
|
|
37
39
|
/** LOGO 在输出图中的位置 */
|
|
38
40
|
logoBox: SplashBox;
|
|
@@ -60,6 +62,11 @@ export declare function parsePositiveInt(value: string, label: string): number;
|
|
|
60
62
|
export declare function parseLength(value: string, base: number, label: string): number;
|
|
61
63
|
/** 解析 #rgb / #rrggbb 颜色 */
|
|
62
64
|
export declare function parseHexColor(value: string): SplashRgba;
|
|
65
|
+
/**
|
|
66
|
+
* 解析启动图背景色。
|
|
67
|
+
* 支持 `#rgb` / `#rrggbb`,以及 `r,g,b` / `r,g,b,a`(0~255)。
|
|
68
|
+
*/
|
|
69
|
+
export declare function parseBackgroundColor(value?: string): SplashRgba;
|
|
63
70
|
/** 颜色转 #rrggbb */
|
|
64
71
|
export declare function colorToHex(color: SplashRgba): string;
|
|
65
72
|
/**
|
package/lib/utils/image.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.DEFAULT_SPLASH_TOP = exports.DEFAULT_SPLASH_LEFT = exports.DEFAULT_SPLAS
|
|
|
7
7
|
exports.parsePositiveInt = parsePositiveInt;
|
|
8
8
|
exports.parseLength = parseLength;
|
|
9
9
|
exports.parseHexColor = parseHexColor;
|
|
10
|
+
exports.parseBackgroundColor = parseBackgroundColor;
|
|
10
11
|
exports.colorToHex = colorToHex;
|
|
11
12
|
exports.normalizeSplashName = normalizeSplashName;
|
|
12
13
|
exports.defaultSplashLeft = defaultSplashLeft;
|
|
@@ -85,6 +86,35 @@ function parseHexColor(value) {
|
|
|
85
86
|
a: 255,
|
|
86
87
|
};
|
|
87
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* 解析启动图背景色。
|
|
91
|
+
* 支持 `#rgb` / `#rrggbb`,以及 `r,g,b` / `r,g,b,a`(0~255)。
|
|
92
|
+
*/
|
|
93
|
+
function parseBackgroundColor(value) {
|
|
94
|
+
const text = String(value ?? '').trim();
|
|
95
|
+
if (!text) {
|
|
96
|
+
return { r: 255, g: 255, b: 255, a: 255 };
|
|
97
|
+
}
|
|
98
|
+
if (!text.includes(',')) {
|
|
99
|
+
return parseHexColor(text);
|
|
100
|
+
}
|
|
101
|
+
const parts = text.split(',').map((part) => part.trim());
|
|
102
|
+
if (parts.length !== 3 && parts.length !== 4) {
|
|
103
|
+
throw new Error(`--bg 颜色格式无效:${value},请使用 #rgb / #rrggbb 或 r,g,b / r,g,b,a`);
|
|
104
|
+
}
|
|
105
|
+
const channels = parts.map((part) => {
|
|
106
|
+
if (!/^\d+$/.test(part)) {
|
|
107
|
+
throw new Error(`--bg 颜色格式无效:${value},请使用 0~255 的整数`);
|
|
108
|
+
}
|
|
109
|
+
const channel = parseInt(part, 10);
|
|
110
|
+
if (channel > 255) {
|
|
111
|
+
throw new Error(`--bg 颜色格式无效:${value},每个通道必须在 0~255 之间`);
|
|
112
|
+
}
|
|
113
|
+
return channel;
|
|
114
|
+
});
|
|
115
|
+
const [r, g, b, a = 255] = channels;
|
|
116
|
+
return { r, g, b, a };
|
|
117
|
+
}
|
|
88
118
|
/** 颜色转 #rrggbb */
|
|
89
119
|
function colorToHex(color) {
|
|
90
120
|
const hex = [color.r, color.g, color.b]
|
|
@@ -205,6 +235,13 @@ function compositeRaw(canvas, width, height, source, sourceWidth, sourceHeight,
|
|
|
205
235
|
if (alpha === 0)
|
|
206
236
|
continue;
|
|
207
237
|
const targetIndex = (targetY * width + targetX) * 4;
|
|
238
|
+
if (canvas[targetIndex + 3] === 0) {
|
|
239
|
+
canvas[targetIndex] = source[sourceIndex];
|
|
240
|
+
canvas[targetIndex + 1] = source[sourceIndex + 1];
|
|
241
|
+
canvas[targetIndex + 2] = source[sourceIndex + 2];
|
|
242
|
+
canvas[targetIndex + 3] = alpha;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
208
245
|
if (alpha === 255) {
|
|
209
246
|
canvas[targetIndex] = source[sourceIndex];
|
|
210
247
|
canvas[targetIndex + 1] = source[sourceIndex + 1];
|
|
@@ -404,10 +441,12 @@ async function validateOutput(buffer, options, expected, tolerance, strictBox, p
|
|
|
404
441
|
if (inPaste)
|
|
405
442
|
continue;
|
|
406
443
|
const idx = (y * raw.width + x) * 4;
|
|
407
|
-
const isBackground =
|
|
408
|
-
raw.data[idx +
|
|
409
|
-
raw.data[idx
|
|
410
|
-
|
|
444
|
+
const isBackground = options.background.a === 0
|
|
445
|
+
? raw.data[idx + 3] === 0
|
|
446
|
+
: raw.data[idx] === options.background.r &&
|
|
447
|
+
raw.data[idx + 1] === options.background.g &&
|
|
448
|
+
raw.data[idx + 2] === options.background.b &&
|
|
449
|
+
raw.data[idx + 3] === 255;
|
|
411
450
|
if (!isBackground) {
|
|
412
451
|
throw new Error('启动图生成结果校验失败:背景色异常');
|
|
413
452
|
}
|
|
@@ -432,7 +471,13 @@ async function generateSplash(options) {
|
|
|
432
471
|
if (!Number.isInteger(top) || top < 0) {
|
|
433
472
|
throw new Error('--top 必须为非负整数');
|
|
434
473
|
}
|
|
474
|
+
if (background.a !== 0 && background.a !== 255) {
|
|
475
|
+
throw new Error('背景透明度仅支持 0(透明)或 255(不透明)');
|
|
476
|
+
}
|
|
435
477
|
if (ninePatch) {
|
|
478
|
+
if (background.a === 0) {
|
|
479
|
+
throw new Error('9-patch 启动图不支持透明背景');
|
|
480
|
+
}
|
|
436
481
|
if (width < MIN_NINE_PATCH_SIZE || height < MIN_NINE_PATCH_SIZE) {
|
|
437
482
|
throw new Error(`9-patch 启动图尺寸不能小于 ${MIN_NINE_PATCH_SIZE}×${MIN_NINE_PATCH_SIZE}`);
|
|
438
483
|
}
|
|
@@ -463,7 +508,7 @@ async function generateSplash(options) {
|
|
|
463
508
|
canvas[idx] = background.r;
|
|
464
509
|
canvas[idx + 1] = background.g;
|
|
465
510
|
canvas[idx + 2] = background.b;
|
|
466
|
-
canvas[idx + 3] =
|
|
511
|
+
canvas[idx + 3] = background.a;
|
|
467
512
|
}
|
|
468
513
|
const scaledWidth = Math.max(1, Math.round(logoRaw.width * logoScale));
|
|
469
514
|
const scaledHeight = Math.max(1, Math.round(logoRaw.height * logoScale));
|
|
@@ -503,6 +548,7 @@ async function generateSplash(options) {
|
|
|
503
548
|
width,
|
|
504
549
|
height,
|
|
505
550
|
background: colorToHex(background),
|
|
551
|
+
transparent: background.a === 0,
|
|
506
552
|
ninePatch,
|
|
507
553
|
logoBox: expectedBox,
|
|
508
554
|
logoBackground: logoBackground ? colorToHex(logoBackground) : null,
|