From 0c1185df3322112d3afc17d006f58b012fbfbd26 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 5 Feb 2025 08:53:06 +0100 Subject: [PATCH 1/4] refactor(forge.config): make afterComplete more concise --- forge.config.cjs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/forge.config.cjs b/forge.config.cjs index 1b2e06f22..b4b0a96b5 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -23,19 +23,16 @@ module.exports = { const extraResources = getExtraResourcesForPlatform(); for (const resource of extraResources) { const baseName = path.basename(resource); - let sourcePath; - if (platform === "darwin") { - sourcePath = path.join(buildPath, `${APP_NAME}.app`, "Contents", "Resources", baseName); - } else { - sourcePath = path.join(buildPath, "resources", baseName); - } - let destPath; - if (baseName !== "256x256.png") { - destPath = path.join(buildPath, baseName); - } else { - destPath = path.join(buildPath, "icon.png"); - } + // prettier-ignore + const sourcePath = (platform === "darwin") + ? path.join(buildPath, `${APP_NAME}.app`, "Contents", "Resources", baseName) + : path.join(buildPath, "resources", baseName); + + // prettier-ignore + const destPath = (baseName !== "256x256.png") + ? path.join(buildPath, baseName) + : path.join(buildPath, "icon.png"); // Copy files from resources folder to root fs.move(sourcePath, destPath) From e0862ce8f31b0ea9636780bedb04be43e70e9f9f Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 5 Feb 2025 09:30:55 +0100 Subject: [PATCH 2/4] refactor(forge.config): avoid duplication for linux makers adds a baseLinuxMakersConfigOptions --- forge.config.cjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/forge.config.cjs b/forge.config.cjs index b4b0a96b5..b1e53a7e5 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -3,6 +3,11 @@ const fs = require("fs-extra"); const APP_NAME = "TriliumNext Notes"; +const baseLinuxMakerConfigOptions = { + icon: "./images/app-icons/png/128x128.png", + desktopTemplate: path.resolve("./bin/electron-forge/desktop.ejs"), +}; + module.exports = { packagerConfig: { executableName: "trilium", @@ -50,8 +55,7 @@ module.exports = { name: "@electron-forge/maker-deb", config: { options: { - icon: "./images/app-icons/png/128x128.png", - desktopTemplate: path.resolve("./bin/electron-forge/desktop.ejs") + ...baseLinuxMakerConfigOptions } } }, @@ -59,8 +63,7 @@ module.exports = { name: "@electron-forge/maker-rpm", config: { options: { - icon: "./images/app-icons/png/128x128.png", - desktopTemplate: path.resolve("./bin/electron-forge/desktop.ejs") + ...baseLinuxMakerConfigOptions } } }, From 2b83470de6cd150080a9f745cd1f1c1e84478ef5 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 5 Feb 2025 09:33:33 +0100 Subject: [PATCH 3/4] refactor(forge.config): call getExtraResourcesForPlatform once only --- forge.config.cjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forge.config.cjs b/forge.config.cjs index b1e53a7e5..b4dd1a7ee 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -3,6 +3,7 @@ const fs = require("fs-extra"); const APP_NAME = "TriliumNext Notes"; +const extraResourcesForPlatform = getExtraResourcesForPlatform(); const baseLinuxMakerConfigOptions = { icon: "./images/app-icons/png/128x128.png", desktopTemplate: path.resolve("./bin/electron-forge/desktop.ejs"), @@ -17,7 +18,7 @@ module.exports = { icon: "./images/app-icons/icon", extraResource: [ // Moved to root - ...getExtraResourcesForPlatform(), + ...extraResourcesForPlatform, // Moved to resources (TriliumNext Notes.app/Contents/Resources on macOS) "translations/", @@ -25,8 +26,7 @@ module.exports = { ], afterComplete: [ (buildPath, _electronVersion, platform, _arch, callback) => { - const extraResources = getExtraResourcesForPlatform(); - for (const resource of extraResources) { + for (const resource of extraResourcesForPlatform) { const baseName = path.basename(resource); // prettier-ignore From 62099abb2948e9640947a30ad8dc742cdfa89b37 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 5 Feb 2025 09:56:08 +0100 Subject: [PATCH 4/4] refactor(forge.config): simplify getExtraResourcesForPlatform --- forge.config.cjs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/forge.config.cjs b/forge.config.cjs index b4dd1a7ee..b3765a35b 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -100,21 +100,20 @@ module.exports = { }; function getExtraResourcesForPlatform() { - let resources = ["dump-db/", "./bin/tpl/anonymize-database.sql"]; - const scripts = ["trilium-portable", "trilium-safe-mode", "trilium-no-cert-check"]; + const resources = ["dump-db/", "./bin/tpl/anonymize-database.sql"]; + + const getScriptRessources = () => { + const scripts = ["trilium-portable", "trilium-safe-mode", "trilium-no-cert-check"]; + const scriptExt = (process.platform === "win32") ? "bat" : "sh"; + return scripts.map(script => `./bin/tpl/${script}.${scriptExt}`); + } + switch (process.platform) { case "win32": - for (const script of scripts) { - resources.push(`./bin/tpl/${script}.bat`); - } - break; - case "darwin": + resources.push(...getScriptRessources()) break; case "linux": - resources.push("images/app-icons/png/256x256.png"); - for (const script of scripts) { - resources.push(`./bin/tpl/${script}.sh`); - } + resources.push(...getScriptRessources(), "images/app-icons/png/256x256.png"); break; default: break;