Notes/apps/desktop/electron-forge/forge.config.cjs

225 lines
8.5 KiB
JavaScript
Raw Normal View History

2025-01-09 18:07:02 +02:00
const path = require("path");
const fs = require("fs-extra");
2024-08-05 18:47:57 +02:00
2025-04-26 09:56:23 +03:00
const ELECTRON_FORGE_DIR = __dirname;
2025-04-26 01:09:28 +03:00
const EXECUTABLE_NAME = "trilium"; // keep in sync with server's package.json -> packagerConfig.executableName
const PRODUCT_NAME = "TriliumNext Notes";
2025-04-26 09:56:23 +03:00
const APP_ICON_PATH = path.join(ELECTRON_FORGE_DIR, "app-icon");
const extraResourcesForPlatform = getExtraResourcesForPlatform();
const baseLinuxMakerConfigOptions = {
name: EXECUTABLE_NAME,
productName: PRODUCT_NAME,
2025-04-26 09:56:23 +03:00
icon: path.join(APP_ICON_PATH, "png/128x128.png"),
desktopTemplate: path.resolve(path.join(ELECTRON_FORGE_DIR, "desktop.ejs")),
categories: ["Office", "Utility"]
};
const windowsSignConfiguration = process.env.WINDOWS_SIGN_EXECUTABLE ? {
hookModulePath: path.join(ELECTRON_FORGE_DIR, "sign-windows.cjs")
} : undefined;
module.exports = {
outDir: "out",
// Documentation of `packagerConfig` options: https://electron.github.io/packager/main/interfaces/Options.html
2025-01-09 18:07:02 +02:00
packagerConfig: {
executableName: EXECUTABLE_NAME,
name: PRODUCT_NAME,
2025-01-09 18:07:02 +02:00
overwrite: true,
asar: true,
2025-04-26 09:56:23 +03:00
icon: path.join(APP_ICON_PATH, "icon"),
osxSign: {},
osxNotarize: {
appleIdPassword: process.env.APPLE_ID_PASSWORD,
teamId: process.env.APPLE_TEAM_ID
},
windowsSign: windowsSignConfiguration,
2025-01-09 18:07:02 +02:00
extraResource: [
// All resources should stay in Resources directory for macOS
2025-04-26 01:09:28 +03:00
...(process.platform === "darwin" ? [] : extraResourcesForPlatform)
2025-01-09 18:07:02 +02:00
],
ignore(copyPath) {
// Known files that will not be ignored and not logged.
if (copyPath.startsWith("/assets") || copyPath.startsWith("/public")) {
return false;
}
// Keep only the prebuild, source code and package index.
if (copyPath.startsWith("/node_modules/better-sqlite3")) {
if (!copyPath.startsWith("/node_modules/better-sqlite3/build")
&& copyPath !== "/node_modules/better-sqlite3/package.json"
&& !copyPath.startsWith("/node_modules/better-sqlite3/lib")) {
return true;
}
}
// console.log("[FORGE] ASAR: ", copyPath);
return false;
},
afterPrune: [
(buildPath, _electronVersion, _platform, _arch, callback) => {
// buildPath is a temporary directory that electron-packager creates - it's in the form of
// /tmp/electron-packager/tmp-SjJl0s/resources/app
try {
const cleanupNodeModulesScript = path.join(buildPath, "build", "node_modules", "@triliumnext/server", "scripts", "cleanupNodeModules.ts");
// we don't have access to any devDeps like 'tsx' here, so use the built-in '--experimental-strip-types' flag instead
const command = `node --experimental-strip-types ${cleanupNodeModulesScript} "${buildPath}" --skip-prune-dev-deps`;
// execSync throws, if above returns any non-zero exit code
// TODO: Not working.
// execSync(command);
callback()
} catch(err) {
callback(err)
}
}
],
2025-01-09 18:07:02 +02:00
afterComplete: [
(buildPath, _electronVersion, platform, _arch, callback) => {
// Only move resources on non-macOS platforms
if (platform !== "darwin") {
for (const resource of extraResourcesForPlatform) {
const baseName = path.basename(resource);
const sourcePath = path.join(buildPath, "resources", baseName);
// prettier-ignore
const destPath = (baseName !== "256x256.png")
? path.join(buildPath, baseName)
: path.join(buildPath, "icon.png");
2024-08-05 18:47:57 +02:00
fs.move(sourcePath, destPath)
.then(() => callback())
.catch((err) => callback(err));
}
} else {
callback();
2025-01-09 18:07:02 +02:00
}
}
]
2024-08-05 18:47:57 +02:00
},
2025-01-09 18:07:02 +02:00
rebuildConfig: {
force: false
2024-08-05 18:47:57 +02:00
},
2025-01-09 18:07:02 +02:00
makers: [
{
name: "@electron-forge/maker-deb",
config: {
options: {
...baseLinuxMakerConfigOptions
2025-01-09 18:07:02 +02:00
}
}
},
2025-02-03 23:21:27 +01:00
{
name: "@electron-forge/maker-flatpak",
config: {
options: {
...baseLinuxMakerConfigOptions,
2025-02-07 18:17:06 +02:00
id: "com.triliumnext.notes",
runtimeVersion: "24.08",
base: "org.electronjs.Electron2.BaseApp",
baseVersion: "24.08",
baseFlatpakref: "https://flathub.org/repo/flathub.flatpakrepo",
modules: [
{
name: "zypak",
sources: {
type: "git",
url: "https://github.com/refi64/zypak",
tag: "v2024.01.17"
}
}
]
2025-02-03 23:21:27 +01:00
},
}
},
2025-02-02 23:00:22 +01:00
{
name: "@electron-forge/maker-rpm",
config: {
options: {
...baseLinuxMakerConfigOptions
2025-02-02 23:00:22 +01:00
}
}
},
2025-01-09 18:07:02 +02:00
{
name: "@electron-forge/maker-squirrel",
config: {
name: EXECUTABLE_NAME,
productName: PRODUCT_NAME,
2025-01-09 18:07:02 +02:00
iconUrl: "https://raw.githubusercontent.com/TriliumNext/Notes/develop/images/app-icons/icon.ico",
2025-04-26 01:09:28 +03:00
setupIcon: path.join(ELECTRON_FORGE_DIR, "setup-icon/setup.ico"),
loadingGif: path.join(ELECTRON_FORGE_DIR, "setup-icon/setup-banner.gif"),
windowsSign: windowsSignConfiguration
2025-01-09 18:07:02 +02:00
}
},
{
name: "@electron-forge/maker-dmg",
config: {
2025-04-26 09:56:23 +03:00
icon: path.join(APP_ICON_PATH, "icon.icns")
2025-01-09 18:07:02 +02:00
}
},
{
name: "@electron-forge/maker-zip",
config: {
options: {
iconUrl: "https://raw.githubusercontent.com/TriliumNext/Notes/develop/images/app-icons/icon.ico",
2025-04-26 09:56:23 +03:00
icon: path.join(APP_ICON_PATH, "icon.ico")
2025-01-09 18:07:02 +02:00
}
}
2024-08-05 18:47:57 +02:00
}
2025-01-09 18:07:02 +02:00
],
plugins: [
{
name: "@electron-forge/plugin-auto-unpack-natives",
config: {}
}
],
hooks: {
postMake(_, makeResults) {
const outputDir = path.join(__dirname, "..", "upload");
2025-03-30 17:34:45 +03:00
fs.mkdirpSync(outputDir);
for (const makeResult of makeResults) {
for (const artifactPath of makeResult.artifacts) {
2025-03-24 19:04:38 +02:00
// Ignore certain artifacts.
2025-03-24 19:10:29 +02:00
let fileName = path.basename(artifactPath);
const extension = path.extname(fileName);
if (fileName === "RELEASES" || extension === ".nupkg") {
2025-03-24 19:04:38 +02:00
continue;
}
2025-03-24 19:10:29 +02:00
// Override the extension for the CI.
const { TRILIUM_ARTIFACT_NAME_HINT } = process.env;
if (TRILIUM_ARTIFACT_NAME_HINT) {
fileName = TRILIUM_ARTIFACT_NAME_HINT.replaceAll("/", "-") + extension;
2025-03-24 19:10:29 +02:00
}
2025-03-24 19:04:38 +02:00
const outputPath = path.join(outputDir, fileName);
console.log(`[Artifact] ${artifactPath} -> ${outputPath}`);
2025-03-30 17:34:45 +03:00
fs.copyFileSync(artifactPath, outputPath);
}
}
}
}
};
2024-08-05 18:47:57 +02:00
function getExtraResourcesForPlatform() {
const resources = [];
2025-04-26 11:58:35 +03:00
const getScriptResources = () => {
const scripts = ["trilium-portable", "trilium-safe-mode", "trilium-no-cert-check"];
const scriptExt = (process.platform === "win32") ? "bat" : "sh";
2025-04-25 18:44:03 +03:00
return scripts.map(script => `apps/desktop/electron-forge/${script}.${scriptExt}`);
}
2025-01-09 18:07:02 +02:00
switch (process.platform) {
case "win32":
2025-04-26 11:58:35 +03:00
resources.push(...getScriptResources())
2025-01-09 18:07:02 +02:00
break;
case "linux":
2025-04-26 11:58:35 +03:00
resources.push(...getScriptResources(), path.join(APP_ICON_PATH, "png/256x256.png"));
2025-01-09 18:07:02 +02:00
break;
default:
break;
}
2024-08-05 18:47:57 +02:00
2025-01-09 18:07:02 +02:00
return resources;
}