From 135e2bb10ef81f442c726581a2dacc52265027f5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 1 Sep 2025 20:50:22 +0300 Subject: [PATCH] chore(dx/desktop): get prod build --- apps/desktop/package.json | 44 +------------------ apps/desktop/scripts/build.ts | 22 ++++++++++ .../desktop/src/{electron-main.ts => main.ts} | 0 apps/server/scripts/build.ts | 4 +- scripts/build-utils.ts | 9 +++- 5 files changed, 33 insertions(+), 46 deletions(-) create mode 100644 apps/desktop/scripts/build.ts rename apps/desktop/src/{electron-main.ts => main.ts} (100%) diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 25d622b77..e5cbdf01b 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -33,6 +33,7 @@ }, "scripts": { "dev": "cross-env NODE_OPTIONS=\"--import tsx\" NODE_ENV=development TRILIUM_ENV=dev TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=../server/src electron src/electron-main.ts", + "build": "tsx scripts/build.ts", "start-prod": "nx build desktop && cross-env TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=dist TRILIUM_PORT=37841 electron dist/main.js" }, "license": "AGPL-3.0-only", @@ -63,63 +64,20 @@ "options": { "main": "apps/desktop/src/electron-main.ts", "outputPath": "apps/desktop/dist", - "outputFileName": "main.js", "tsConfig": "apps/desktop/tsconfig.app.json", - "platform": "node", "external": [ "electron", "@electron/remote", "better-sqlite3", "./xhr-sync-worker.js" ], - "format": [ - "cjs" - ], "thirdParty": true, - "declaration": false, "esbuildOptions": { "splitting": false, "loader": { ".css": "text" } }, - "assets": [ - { - "glob": "**/*", - "input": "apps/server/dist/node_modules", - "output": "node_modules" - }, - { - "glob": "**/*", - "input": "apps/desktop/node_modules/@electron/remote", - "output": "node_modules/@electron/remote" - }, - { - "glob": "**/*", - "input": "apps/server/dist/assets", - "output": "assets" - }, - { - "glob": "**/*", - "input": "packages/share-theme/src/templates", - "output": "share-theme/templates" - }, - { - "glob": "**/*", - "input": "apps/desktop/src/assets", - "output": "assets" - }, - { - "glob": "**/*", - "input": "apps/server/dist/public", - "output": "public" - }, - { - "glob": "xhr-sync-worker.js", - "input": "apps/server/node_modules/jsdom/lib/jsdom/living/xhr", - "output": "" - } - ], "declarationRootDir": "apps/desktop/src" } }, diff --git a/apps/desktop/scripts/build.ts b/apps/desktop/scripts/build.ts new file mode 100644 index 000000000..07e31f71a --- /dev/null +++ b/apps/desktop/scripts/build.ts @@ -0,0 +1,22 @@ +import BuildHelper from "../../../scripts/build-utils"; + +const build = new BuildHelper("apps/desktop"); + +async function main() { + await build.buildBackend([ "src/main.ts"]); + + // Copy assets. + build.copy("src/assets", "assets/"); + build.copy("/apps/server/src/assets", "assets/"); + build.copy("/packages/share-theme/src/templates", "share-theme/templates/"); + + // Copy node modules dependencies + build.copyNodeModules([ "better-sqlite3", "bindings", "file-uri-to-path", "@electron/remote" ]); + build.copy("/apps/server/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js", "xhr-sync-worker.js"); + + // Integrate the client. + build.triggerBuildAndCopyTo("apps/client", "public/"); + build.deleteFromOutput("public/webpack-stats.json"); +} + +main(); diff --git a/apps/desktop/src/electron-main.ts b/apps/desktop/src/main.ts similarity index 100% rename from apps/desktop/src/electron-main.ts rename to apps/desktop/src/main.ts diff --git a/apps/server/scripts/build.ts b/apps/server/scripts/build.ts index c4a17941d..5606644f5 100644 --- a/apps/server/scripts/build.ts +++ b/apps/server/scripts/build.ts @@ -3,11 +3,11 @@ import BuildHelper from "../../../scripts/build-utils"; const build = new BuildHelper("apps/server"); async function main() { - build.buildBackend([ "src/main.ts", "src/docker_healthcheck.ts" ]) + await build.buildBackend([ "src/main.ts", "src/docker_healthcheck.ts" ]) // Copy assets build.copy("src/assets", "assets/"); - build.copy("../../packages/share-theme/src/templates", "share-theme/templates/"); + build.copy("/packages/share-theme/src/templates", "share-theme/templates/"); // Copy node modules dependencies build.copyNodeModules([ "better-sqlite3", "bindings", "file-uri-to-path" ]); diff --git a/scripts/build-utils.ts b/scripts/build-utils.ts index 5857ffce4..e4706b03b 100644 --- a/scripts/build-utils.ts +++ b/scripts/build-utils.ts @@ -19,10 +19,17 @@ export default class BuildHelper { } copy(projectDirPath: string, outDirPath: string) { + let sourcePath: string; + if (projectDirPath.startsWith("/")) { + sourcePath = join(this.rootDir, projectDirPath.substring(1)); + } else { + sourcePath = join(this.projectDir, projectDirPath); + } + if (outDirPath.endsWith("/")) { mkdirpSync(join(outDirPath)); } - copySync(join(this.projectDir, projectDirPath), join(this.outDir, outDirPath), { dereference: true }); + copySync(sourcePath, join(this.outDir, outDirPath), { dereference: true }); } deleteFromOutput(path: string) {