From 0e5108bd08a77870398f7b084b0888fce96f31f5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 31 Aug 2025 22:30:07 +0300 Subject: [PATCH] chore(dx/server): start building & copying assets --- apps/server/package.json | 48 ++------------------------------ apps/server/scripts/build.ts | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 46 deletions(-) create mode 100644 apps/server/scripts/build.ts diff --git a/apps/server/package.json b/apps/server/package.json index 93fa686b0..347c8595a 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -284,38 +284,13 @@ } }, "options": { - "main": "apps/server/src/main.ts", - "outputPath": "apps/server/dist", - "tsConfig": "apps/server/tsconfig.app.json", - "platform": "node", - "external": [ - "electron", - "@electron/remote", - "better-sqlite3", - "./xhr-sync-worker.js" - ], - "format": [ - "cjs" - ], "declarationRootDir": "apps/server/src", "thirdParty": true, "declaration": false, - "esbuildOptions": { - "splitting": false, - "loader": { - ".css": "text", - ".ejs": "text" - } - }, "additionalEntryPoints": [ "apps/server/src/docker_healthcheck.ts" ], "assets": [ - { - "glob": "**/*", - "input": "apps/server/src/assets", - "output": "assets" - }, { "glob": "**/*", "input": "packages/share-theme/src/templates", @@ -328,26 +303,6 @@ "ignore": [ "webpack-stats.json" ] - }, - { - "glob": "**/*", - "input": "apps/server/node_modules/better-sqlite3", - "output": "node_modules/better-sqlite3" - }, - { - "glob": "**/*", - "input": "apps/server/node_modules/bindings", - "output": "node_modules/bindings" - }, - { - "glob": "**/*", - "input": "apps/server/node_modules/file-uri-to-path", - "output": "node_modules/file-uri-to-path" - }, - { - "glob": "xhr-sync-worker.js", - "input": "apps/server/node_modules/jsdom/lib/jsdom/living/xhr", - "output": "" } ] } @@ -364,7 +319,8 @@ } }, "scripts": { - "dev": "cross-env TRILIUM_ENV=dev TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=src tsx watch --ignore '../client/node_modules/.vite-temp' ./src/main.ts" + "dev": "cross-env TRILIUM_ENV=dev TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=src tsx watch --ignore '../client/node_modules/.vite-temp' ./src/main.ts", + "build": "tsx scripts/build.ts" }, "main": "./src/main.ts" } \ No newline at end of file diff --git a/apps/server/scripts/build.ts b/apps/server/scripts/build.ts new file mode 100644 index 000000000..225333bb0 --- /dev/null +++ b/apps/server/scripts/build.ts @@ -0,0 +1,53 @@ +import * as esbuild from "esbuild"; +import { join } from "path"; +import * as fs from "fs-extra"; + +const projectDir = __dirname + "/.."; +const outDir = join(projectDir, "dist"); + +async function build() { + esbuild.build({ + entryPoints: [ join(projectDir, "src/main.ts") ], + tsconfig: join(projectDir, "tsconfig.app.json"), + platform: "node", + bundle: true, + outdir: outDir, + format: "cjs", + external: [ + "electron", + "@electron/remote", + "better-sqlite3", + "./xhr-sync-worker.js", + "@preact/preset-vite", + "vite" + ], + splitting: false, + loader: { + ".css": "text", + ".ejs": "text" + } + }); +} + +function copyAssets() { + // Copy server assets + fs.copySync(join(projectDir, "src/assets"), join(outDir, "assets")); + + // Copy node modules + fs.mkdir(join(outDir, "node_modules")); + for (const module of [ "better-sqlite3", "bindings", "file-uri-to-path" ]) { + fs.copySync(join(projectDir, "node_modules", module), join(outDir, "node_modules", module), { dereference: true }); + } + + // Copy sync worker. + fs.copySync(join(projectDir, "node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js"), join(outDir, "xhr-sync-worker.js")); +} + +async function main() { + fs.rmSync(outDir, { recursive: true }); + fs.mkdirSync(outDir); + await build(); + copyAssets(); +} + +main();