feat(desktop-client): add afterPack hook to clean up unnecessary localization files and include certificate files for code signing
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// electron-builder afterPack hook — 在签名前裁掉不要的本地化文件
|
||||
// 解决 electron-builder 25 + Electron 41 不识别 *_NEUTER / *_MASCULINE / *_FEMININE 变体的 bug
|
||||
// 220 个 .lproj → 仅保留 en* 和 zh_CN*,签名时间从 ~10 分钟降到 ~30 秒
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 只保留 en 和 zh_CN(性别变体 *_NEUTER/_MASCULINE/_FEMININE 在调用方已剥离)
|
||||
const KEEP = new Set(['en', 'zh_CN']);
|
||||
function shouldKeepLocale(base) {
|
||||
return KEEP.has(base);
|
||||
}
|
||||
|
||||
exports.default = async function afterPack(context) {
|
||||
const { appOutDir, packager } = context;
|
||||
const productFilename = packager.appInfo.productFilename;
|
||||
const appPath = path.join(appOutDir, `${productFilename}.app`);
|
||||
|
||||
// 两处都要清理:app 自己的 Resources + Electron Framework 的 Resources
|
||||
const dirs = [
|
||||
path.join(appPath, 'Contents/Resources'),
|
||||
path.join(appPath, 'Contents/Frameworks/Electron Framework.framework/Versions/A/Resources'),
|
||||
];
|
||||
|
||||
let removed = 0;
|
||||
let kept = 0;
|
||||
|
||||
for (const dir of dirs) {
|
||||
if (!fs.existsSync(dir)) continue;
|
||||
for (const entry of fs.readdirSync(dir)) {
|
||||
if (!entry.endsWith('.lproj')) continue;
|
||||
// 去掉 .lproj 后缀和性别变体后缀,得到基础语言代码
|
||||
const base = entry
|
||||
.replace(/\.lproj$/, '')
|
||||
.replace(/_(NEUTER|MASCULINE|FEMININE)$/, '');
|
||||
|
||||
if (shouldKeepLocale(base)) {
|
||||
kept++;
|
||||
} else {
|
||||
fs.rmSync(path.join(dir, entry), { recursive: true, force: true });
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[afterPack] 本地化清理:保留 ${kept} 个,删除 ${removed} 个 .lproj`);
|
||||
};
|
||||
Reference in New Issue
Block a user