mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
chore(dx/edit-docs): de-nxify
This commit is contained in:
parent
c75d2435fa
commit
11d95b89e1
@ -30,14 +30,13 @@
|
|||||||
"prebuild-install": "^7.1.1"
|
"prebuild-install": "^7.1.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cross-env TRILIUM_PORT=37741 TRILIUM_DATA_DIR=data 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/start.mts",
|
"start-no-dir": "cross-env TRILIUM_PORT=37743 tsx ../../scripts/electron-start.mts src/main.ts",
|
||||||
"build": "tsx scripts/build.ts",
|
"build": "tsx scripts/build.ts",
|
||||||
"start-prod": "pnpm build && cross-env TRILIUM_DATA_DIR=data TRILIUM_PORT=37841 electron dist",
|
"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:make": "pnpm build && cross-env electron-forge make dist",
|
||||||
"electron-forge:package": "pnpm build && electron-forge package dist",
|
"electron-forge:package": "pnpm build && electron-forge package dist",
|
||||||
"electron-forge:start": "pnpm build && electron-forge start dist",
|
"electron-forge:start": "pnpm build && electron-forge start dist"
|
||||||
"postinstall": "tsx scripts/rebuild.mts"
|
|
||||||
},
|
},
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"author": {
|
"author": {
|
||||||
|
@ -15,120 +15,8 @@
|
|||||||
"electron": "37.4.0",
|
"electron": "37.4.0",
|
||||||
"fs-extra": "11.3.1"
|
"fs-extra": "11.3.1"
|
||||||
},
|
},
|
||||||
"nx": {
|
"scripts": {
|
||||||
"name": "edit-docs",
|
"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",
|
||||||
"implicitDependencies": [
|
"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"
|
||||||
"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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -26,7 +26,8 @@
|
|||||||
"chore:update-version": "tsx ./scripts/update-version.ts",
|
"chore:update-version": "tsx ./scripts/update-version.ts",
|
||||||
"test:all": "pnpm test:parallel && pnpm test:sequential",
|
"test:all": "pnpm test:parallel && pnpm test:sequential",
|
||||||
"test:parallel": "pnpm --filter=!server --filter=!ckeditor5-mermaid --filter=!ckeditor5-math --parallel test",
|
"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,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import { join } from "path";
|
import { join, resolve } from "path";
|
||||||
import { cpSync, existsSync, mkdirSync, rmSync } from "fs";
|
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import { rebuild } from "@electron/rebuild"
|
import { rebuild } from "@electron/rebuild"
|
||||||
import { getElectronPath, isNixOS } from "../../../scripts/utils.mjs";
|
import { getElectronPath, isNixOS } from "./utils.mjs";
|
||||||
import packageJson from "../package.json" with { type: "json" };
|
|
||||||
|
|
||||||
const desktopProjectRoot = join(import.meta.dirname, "..");
|
const workspaceRoot = join(import.meta.dirname, "..");
|
||||||
const workspaceRoot = join(desktopProjectRoot, "../..");
|
|
||||||
|
|
||||||
function copyNativeDependencies() {
|
function copyNativeDependencies(projectRoot: string) {
|
||||||
const destPath = join(desktopProjectRoot, "node_modules/better-sqlite3");
|
const destPath = join(projectRoot, "node_modules/better-sqlite3");
|
||||||
|
|
||||||
if (existsSync(destPath)) {
|
if (existsSync(destPath)) {
|
||||||
rmSync(destPath, { recursive: true });
|
rmSync(destPath, { recursive: true });
|
||||||
@ -18,24 +16,28 @@ function copyNativeDependencies() {
|
|||||||
cpSync(join(workspaceRoot, "node_modules/better-sqlite3"), destPath, { recursive: true, dereference: true });
|
cpSync(join(workspaceRoot, "node_modules/better-sqlite3"), destPath, { recursive: true, dereference: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildNativeDependencies() {
|
function rebuildNativeDependencies(projectRoot: string) {
|
||||||
const electronVersion = determineElectronVersion();
|
const electronVersion = determineElectronVersion(projectRoot);
|
||||||
|
|
||||||
if (!electronVersion) {
|
if (!electronVersion) {
|
||||||
console.error("Unable to determine Electron version.");
|
console.error("Unable to determine Electron version.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Rebuilding ${desktopProjectRoot} with ${electronVersion}...`);
|
console.log(`Rebuilding ${projectRoot} with ${electronVersion}...`);
|
||||||
|
|
||||||
|
const resolvedPath = resolve(projectRoot);
|
||||||
rebuild({
|
rebuild({
|
||||||
projectRootPath: desktopProjectRoot,
|
projectRootPath: resolvedPath,
|
||||||
buildPath: desktopProjectRoot,
|
buildPath: resolvedPath,
|
||||||
electronVersion
|
electronVersion,
|
||||||
|
force: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function determineElectronVersion() {
|
function determineElectronVersion(projectRoot: string) {
|
||||||
|
const packageJson = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf-8"));
|
||||||
|
|
||||||
if (isNixOS()) {
|
if (isNixOS()) {
|
||||||
console.log("Detected NixOS, reading Electron version from PATH");
|
console.log("Detected NixOS, reading Electron version from PATH");
|
||||||
|
|
||||||
@ -51,5 +53,7 @@ function determineElectronVersion() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
copyNativeDependencies();
|
for (const projectRoot of [ "apps/desktop", "apps/edit-docs" ]) {
|
||||||
rebuildNativeDependencies();
|
copyNativeDependencies(projectRoot);
|
||||||
|
rebuildNativeDependencies(projectRoot);
|
||||||
|
}
|
@ -1,20 +1,17 @@
|
|||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import { getElectronPath, isNixOS } from "../../../scripts/utils.mjs";
|
import { getElectronPath, isNixOS } from "./utils.mjs";
|
||||||
import { join } from "path";
|
|
||||||
|
|
||||||
const projectRoot = join(import.meta.dirname, "..");
|
|
||||||
const LD_LIBRARY_PATH = isNixOS() && execSync("nix eval --raw nixpkgs#gcc.cc.lib").toString("utf-8") + "/lib";
|
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",
|
stdio: "inherit",
|
||||||
cwd: projectRoot,
|
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
NODE_OPTIONS: "--import tsx",
|
NODE_OPTIONS: "--import tsx",
|
||||||
NODE_ENV: "development",
|
NODE_ENV: "development",
|
||||||
TRILIUM_ENV: "dev",
|
TRILIUM_ENV: "dev",
|
||||||
TRILIUM_RESOURCE_DIR: "../server/src",
|
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
|
LD_LIBRARY_PATH
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user