diff --git a/package.json b/package.json index a227ebcfb..3993be1aa 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/remove-unused-locales.js b/scripts/remove-unused-locales.js new file mode 100644 index 000000000..c5494d58a --- /dev/null +++ b/scripts/remove-unused-locales.js @@ -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 }); + } + } +};