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
chore(script_deployer): basic support for backend notes
Elian Dorane26e69441ed0
diff --git a/apps/script-deployer/src/deploy.spec.ts b/apps/script-deployer/src/deploy.spec.tsindex 2773c2bd56..2f8e4f265a 100644--- a/apps/script-deployer/src/deploy.spec.ts+++ b/apps/script-deployer/src/deploy.spec.ts@@ -300,4 +300,41 @@ describe("deployScript", () => {});});});++ describe("backend script", () => {+ const meta = { id: "hello-world", type: "backend", run: "backendStartup", title: "Hello World" };+ const content = `api.log("Hello from script-deployer!");`;+ const mime = "application/javascript;env=backend";++ it("creates a code note with #run label", () => {+ deployScript(meta, content, mime, becca, notesService);++ const codeId = codeNoteId(meta.id);+ const codeNote = becca.notes[codeId];++ expect(codeNote).toBeDefined();+ expect(codeNote.type).toBe("code");++ const runLabel = codeNote.getLabels().find((a) => a.name === "run");+ expect(runLabel).toBeDefined();+ expect(runLabel!.value).toBe("backendStartup");+ });++ it("places the code note under scripts folder, no render note", () => {+ deployScript(meta, content, mime, becca, notesService);++ const codeId = codeNoteId(meta.id);+ const codeNote = becca.notes[codeId];+ expect(codeNote.getParentBranches().some((b) => b.parentNoteId === SCRIPTS_NOTE_ID)).toBe(true);+ expect(becca.notes[renderNoteId(meta.id)]).toBeUndefined();+ });++ it("does not set #run when run field is absent", () => {+ const metaNoRun = { id: "no-run", type: "backend", title: "No Run" };+ deployScript(metaNoRun, content, mime, becca, notesService);++ const codeNote = becca.notes[codeNoteId(metaNoRun.id)];+ expect(codeNote.getLabels().find((a) => a.name === "run")).toBeUndefined();+ });+ });});diff --git a/apps/script-deployer/src/deploy.ts b/apps/script-deployer/src/deploy.tsindex 94856c85cf..1797cb0045 100644--- a/apps/script-deployer/src/deploy.ts+++ b/apps/script-deployer/src/deploy.ts@@ -133,6 +133,7 @@ export interface BeccaLike {save(): void;setContent(content: string): void;setRelation(name: string, targetNoteId: string): void;+ setLabel(name: string, value?: string): void;}>;}@@ -196,7 +197,7 @@ export function deployScript(return { action: "created", codeNoteId: codeId, renderNoteId: renderId, title: meta.title, type: meta.type };}- // Plain code note.+ // Plain code note (backend script, widget, etc.)notesService.createNewNote({noteId: codeId,parentNoteId,@@ -206,5 +207,11 @@ export function deployScript(content,});+ // Backend scripts need a #run label to be executed by the scheduler.+ if (meta.type === "backend" && meta.run) {+ const codeNote = becca.notes[codeId];+ codeNote.setLabel("run", meta.run);+ }+return { action: "created", codeNoteId: codeId, title: meta.title, type: meta.type };}