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
feat(script_deployer): basic support for syncing
Elian Doran593502808257
diff --git a/apps/script-deployer/scripts/import-xopp-to-canvas.jsx b/apps/script-deployer/scripts/import-xopp-to-canvas.jsxindex 593c6c7fe0..7ea268433d 100644--- a/apps/script-deployer/scripts/import-xopp-to-canvas.jsx+++ b/apps/script-deployer/scripts/import-xopp-to-canvas.jsx@@ -24,6 +24,8 @@ const XOPP_COLORS = {white: "#ffffff",};+// Hi there.+function convertColor(color) {if (!color) return "#000000";const lower = color.toLowerCase();@@ -339,7 +341,7 @@ export default function XoppImporter() {return (<div style={{ padding: "20px", maxWidth: "600px" }}>- <h2 style={{ marginTop: 0 }}>Xournal++ Importer</h2>+ <h2 style={{ marginTop: 0 }}>Xournal-- Importer</h2><p style={{ color: "#666" }}>Convert <code>.xopp</code> files to Excalidraw canvas notes.Multi-page documents are stacked vertically.diff --git a/apps/script-deployer/src/dev.ts b/apps/script-deployer/src/dev.tsindex 0770cadee9..b17b8806ea 100644--- a/apps/script-deployer/src/dev.ts+++ b/apps/script-deployer/src/dev.ts@@ -6,8 +6,8 @@* On subsequent runs it just boots the server.*/-import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";-import { resolve, join, extname } from "node:path";+import { existsSync, mkdirSync, readdirSync, readFileSync, watch, writeFileSync } from "node:fs";+import { resolve, join, basename, extname } from "node:path";// ── Environment — must be set before any server module is imported ──────────const DATA_DIR = resolve(__dirname, "../data");@@ -217,6 +217,49 @@ async function deployScripts() {}}+function watchScripts() {+ // Debounce per file — editors can fire multiple events on a single save.+ const timers = new Map<string, ReturnType<typeof setTimeout>>();++ watch(SCRIPTS_DIR, (eventType, filename) => {+ if (!filename || !MIME_BY_EXT[extname(filename)]) return;++ if (timers.has(filename)) clearTimeout(timers.get(filename));+ timers.set(filename, setTimeout(() => {+ timers.delete(filename);+ syncFile(filename);+ }, 100));+ });++ async function syncFile(filename: string) {+ const filePath = join(SCRIPTS_DIR, filename);+ if (!existsSync(filePath)) return;++ const source = readFileSync(filePath, "utf-8");+ const meta = parseScriptMeta(source, filename);+ if (!meta) return;++ const codeNoteId = `_sd_${meta.id}`;++ // Already in memory from deployScripts(), import() returns from cache.+ const becca = (await import("@triliumnext/server/src/becca/becca.js")).default;+ const cls = (await import("@triliumnext/server/src/services/cls.js")).default;++ const note = becca.notes[codeNoteId];+ if (!note) {+ console.log(` [watch] ${filename}: note ${codeNoteId} not found, restart to create.`);+ return;+ }++ cls.init(() => {+ note.setContent(source);+ });+ console.log(` [watch] Synced: ${meta.title}`);+ }++ console.log(`Watching ${SCRIPTS_DIR} for changes…`);+}+async function main() {await ensureTranslations();await ensureDatabase();@@ -229,6 +272,7 @@ async function main() {await ensureScriptsFolder();await deployScripts();+ watchScripts();console.log(`\nScript-deployer Trilium instance running on http://localhost:${PORT}`);console.log(`Token file: ${TOKEN_PATH}\n`);