Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(dx/server): extract basic build commands to separate file
Elian Doran1e991c052603
diff --git a/apps/server/scripts/build.ts b/apps/server/scripts/build.tsindex 29147ec5b4..b029697225 100644--- a/apps/server/scripts/build.ts+++ b/apps/server/scripts/build.ts@@ -1,12 +1,13 @@import * as esbuild from "esbuild";import { join } from "path";-import * as fs from "fs-extra";import * as child_process from "child_process";+import BuildHelper from "../../../scripts/build-utils";const projectDir = __dirname + "/..";const outDir = join(projectDir, "dist");+const build = new BuildHelper("apps/server");-async function build() {+async function runBuild() {esbuild.build({entryPoints: [join(projectDir, "src/main.ts"),@@ -41,18 +42,18 @@ async function build() {function copyAssets() {// Copy server assets- copy("src/assets", "assets/");+ build.copy("src/assets", "assets/");// Copy node modulesfor (const module of [ "better-sqlite3", "bindings", "file-uri-to-path" ]) {- copy(`node_modules/${module}`, `node_modules/${module}/`);+ build.copy(`node_modules/${module}`, `node_modules/${module}/`);}// Copy sync worker.- copy("node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js", "xhr-sync-worker.js");+ build.copy("node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js", "xhr-sync-worker.js");// Copy share templates.- copy("../../packages/share-theme/src/templates", "share-theme/templates/");+ build.copy("../../packages/share-theme/src/templates", "share-theme/templates/");}function buildAndCopyClient() {@@ -60,26 +61,14 @@ function buildAndCopyClient() {child_process.execSync("pnpm build", { cwd: join(projectDir, "../client"), stdio: "inherit" });// Copy the artifacts.- copy("../client/dist", "public/");+ build.copy("../client/dist", "public/");// Remove unnecessary files.- deleteFromOutput("public/webpack-stats.json");-}--function copy(projectDirPath: string, outDirPath: string) {- if (outDirPath.endsWith("/")) {- fs.mkdirpSync(join(outDirPath));- }- fs.copySync(join(projectDir, projectDirPath), join(outDir, outDirPath), { dereference: true });-}--function deleteFromOutput(path: string) {- fs.rmSync(join(outDir, path), { recursive: true });+ build.deleteFromOutput("public/webpack-stats.json");}async function main() {- fs.emptyDirSync(outDir);- await build();+ await runBuild();copyAssets();buildAndCopyClient();}diff --git a/scripts/build-utils.ts b/scripts/build-utils.tsnew file mode 100644index 0000000000..27790488b7--- /dev/null+++ b/scripts/build-utils.ts@@ -0,0 +1,28 @@+import { rmSync } from "fs";+import { copySync, emptyDirSync, mkdirpSync } from "fs-extra";+import { join } from "path";++export default class BuildHelper {++ private projectDir: string;+ private outDir: string;++ constructor(projectPath: string) {+ this.projectDir = join(__dirname, "..", projectPath);+ this.outDir = join(this.projectDir, "dist");++ emptyDirSync(this.outDir);+ }++ copy(projectDirPath: string, outDirPath: string) {+ if (outDirPath.endsWith("/")) {+ mkdirpSync(join(outDirPath));+ }+ copySync(join(this.projectDir, projectDirPath), join(this.outDir, outDirPath), { dereference: true });+ }++ deleteFromOutput(path: string) {+ rmSync(join(this.outDir, path), { recursive: true });+ }++}