Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 248f6d6

Browse files
committed
refactor(forge): switch to TypeScript
1 parent 0744a85 commit 248f6d6

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
paths:
1313
- .github/actions/build-electron/*
1414
- .github/workflows/nightly.yml
15-
- forge.config.cjs
15+
- forge.config.ts
1616

1717
concurrency:
1818
group: ${{ github.workflow }}-${{ github.ref }}

apps/desktop/electron-forge/forge.config.cjs renamed to apps/desktop/electron-forge/forge.config.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const path = require("path");
2-
const fs = require("fs-extra");
3-
const { LOCALES } = require("@triliumnext/commons");
1+
import path from "path";
2+
import fs from "fs-extra";
3+
import { LOCALES } from "@triliumnext/commons";
4+
import { PRODUCT_NAME } from "../src/app-info.js";
45

56
const ELECTRON_FORGE_DIR = __dirname;
67

78
const EXECUTABLE_NAME = "trilium"; // keep in sync with server's package.json -> packagerConfig.executableName
8-
const { PRODUCT_NAME } = require("../src/app-info.js");
99
const APP_ICON_PATH = path.join(ELECTRON_FORGE_DIR, "app-icon");
1010

1111
const extraResourcesForPlatform = getExtraResourcesForPlatform();
@@ -147,13 +147,13 @@ module.exports = {
147147
const isMac = (process.platform === "darwin");
148148
let localesToKeep = LOCALES
149149
.filter(locale => !locale.contentOnly)
150-
.map(locale => locale.electronLocale);
150+
.map(locale => locale.electronLocale) as string[];
151151
if (!isMac) {
152152
localesToKeep = localesToKeep.map(locale => locale.replace("_", "-"))
153153
}
154154

155155
const keptLocales = new Set();
156-
const removedLocales = [];
156+
const removedLocales: string[] = [];
157157
const extension = (isMac ? ".lproj" : ".pak");
158158

159159
for (const outputPath of packageResult.outputPaths) {
@@ -169,39 +169,39 @@ module.exports = {
169169
console.log(`No locales directory found in '${localeDir}'.`);
170170
process.exit(2);
171171
}
172-
172+
173173
const files = fs.readdirSync(localeDir);
174-
174+
175175
for (const file of files) {
176176
if (!file.endsWith(extension)) {
177177
continue;
178178
}
179-
179+
180180
let localeName = path.basename(file, extension);
181181
if (localeName === "en-US" && !isMac) {
182182
// If the locale is "en-US" on Windows, we treat it as "en".
183183
// This is because the Windows version of Electron uses "en-US.pak" instead of "en.pak".
184184
localeName = "en";
185185
}
186-
186+
187187
if (localesToKeep.includes(localeName)) {
188188
keptLocales.add(localeName);
189189
continue;
190190
}
191-
191+
192192
const filePath = path.join(localeDir, file);
193193
if (isMac) {
194194
fs.rm(filePath, { recursive: true });
195195
} else {
196196
fs.unlinkSync(filePath);
197197
}
198-
198+
199199
removedLocales.push(file);
200200
}
201201
}
202202
}
203203

204-
console.log(`Removed unused locale files: ${removedLocales.join(", ")}`);
204+
console.log(`Removed unused locale files: ${removedLocales.join(", ")}`);
205205

206206
// Ensure all locales that should be kept are actually present.
207207
for (const locale of localesToKeep) {
@@ -229,7 +229,7 @@ module.exports = {
229229
if (TRILIUM_ARTIFACT_NAME_HINT) {
230230
fileName = TRILIUM_ARTIFACT_NAME_HINT.replaceAll("/", "-") + extension;
231231
}
232-
232+
233233
const outputPath = path.join(outputDir, fileName);
234234
console.log(`[Artifact] ${artifactPath} -> ${outputPath}`);
235235
fs.copyFileSync(artifactPath, outputPath);
@@ -240,7 +240,7 @@ module.exports = {
240240
};
241241

242242
function getExtraResourcesForPlatform() {
243-
const resources = [];
243+
const resources: string[] = [];
244244

245245
const getScriptResources = () => {
246246
const scripts = ["trilium-portable", "trilium-safe-mode", "trilium-no-cert-check"];

apps/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"prebuild-install": "^7.1.1"
3030
},
3131
"config": {
32-
"forge": "./electron-forge/forge.config.cjs"
32+
"forge": "./electron-forge/forge.config.ts"
3333
},
3434
"scripts": {
3535
"start-prod": "nx build desktop && cross-env TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=dist TRILIUM_PORT=37841 electron dist/main.js"

apps/desktop/tsconfig.forge.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "ESNext",
5+
"moduleResolution": "bundler",
6+
"target": "ES2020",
7+
"outDir": "dist",
8+
"types": [
9+
"node",
10+
"express"
11+
],
12+
"rootDir": "electron-forge",
13+
"tsBuildInfoFile": "dist/tsconfig.app.tsbuildinfo"
14+
},
15+
"include": [
16+
"**/*.ts"
17+
],
18+
"exclude": [
19+
"eslint.config.js",
20+
"eslint.config.cjs",
21+
"eslint.config.mjs"
22+
]
23+
}

apps/desktop/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
},
1212
{
1313
"path": "./tsconfig.app.json"
14+
},
15+
{
16+
"path": "./tsconfig.forge.json"
1417
}
1518
]
1619
}

flake.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@
169169
comment = meta.description;
170170
desktopName = "TriliumNext Notes";
171171
categories = [ "Office" ];
172-
# TODO: electron-forge build has this set to PRODUCT_NAME (forge.config.cjs)
173-
# But the plain build doesn't set this (or the app icon).
174172
startupWMClass = "TriliumNext Notes";
175173
})
176174
];

0 commit comments

Comments
 (0)