feat(forge): remove unused locales

This commit is contained in:
Elian Doran 2025-06-11 21:08:02 +03:00
parent 825c2c1fe9
commit 23c45ee219
No known key found for this signature in database
3 changed files with 36 additions and 0 deletions

View File

@ -1,5 +1,6 @@
const path = require("path"); const path = require("path");
const fs = require("fs-extra"); const fs = require("fs-extra");
const { LOCALES } = require("@triliumnext/commons");
const ELECTRON_FORGE_DIR = __dirname; const ELECTRON_FORGE_DIR = __dirname;
@ -141,6 +142,35 @@ 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("_", "-"));
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) {
const localeName = path.basename(file, ".pak");
if (localesToKeep.includes(localeName)) {
continue;
}
console.log(`Removing unused locale file: ${file}`);
const filePath = path.join(localesDir, file);
fs.unlinkSync(filePath);
}
}
},
// 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");
fs.mkdirpSync(outputDir); fs.mkdirpSync(outputDir);

View File

@ -24,6 +24,9 @@
"references": [ "references": [
{ {
"path": "../server/tsconfig.app.json" "path": "../server/tsconfig.app.json"
},
{
"path": "../../packages/commons/tsconfig.lib.json"
} }
] ]
} }

View File

@ -6,6 +6,9 @@
{ {
"path": "../server" "path": "../server"
}, },
{
"path": "../../packages/commons"
},
{ {
"path": "./tsconfig.app.json" "path": "./tsconfig.app.json"
} }