mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
fix(desktop): use plugin to clean up languages
This commit is contained in:
parent
58e2bc2b6c
commit
cbcc219f1f
@ -1,6 +1,7 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const { LOCALES } = require("@triliumnext/commons");
|
const { LOCALES } = require("@triliumnext/commons");
|
||||||
|
const setLanguages = require('electron-packager-languages');
|
||||||
|
|
||||||
const ELECTRON_FORGE_DIR = __dirname;
|
const ELECTRON_FORGE_DIR = __dirname;
|
||||||
|
|
||||||
@ -29,6 +30,10 @@ const macosSignConfiguration = process.env.APPLE_ID ? {
|
|||||||
}
|
}
|
||||||
} : undefined;
|
} : undefined;
|
||||||
|
|
||||||
|
const localesToKeep = LOCALES
|
||||||
|
.filter(locale => !locale.contentOnly)
|
||||||
|
.map(locale => locale.electronLocale);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
outDir: "out",
|
outDir: "out",
|
||||||
// Documentation of `packagerConfig` options: https://electron.github.io/packager/main/interfaces/Options.html
|
// Documentation of `packagerConfig` options: https://electron.github.io/packager/main/interfaces/Options.html
|
||||||
@ -45,6 +50,9 @@ module.exports = {
|
|||||||
...(process.platform === "darwin" ? [] : extraResourcesForPlatform)
|
...(process.platform === "darwin" ? [] : extraResourcesForPlatform)
|
||||||
],
|
],
|
||||||
prune: false,
|
prune: false,
|
||||||
|
afterCopy: [
|
||||||
|
setLanguages(localesToKeep)
|
||||||
|
],
|
||||||
afterComplete: [
|
afterComplete: [
|
||||||
(buildPath, _electronVersion, platform, _arch, callback) => {
|
(buildPath, _electronVersion, platform, _arch, callback) => {
|
||||||
// Only move resources on non-macOS platforms
|
// Only move resources on non-macOS platforms
|
||||||
@ -142,53 +150,6 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
hooks: {
|
hooks: {
|
||||||
// Remove unused locales from the packaged app to save some space.
|
|
||||||
postPackage(_, packageResult) {
|
|
||||||
const localesToKeep = LOCALES
|
|
||||||
.filter(locale => !locale.contentOnly)
|
|
||||||
.map(locale => locale.electronLocale.replace("_", "-"));
|
|
||||||
const keptLocales = new Set();
|
|
||||||
const removedLocales = [];
|
|
||||||
|
|
||||||
for (const outputPath of packageResult.outputPaths) {
|
|
||||||
const localesDir = path.join(outputPath, 'locales');
|
|
||||||
|
|
||||||
if (!fs.existsSync(localesDir)) {
|
|
||||||
console.log('No locales directory found. Skipping cleanup.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = fs.readdirSync(localesDir);
|
|
||||||
|
|
||||||
for (const file of files) {
|
|
||||||
let localeName = path.basename(file, ".pak");
|
|
||||||
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".
|
|
||||||
localeName = "en";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localesToKeep.includes(localeName)) {
|
|
||||||
keptLocales.add(localeName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filePath = path.join(localesDir, file);
|
|
||||||
fs.unlinkSync(filePath);
|
|
||||||
removedLocales.push(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Removed unused locale files: ${removedLocales.join(", ")}`);
|
|
||||||
|
|
||||||
// Ensure all locales that should be kept are actually present.
|
|
||||||
for (const locale of localesToKeep) {
|
|
||||||
if (!keptLocales.has(locale)) {
|
|
||||||
console.error(`Locale ${locale} was not found in the packaged app.`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// Gather all the artifacts produced by the makers and copy them to a common upload directory.
|
// Gather all the artifacts produced by the makers and copy them to a common upload directory.
|
||||||
postMake(_, makeResults) {
|
postMake(_, makeResults) {
|
||||||
const outputDir = path.join(__dirname, "..", "upload");
|
const outputDir = path.join(__dirname, "..", "upload");
|
||||||
|
@ -10,14 +10,10 @@
|
|||||||
"electron-debug": "4.1.0",
|
"electron-debug": "4.1.0",
|
||||||
"electron-dl": "4.0.0",
|
"electron-dl": "4.0.0",
|
||||||
"electron-squirrel-startup": "1.0.1",
|
"electron-squirrel-startup": "1.0.1",
|
||||||
"jquery.fancytree": "2.38.5",
|
"jquery-hotkeys": "0.2.2",
|
||||||
"jquery-hotkeys": "0.2.2"
|
"jquery.fancytree": "2.38.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/electron-squirrel-startup": "1.0.2",
|
|
||||||
"@triliumnext/server": "workspace:*",
|
|
||||||
"copy-webpack-plugin": "13.0.0",
|
|
||||||
"electron": "36.4.0",
|
|
||||||
"@electron-forge/cli": "7.8.1",
|
"@electron-forge/cli": "7.8.1",
|
||||||
"@electron-forge/maker-deb": "7.8.1",
|
"@electron-forge/maker-deb": "7.8.1",
|
||||||
"@electron-forge/maker-dmg": "7.8.1",
|
"@electron-forge/maker-dmg": "7.8.1",
|
||||||
@ -26,6 +22,11 @@
|
|||||||
"@electron-forge/maker-squirrel": "7.8.1",
|
"@electron-forge/maker-squirrel": "7.8.1",
|
||||||
"@electron-forge/maker-zip": "7.8.1",
|
"@electron-forge/maker-zip": "7.8.1",
|
||||||
"@electron-forge/plugin-auto-unpack-natives": "7.8.1",
|
"@electron-forge/plugin-auto-unpack-natives": "7.8.1",
|
||||||
|
"@triliumnext/server": "workspace:*",
|
||||||
|
"@types/electron-squirrel-startup": "1.0.2",
|
||||||
|
"copy-webpack-plugin": "13.0.0",
|
||||||
|
"electron": "36.4.0",
|
||||||
|
"electron-packager-languages": "0.6.0",
|
||||||
"prebuild-install": "^7.1.1"
|
"prebuild-install": "^7.1.1"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
12
pnpm-lock.yaml
generated
12
pnpm-lock.yaml
generated
@ -394,6 +394,9 @@ importers:
|
|||||||
electron:
|
electron:
|
||||||
specifier: 36.4.0
|
specifier: 36.4.0
|
||||||
version: 36.4.0
|
version: 36.4.0
|
||||||
|
electron-packager-languages:
|
||||||
|
specifier: 0.6.0
|
||||||
|
version: 0.6.0
|
||||||
prebuild-install:
|
prebuild-install:
|
||||||
specifier: ^7.1.1
|
specifier: ^7.1.1
|
||||||
version: 7.1.3
|
version: 7.1.3
|
||||||
@ -7191,6 +7194,10 @@ packages:
|
|||||||
electron-localshortcut@3.2.1:
|
electron-localshortcut@3.2.1:
|
||||||
resolution: {integrity: sha512-DWvhKv36GsdXKnaFFhEiK8kZZA+24/yFLgtTwJJHc7AFgDjNRIBJZ/jq62Y/dWv9E4ypYwrVWN2bVrCYw1uv7Q==}
|
resolution: {integrity: sha512-DWvhKv36GsdXKnaFFhEiK8kZZA+24/yFLgtTwJJHc7AFgDjNRIBJZ/jq62Y/dWv9E4ypYwrVWN2bVrCYw1uv7Q==}
|
||||||
|
|
||||||
|
electron-packager-languages@0.6.0:
|
||||||
|
resolution: {integrity: sha512-vdSTJ6nH93RFo2YnoFbQDb9IAgMTG8ixYOQZuunpFVIUhKpPrRhmbQOuTBk7zJt5eaKUhMZixMD87WQynnM5iQ==}
|
||||||
|
engines: {node: '>6.0.0'}
|
||||||
|
|
||||||
electron-squirrel-startup@1.0.1:
|
electron-squirrel-startup@1.0.1:
|
||||||
resolution: {integrity: sha512-sTfFIHGku+7PsHLJ7v0dRcZNkALrV+YEozINTW8X1nM//e5O3L+rfYuvSW00lmGHnYmUjARZulD8F2V8ISI9RA==}
|
resolution: {integrity: sha512-sTfFIHGku+7PsHLJ7v0dRcZNkALrV+YEozINTW8X1nM//e5O3L+rfYuvSW00lmGHnYmUjARZulD8F2V8ISI9RA==}
|
||||||
|
|
||||||
@ -21351,6 +21358,10 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
|
electron-packager-languages@0.6.0:
|
||||||
|
dependencies:
|
||||||
|
rimraf: 2.6.3
|
||||||
|
|
||||||
electron-squirrel-startup@1.0.1:
|
electron-squirrel-startup@1.0.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
debug: 2.6.9
|
debug: 2.6.9
|
||||||
@ -26258,7 +26269,6 @@ snapshots:
|
|||||||
rimraf@2.6.3:
|
rimraf@2.6.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
glob: 7.2.3
|
glob: 7.2.3
|
||||||
optional: true
|
|
||||||
|
|
||||||
rimraf@3.0.2:
|
rimraf@3.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user