Skip to content

Commit 42dfadc

Browse files
authored
build: remove unused language locale resources (#1573)
Signed-off-by: Adam Setch <[email protected]>
1 parent 010b155 commit 42dfadc

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
"owner": "gitify-app",
123123
"repo": "gitify"
124124
},
125-
"afterSign": "scripts/notarize.js"
125+
"afterSign": "scripts/notarize.js",
126+
"afterPack": "scripts/remove-unused-locales.js"
126127
},
127128
"dependencies": {
128129
"@electron/remote": "2.1.2",

scripts/remove-unused-locales.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const path = require('node:path');
2+
const fs = require('node:fs');
3+
4+
const packageJson = require('../package.json');
5+
const electronLanguages = packageJson.build.electronLanguages;
6+
7+
exports.default = async (context) => {
8+
const appName = context.packager.appInfo.productFilename;
9+
const appOutDir = context.appOutDir;
10+
const platform = context.electronPlatformName;
11+
12+
if (platform !== 'darwin') {
13+
return;
14+
}
15+
16+
const resourcesPath = path.join(
17+
appOutDir,
18+
`${appName}.app`,
19+
'Contents',
20+
'Frameworks',
21+
'Electron Framework.framework',
22+
'Versions',
23+
'A',
24+
'Resources',
25+
);
26+
27+
// Get all locale directories
28+
const allLocales = fs
29+
.readdirSync(resourcesPath)
30+
.filter((file) => file.endsWith('.lproj'));
31+
32+
const langLocales = electronLanguages.map((lang) => `${lang}.lproj`);
33+
34+
// Remove unused locales
35+
for (const locale of allLocales) {
36+
if (!langLocales.includes(locale)) {
37+
const localePath = path.join(resourcesPath, locale);
38+
fs.rmSync(localePath, { recursive: true });
39+
}
40+
}
41+
};

0 commit comments

Comments
 (0)