mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	chore(dx/edit-docs): de-nxify
This commit is contained in:
		| @@ -30,14 +30,13 @@ | ||||
|     "prebuild-install": "^7.1.1" | ||||
|   },   | ||||
|   "scripts": { | ||||
|     "dev": "cross-env TRILIUM_PORT=37741 TRILIUM_DATA_DIR=data tsx scripts/start.mts", | ||||
|     "start-no-dir": "cross-env TRILIUM_PORT=37743 tsx scripts/start.mts", | ||||
|     "dev": "cross-env TRILIUM_PORT=37741 TRILIUM_DATA_DIR=data tsx ../../scripts/electron-start.mts src/main.ts", | ||||
|     "start-no-dir": "cross-env TRILIUM_PORT=37743 tsx ../../scripts/electron-start.mts src/main.ts", | ||||
|     "build": "tsx scripts/build.ts", | ||||
|     "start-prod": "pnpm build && cross-env TRILIUM_DATA_DIR=data TRILIUM_PORT=37841 electron dist", | ||||
|     "electron-forge:make": "pnpm build && cross-env electron-forge make dist", | ||||
|     "electron-forge:package": "pnpm build && electron-forge package dist", | ||||
|     "electron-forge:start": "pnpm build && electron-forge start dist", | ||||
|     "postinstall": "tsx scripts/rebuild.mts" | ||||
|     "electron-forge:start": "pnpm build && electron-forge start dist" | ||||
|   }, | ||||
|   "license": "AGPL-3.0-only", | ||||
|   "author": { | ||||
|   | ||||
| @@ -15,120 +15,8 @@ | ||||
|     "electron": "37.4.0", | ||||
|     "fs-extra": "11.3.1" | ||||
|   }, | ||||
|   "nx": { | ||||
|     "name": "edit-docs", | ||||
|     "implicitDependencies": [ | ||||
|       "server" | ||||
|     ], | ||||
|     "targets": { | ||||
|       "build": { | ||||
|         "executor": "@nx/esbuild:esbuild", | ||||
|         "outputs": [ | ||||
|           "{options.outputPath}" | ||||
|         ], | ||||
|         "options": { | ||||
|           "main": "apps/edit-docs/src/edit-docs.ts", | ||||
|           "outputPath": "apps/edit-docs/dist", | ||||
|           "tsConfig": "apps/edit-docs/tsconfig.app.json", | ||||
|           "platform": "node", | ||||
|           "additionalEntryPoints": [ | ||||
|             "apps/edit-docs/src/edit-demo.ts" | ||||
|           ], | ||||
|           "external": [ | ||||
|             "electron", | ||||
|             "@electron/remote", | ||||
|             "better-sqlite3", | ||||
|             "./xhr-sync-worker.js" | ||||
|           ], | ||||
|           "format": [ | ||||
|             "cjs" | ||||
|           ], | ||||
|           "minify": false, | ||||
|           "thirdParty": true, | ||||
|           "declaration": false, | ||||
|           "esbuildOptions": { | ||||
|             "splitting": false, | ||||
|             "loader": { | ||||
|               ".css": "text" | ||||
|             } | ||||
|           }, | ||||
|           "assets": [ | ||||
|             { | ||||
|               "glob": "**/*", | ||||
|               "input": "apps/server/dist/node_modules", | ||||
|               "output": "node_modules" | ||||
|             }, | ||||
|             { | ||||
|               "glob": "**/*", | ||||
|               "input": "apps/server/dist/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/edit-docs/src" | ||||
|         } | ||||
|       }, | ||||
|       "rebuild-deps": { | ||||
|         "executor": "nx:run-commands", | ||||
|         "dependsOn": [ | ||||
|           "build" | ||||
|         ], | ||||
|         "defaultConfiguration": "default", | ||||
|         "cache": true, | ||||
|         "configurations": { | ||||
|           "default": { | ||||
|             "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist" | ||||
|           }, | ||||
|           "nixos": { | ||||
|             "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist $(nix-shell -p electron_35 --run \"electron --version\")" | ||||
|           } | ||||
|         } | ||||
|       }, | ||||
|       "edit-docs": { | ||||
|         "executor": "nx:run-commands", | ||||
|         "dependsOn": [ | ||||
|           "rebuild-deps" | ||||
|         ], | ||||
|         "defaultConfiguration": "default", | ||||
|         "configurations": { | ||||
|           "default": { | ||||
|             "command": "electron edit-docs.cjs", | ||||
|             "cwd": "{projectRoot}/dist" | ||||
|           }, | ||||
|           "nixos": { | ||||
|             "command": "nix-shell -p electron_35 --run \"electron {projectRoot}/dist/edit-docs.cjs\"", | ||||
|             "cwd": ".", | ||||
|             "forwardAllArgs": false | ||||
|           } | ||||
|         } | ||||
|       }, | ||||
|       "edit-demo": { | ||||
|         "executor": "nx:run-commands", | ||||
|         "dependsOn": [ | ||||
|           "rebuild-deps" | ||||
|         ], | ||||
|         "defaultConfiguration": "default", | ||||
|         "configurations": { | ||||
|           "default": { | ||||
|             "command": "electron edit-demo.cjs", | ||||
|             "cwd": "{projectRoot}/dist" | ||||
|           }, | ||||
|           "nixos": { | ||||
|             "command": "nix-shell -p electron_35 --run \"electron {projectRoot}/dist/edit-demo.cjs\"", | ||||
|             "cwd": ".", | ||||
|             "forwardAllArgs": false | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   }   | ||||
|   "scripts": { | ||||
|     "edit-docs": "cross-env TRILIUM_PORT=37741 TRILIUM_DATA_DIR=data TRILIUM_INTEGRATION_TEST=memory-no-store DOCS_ROOT=../../../docs USER_GUIDE_ROOT=\"../../server/src/assets/doc_notes/en/User Guide\" tsx ../../scripts/electron-start.mts src/edit-docs.ts", | ||||
|     "edit-demo": "cross-env TRILIUM_PORT=37741 TRILIUM_DATA_DIR=data TRILIUM_INTEGRATION_TEST=memory-no-store DOCS_ROOT=../../../docs USER_GUIDE_ROOT=\"../../server/src/assets/doc_notes/en/User Guide\" tsx ../../scripts/electron-start.mts src/edit-demo.ts" | ||||
|   } | ||||
| } | ||||
| @@ -26,7 +26,8 @@ | ||||
|     "chore:update-version": "tsx ./scripts/update-version.ts", | ||||
|     "test:all": "pnpm test:parallel && pnpm test:sequential", | ||||
|     "test:parallel": "pnpm --filter=!server --filter=!ckeditor5-mermaid --filter=!ckeditor5-math --parallel test", | ||||
|     "test:sequential": "pnpm --filter=server --filter=ckeditor5-mermaid --filter=ckeditor5-math --sequential test" | ||||
|     "test:sequential": "pnpm --filter=server --filter=ckeditor5-mermaid --filter=ckeditor5-math --sequential test", | ||||
|     "postinstall": "tsx scripts/electron-rebuild.mts" | ||||
|   }, | ||||
|   "private": true, | ||||
|   "devDependencies": { | ||||
|   | ||||
| @@ -1,15 +1,13 @@ | ||||
| import { join } from "path"; | ||||
| import { cpSync, existsSync, mkdirSync, rmSync } from "fs"; | ||||
| import { join, resolve } from "path"; | ||||
| import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "fs"; | ||||
| import { execSync } from "child_process"; | ||||
| import { rebuild } from "@electron/rebuild" | ||||
| import { getElectronPath, isNixOS } from "../../../scripts/utils.mjs"; | ||||
| import packageJson from "../package.json" with { type: "json" }; | ||||
| import { getElectronPath, isNixOS } from "./utils.mjs"; | ||||
| 
 | ||||
| const desktopProjectRoot = join(import.meta.dirname, ".."); | ||||
| const workspaceRoot = join(desktopProjectRoot, "../.."); | ||||
| const workspaceRoot = join(import.meta.dirname, ".."); | ||||
| 
 | ||||
| function copyNativeDependencies() { | ||||
|     const destPath = join(desktopProjectRoot, "node_modules/better-sqlite3"); | ||||
| function copyNativeDependencies(projectRoot: string) { | ||||
|     const destPath = join(projectRoot, "node_modules/better-sqlite3"); | ||||
|      | ||||
|     if (existsSync(destPath)) { | ||||
|         rmSync(destPath, { recursive: true }); | ||||
| @@ -18,24 +16,28 @@ function copyNativeDependencies() { | ||||
|     cpSync(join(workspaceRoot, "node_modules/better-sqlite3"), destPath, { recursive: true, dereference: true }); | ||||
| } | ||||
| 
 | ||||
| function rebuildNativeDependencies() { | ||||
|     const electronVersion = determineElectronVersion(); | ||||
| function rebuildNativeDependencies(projectRoot: string) { | ||||
|     const electronVersion = determineElectronVersion(projectRoot); | ||||
| 
 | ||||
|     if (!electronVersion) { | ||||
|         console.error("Unable to determine Electron version."); | ||||
|         process.exit(1); | ||||
|     } | ||||
| 
 | ||||
|     console.log(`Rebuilding ${desktopProjectRoot} with ${electronVersion}...`); | ||||
|     console.log(`Rebuilding ${projectRoot} with ${electronVersion}...`); | ||||
| 
 | ||||
|     const resolvedPath = resolve(projectRoot); | ||||
|     rebuild({ | ||||
|         projectRootPath: desktopProjectRoot, | ||||
|         buildPath: desktopProjectRoot, | ||||
|         electronVersion | ||||
|         projectRootPath: resolvedPath, | ||||
|         buildPath: resolvedPath, | ||||
|         electronVersion, | ||||
|         force: true | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| function determineElectronVersion() { | ||||
| function determineElectronVersion(projectRoot: string) { | ||||
|     const packageJson = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf-8")); | ||||
| 
 | ||||
|     if (isNixOS()) { | ||||
|         console.log("Detected NixOS, reading Electron version from PATH"); | ||||
| 
 | ||||
| @@ -51,5 +53,7 @@ function determineElectronVersion() { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| copyNativeDependencies(); | ||||
| rebuildNativeDependencies(); | ||||
| for (const projectRoot of [ "apps/desktop", "apps/edit-docs" ]) { | ||||
|     copyNativeDependencies(projectRoot); | ||||
|     rebuildNativeDependencies(projectRoot); | ||||
| } | ||||
| @@ -1,20 +1,17 @@ | ||||
| import { execSync } from "child_process"; | ||||
| import { getElectronPath, isNixOS } from "../../../scripts/utils.mjs"; | ||||
| import { join } from "path"; | ||||
| import { getElectronPath, isNixOS } from "./utils.mjs"; | ||||
| 
 | ||||
| const projectRoot = join(import.meta.dirname, ".."); | ||||
| const LD_LIBRARY_PATH = isNixOS() && execSync("nix eval --raw nixpkgs#gcc.cc.lib").toString("utf-8") + "/lib"; | ||||
| 
 | ||||
| execSync(`${getElectronPath()} ./src/main.ts`, { | ||||
| execSync(`${getElectronPath()} ${process.argv[2]}`, { | ||||
|     stdio: "inherit", | ||||
|     cwd: projectRoot, | ||||
|     env: { | ||||
|         ...process.env, | ||||
|         NODE_OPTIONS: "--import tsx", | ||||
|         NODE_ENV: "development", | ||||
|         TRILIUM_ENV: "dev", | ||||
|         TRILIUM_RESOURCE_DIR: "../server/src", | ||||
|         BETTERSQLITE3_NATIVE_PATH: join(projectRoot, "node_modules/better-sqlite3/build/Release/better_sqlite3.node"), | ||||
|         BETTERSQLITE3_NATIVE_PATH: "node_modules/better-sqlite3/build/Release/better_sqlite3.node", | ||||
|         LD_LIBRARY_PATH | ||||
|     } | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user