2025-01-09 18:07:02 +02:00
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs-extra");
|
2025-03-25 09:02:03 +01:00
|
|
|
const { execSync } = require("child_process");
|
2024-08-05 18:47:57 +02:00
|
|
|
|
2025-02-24 00:44:50 +00:00
|
|
|
const APP_NAME = "TriliumNext Notes";
|
2025-03-24 08:59:46 +02:00
|
|
|
const BIN_PATH = path.normalize("./bin/electron-forge");
|
2024-08-11 06:57:34 +03:00
|
|
|
|
2025-02-05 09:33:33 +01:00
|
|
|
const extraResourcesForPlatform = getExtraResourcesForPlatform();
|
2025-02-05 09:30:55 +01:00
|
|
|
const baseLinuxMakerConfigOptions = {
|
|
|
|
icon: "./images/app-icons/png/128x128.png",
|
2025-03-24 09:00:30 +02:00
|
|
|
desktopTemplate: path.resolve(path.join(BIN_PATH, "desktop.ejs")),
|
2025-02-07 08:57:20 +01:00
|
|
|
categories: ["Office", "Utility"]
|
2025-02-05 09:30:55 +01:00
|
|
|
};
|
2025-03-24 17:53:04 +02:00
|
|
|
const windowsSignConfiguration = process.env.WINDOWS_SIGN_EXECUTABLE ? {
|
2025-03-24 17:04:22 +02:00
|
|
|
hookModulePath: path.join(BIN_PATH, "sign-windows.cjs")
|
2025-03-24 17:53:04 +02:00
|
|
|
} : undefined;
|
2025-02-05 09:30:55 +01:00
|
|
|
|
2023-11-08 21:27:48 +02:00
|
|
|
module.exports = {
|
2025-03-13 08:09:53 +01:00
|
|
|
// we run electron-forge inside the ./build folder,
|
|
|
|
// to have it output to ./dist, we need to go up a directory first
|
|
|
|
outDir: "../dist",
|
2025-01-09 18:07:02 +02:00
|
|
|
packagerConfig: {
|
|
|
|
executableName: "trilium",
|
|
|
|
name: APP_NAME,
|
|
|
|
overwrite: true,
|
|
|
|
asar: true,
|
|
|
|
icon: "./images/app-icons/icon",
|
2025-02-22 22:43:09 +00:00
|
|
|
osxSign: {},
|
|
|
|
osxNotarize: {
|
|
|
|
appleId: process.env.APPLE_ID,
|
|
|
|
appleIdPassword: process.env.APPLE_ID_PASSWORD,
|
|
|
|
teamId: process.env.APPLE_TEAM_ID
|
|
|
|
},
|
2025-03-24 17:04:22 +02:00
|
|
|
windowsSign: windowsSignConfiguration,
|
2025-01-09 18:07:02 +02:00
|
|
|
extraResource: [
|
2025-02-22 22:43:09 +00:00
|
|
|
// All resources should stay in Resources directory for macOS
|
|
|
|
...(process.platform === "darwin" ? [] : extraResourcesForPlatform),
|
2024-10-13 14:24:46 +03:00
|
|
|
|
2025-02-22 22:43:09 +00:00
|
|
|
// These always go in Resources
|
2025-01-09 18:07:02 +02:00
|
|
|
"translations/",
|
|
|
|
"node_modules/@highlightjs/cdn-assets/styles"
|
|
|
|
],
|
2025-03-25 09:02:03 +01:00
|
|
|
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, "bin", "cleanupNodeModules.ts");
|
|
|
|
// we don't have access to any devDeps like 'tsx' here, so use the built-in '--experimental-strip-types' flag instead
|
2025-03-27 09:35:48 +01:00
|
|
|
const command = `node --experimental-strip-types ${cleanupNodeModulesScript} "${buildPath}" --skip-prune-dev-deps`;
|
2025-03-25 09:02:03 +01:00
|
|
|
// execSync throws, if above returns any non-zero exit code
|
|
|
|
execSync(command);
|
|
|
|
callback()
|
|
|
|
} catch(err) {
|
|
|
|
callback(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2025-01-09 18:07:02 +02:00
|
|
|
afterComplete: [
|
|
|
|
(buildPath, _electronVersion, platform, _arch, callback) => {
|
2025-02-22 22:43:09 +00:00
|
|
|
// 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);
|
2025-02-24 16:12:53 +00:00
|
|
|
|
|
|
|
// prettier-ignore
|
2025-02-22 22:43:09 +00:00
|
|
|
const destPath = (baseName !== "256x256.png")
|
|
|
|
? path.join(buildPath, baseName)
|
|
|
|
: path.join(buildPath, "icon.png");
|
2024-08-05 18:47:57 +02:00
|
|
|
|
2025-02-22 22:43:09 +00: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: true
|
2024-08-05 18:47:57 +02:00
|
|
|
},
|
2025-01-09 18:07:02 +02:00
|
|
|
makers: [
|
|
|
|
{
|
|
|
|
name: "@electron-forge/maker-deb",
|
|
|
|
config: {
|
|
|
|
options: {
|
2025-02-05 09:30:55 +01:00
|
|
|
...baseLinuxMakerConfigOptions
|
2025-01-09 18:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2025-02-03 23:21:27 +01:00
|
|
|
{
|
|
|
|
name: "@electron-forge/maker-flatpak",
|
|
|
|
config: {
|
|
|
|
options: {
|
2025-02-07 08:52:55 +01:00
|
|
|
...baseLinuxMakerConfigOptions,
|
2025-02-07 18:17:06 +02:00
|
|
|
id: "com.triliumnext.notes",
|
2025-02-05 08:32:59 +01:00
|
|
|
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: {
|
2025-02-05 09:30:55 +01:00
|
|
|
...baseLinuxMakerConfigOptions
|
2025-02-02 23:00:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2025-01-09 18:07:02 +02:00
|
|
|
{
|
|
|
|
name: "@electron-forge/maker-squirrel",
|
|
|
|
config: {
|
|
|
|
iconUrl: "https://raw.githubusercontent.com/TriliumNext/Notes/develop/images/app-icons/icon.ico",
|
2025-02-01 14:36:55 +02:00
|
|
|
setupIcon: "./images/app-icons/win/setup.ico",
|
2025-03-24 11:21:31 +02:00
|
|
|
loadingGif: "./images/app-icons/win/setup-banner.gif",
|
2025-03-24 17:04:22 +02:00
|
|
|
windowsSign: windowsSignConfiguration
|
2025-01-09 18:07:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "@electron-forge/maker-dmg",
|
|
|
|
config: {
|
|
|
|
icon: "./images/app-icons/icon.icns"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "@electron-forge/maker-zip",
|
|
|
|
config: {
|
|
|
|
options: {
|
|
|
|
iconUrl: "https://raw.githubusercontent.com/TriliumNext/Notes/develop/images/app-icons/icon.ico",
|
|
|
|
icon: "./images/app-icons/icon.ico"
|
|
|
|
}
|
|
|
|
}
|
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: {}
|
|
|
|
}
|
2025-03-23 23:06:41 +02:00
|
|
|
],
|
|
|
|
hooks: {
|
|
|
|
postMake(_, makeResults) {
|
2025-03-23 23:08:02 +02:00
|
|
|
const outputDir = path.join(__dirname, "..", "upload");
|
2025-03-30 17:34:45 +03:00
|
|
|
fs.mkdirpSync(outputDir);
|
2025-03-23 23:06:41 +02:00
|
|
|
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) {
|
2025-03-30 16:44:46 +03:00
|
|
|
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);
|
2025-03-23 23:06:41 +02:00
|
|
|
console.log(`[Artifact] ${artifactPath} -> ${outputPath}`);
|
2025-03-30 17:34:45 +03:00
|
|
|
fs.copyFileSync(artifactPath, outputPath);
|
2025-03-23 23:06:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-08 21:27:48 +02:00
|
|
|
};
|
2024-08-05 18:47:57 +02:00
|
|
|
|
|
|
|
function getExtraResourcesForPlatform() {
|
2025-03-11 22:23:59 +01:00
|
|
|
const resources = [];
|
2025-02-05 09:56:08 +01:00
|
|
|
|
|
|
|
const getScriptRessources = () => {
|
|
|
|
const scripts = ["trilium-portable", "trilium-safe-mode", "trilium-no-cert-check"];
|
|
|
|
const scriptExt = (process.platform === "win32") ? "bat" : "sh";
|
2025-04-19 00:20:18 +03:00
|
|
|
return scripts.map(script => `./tpl/${script}.${scriptExt}`);
|
2025-02-05 09:56:08 +01:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
switch (process.platform) {
|
|
|
|
case "win32":
|
2025-02-05 09:56:08 +01:00
|
|
|
resources.push(...getScriptRessources())
|
2025-01-09 18:07:02 +02:00
|
|
|
break;
|
|
|
|
case "linux":
|
2025-02-05 09:56:08 +01:00
|
|
|
resources.push(...getScriptRessources(), "images/app-icons/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;
|
|
|
|
}
|