mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
fix(forge): adapt removing lproj on macOS
This commit is contained in:
parent
3d7784ca18
commit
7427507aca
@ -144,24 +144,36 @@ module.exports = {
|
||||
hooks: {
|
||||
// Remove unused locales from the packaged app to save some space.
|
||||
postPackage(_, packageResult) {
|
||||
const localesToKeep = LOCALES
|
||||
const isMac = (process.platform === "darwin");
|
||||
let localesToKeep = LOCALES
|
||||
.filter(locale => !locale.contentOnly)
|
||||
.map(locale => locale.electronLocale.replace("_", "-"));
|
||||
.map(locale => locale.electronLocale);
|
||||
if (!isMac) {
|
||||
localesToKeep.map(locale => locale.replace("_", "-"))
|
||||
}
|
||||
|
||||
const keptLocales = new Set();
|
||||
const removedLocales = [];
|
||||
const extension = (isMac ? ".lproj" : ".pak");
|
||||
|
||||
for (const outputPath of packageResult.outputPaths) {
|
||||
const localesDir = path.join(outputPath, 'locales');
|
||||
const localesDir = isMac
|
||||
? path.join(outputPath, "TriliumNext Notes.app/Contents/Resources")
|
||||
: path.join(outputPath, 'locales');
|
||||
|
||||
if (!fs.existsSync(localesDir)) {
|
||||
console.log('No locales directory found. Skipping cleanup.');
|
||||
return;
|
||||
console.log(`No locales directory found in '${localesDir}'.`);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(localesDir);
|
||||
|
||||
for (const file of files) {
|
||||
let localeName = path.basename(file, ".pak");
|
||||
if (!file.endsWith(extension)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let localeName = path.basename(file, extension);
|
||||
if (localeName === "en-US" && process.platform === "win32") {
|
||||
// If the locale is "en-US" on Windows, we treat it as "en".
|
||||
// This is because the Windows version of Electron uses "en-US.pak" instead of "en.pak".
|
||||
@ -174,7 +186,12 @@ module.exports = {
|
||||
}
|
||||
|
||||
const filePath = path.join(localesDir, file);
|
||||
if (isMac) {
|
||||
fs.rm(filePath, { recursive: true });
|
||||
} else {
|
||||
fs.unlinkSync(filePath);
|
||||
}
|
||||
|
||||
removedLocales.push(file);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user