mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +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: {
|
hooks: {
|
||||||
// Remove unused locales from the packaged app to save some space.
|
// Remove unused locales from the packaged app to save some space.
|
||||||
postPackage(_, packageResult) {
|
postPackage(_, packageResult) {
|
||||||
const localesToKeep = LOCALES
|
const isMac = (process.platform === "darwin");
|
||||||
|
let localesToKeep = LOCALES
|
||||||
.filter(locale => !locale.contentOnly)
|
.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 keptLocales = new Set();
|
||||||
const removedLocales = [];
|
const removedLocales = [];
|
||||||
|
const extension = (isMac ? ".lproj" : ".pak");
|
||||||
|
|
||||||
for (const outputPath of packageResult.outputPaths) {
|
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)) {
|
if (!fs.existsSync(localesDir)) {
|
||||||
console.log('No locales directory found. Skipping cleanup.');
|
console.log(`No locales directory found in '${localesDir}'.`);
|
||||||
return;
|
process.exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = fs.readdirSync(localesDir);
|
const files = fs.readdirSync(localesDir);
|
||||||
|
|
||||||
for (const file of files) {
|
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 (localeName === "en-US" && process.platform === "win32") {
|
||||||
// If the locale is "en-US" on Windows, we treat it as "en".
|
// 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".
|
// 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);
|
const filePath = path.join(localesDir, file);
|
||||||
|
if (isMac) {
|
||||||
|
fs.rm(filePath, { recursive: true });
|
||||||
|
} else {
|
||||||
fs.unlinkSync(filePath);
|
fs.unlinkSync(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
removedLocales.push(file);
|
removedLocales.push(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user