-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(macOS) Removed unused locales in order to reduce UI app size
- Loading branch information
Showing
7 changed files
with
76 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,58 @@ | ||
var fs = require ('fs'); | ||
const path = require('path'); | ||
|
||
exports.default = async function (context) { | ||
console.log (`afterPack hook triggered (${__filename})`); | ||
console.log (" - removing all locales except en-US"); | ||
var fs = require ('fs'); | ||
var localeDir = context.appOutDir+'/locales/'; | ||
|
||
fs.readdir (localeDir, function (err, files) { | ||
if (! (files && files.length)) return; | ||
for (var i = 0, len = files.length; i < len; i++) { | ||
var match = files[i].match(/en-US\.pak/); | ||
if (match === null) { | ||
fs.unlinkSync (localeDir+files [i]); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
console.log (`AfterPack hook triggered ('${__filename}')`); | ||
|
||
// In order to reduce the size of the app, we remove all unused locales | ||
try { | ||
if (context?.packager?.platform?.buildConfigurationKey === 'mac') { | ||
let localeDir = context.appOutDir+'/IVPN.app/Contents/Frameworks/Electron Framework.framework/Resources/'; | ||
if (fs.existsSync(localeDir)) | ||
removeLocalesMac(localeDir); | ||
} else { | ||
let localeDir = context.appOutDir+'/locales/'; | ||
if (fs.existsSync(localeDir)) | ||
removeLocales(localeDir); | ||
} | ||
} catch (e) { | ||
console.error("Error removing locales in afterPack hook:", e); | ||
} | ||
} | ||
|
||
function removeLocales(localesFolderPath) { | ||
console.log (` - removing all locales except en-US (from '${localesFolderPath}')`); | ||
let removedCnt = 0; | ||
let files = fs.readdirSync(localesFolderPath); | ||
if (files && files.length) { | ||
for (var i = 0, len = files.length; i < len; i++) { | ||
var match = files[i].match(/en-US\.pak/); | ||
if (match === null) { | ||
fs.unlinkSync(path.join(localesFolderPath, files[i])); | ||
removedCnt+=1; | ||
} | ||
} | ||
} | ||
console.log (` removed ${removedCnt} locales`); | ||
} | ||
|
||
function removeLocalesMac(resourcesFolderPath) { | ||
console.log (` - removing all locales except en/en-US (from '${resourcesFolderPath}')`); | ||
let removedCnt = 0; | ||
let files = fs.readdirSync(resourcesFolderPath); | ||
if (files && files.length) { | ||
for (var i = 0, len = files.length; i < len; i++) { | ||
const lprojDir = files[i]; | ||
if (lprojDir === 'en.lproj' || lprojDir === 'en-US.lproj' || lprojDir === 'en_US.lproj') | ||
continue; | ||
const lprojDirPath = path.join(resourcesFolderPath, files[i]); | ||
const localePakPath = path.join(lprojDirPath,"locale.pak"); | ||
if (fs.lstatSync(lprojDirPath).isDirectory() && path.extname(lprojDirPath) === '.lproj' && fs.existsSync(localePakPath)) { | ||
fs.unlinkSync(localePakPath); | ||
fs.rmdirSync(lprojDirPath); | ||
removedCnt+=1; | ||
} | ||
} | ||
} | ||
console.log (` removed ${removedCnt} locales`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters