Skip to content

Commit

Permalink
build: remove unused language locale resources
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <adam.setch@outlook.com>
  • Loading branch information
setchy committed Oct 5, 2024
1 parent 88d9d88 commit 0704d28
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
"owner": "gitify-app",
"repo": "gitify"
},
"afterSign": "scripts/notarize.js"
"afterSign": "scripts/notarize.js",
"afterPack": "scripts/remove-unused-locales.js"
},
"dependencies": {
"@electron/remote": "2.1.2",
Expand Down
41 changes: 41 additions & 0 deletions scripts/remove-unused-locales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const path = require('node:path');
const fs = require('node:fs');

const packageJson = require('../package.json');
const electronLanguages = packageJson.build.electronLanguages;

exports.default = async (context) => {
const appName = context.packager.appInfo.productFilename;
const appOutDir = context.appOutDir;
const platform = context.electronPlatformName;

if (platform !== 'darwin') {
return;
}

const resourcesPath = path.join(
appOutDir,
`${appName}.app`,
'Contents',
'Frameworks',
'Electron Framework.framework',
'Versions',
'A',
'Resources',
);

// Get all locale directories
const allLocales = fs
.readdirSync(resourcesPath)
.filter((file) => file.endsWith('.lproj'));

const langLocales = electronLanguages.map((lang) => `${lang}.lproj`);

// Remove unused locales
for (const locale of allLocales) {
if (!langLocales.includes(locale)) {
const localePath = path.join(resourcesPath, locale);
fs.rmSync(localePath, { recursive: true });
}
}
};

0 comments on commit 0704d28

Please sign in to comment.