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
fix(script_deployer): labels not applied on already existing note
Elian Doran82056e59bf7f
diff --git a/apps/script-deployer/src/deploy.spec.ts b/apps/script-deployer/src/deploy.spec.tsindex 2f8e4f265a..0a156748c8 100644--- a/apps/script-deployer/src/deploy.spec.ts+++ b/apps/script-deployer/src/deploy.spec.ts@@ -337,4 +337,49 @@ describe("deployScript", () => {expect(codeNote.getLabels().find((a) => a.name === "run")).toBeUndefined();});});++ describe("execute labels", () => {+ const content = `api.log("test");`;+ const mime = "application/javascript;env=backend";++ it("sets executeButton, executeDescription, and executeTitle on creation", () => {+ const meta = {+ id: "exec-test",+ type: "backend",+ title: "Exec Test",+ executeButton: "true",+ executeDescription: "Does something useful",+ executeTitle: "Run It",+ };+ deployScript(meta, content, mime, becca, notesService);++ const codeNote = becca.notes[codeNoteId(meta.id)];+ const labels = codeNote.getLabels();+ expect(labels.find((a) => a.name === "executeButton")?.value).toBe("true");+ expect(labels.find((a) => a.name === "executeDescription")?.value).toBe("Does something useful");+ expect(labels.find((a) => a.name === "executeTitle")?.value).toBe("Run It");+ });++ it("sets execute labels on update of an existing note", () => {+ const meta = { id: "exec-update", type: "backend", title: "Before" };+ deployScript(meta, content, mime, becca, notesService);++ const updated = { ...meta, title: "After", executeButton: "true", executeDescription: "Now executable" };+ const result = deployScript(updated, content, mime, becca, notesService);++ expect(result.action).toBe("updated");+ const labels = becca.notes[codeNoteId(meta.id)].getLabels();+ expect(labels.find((a) => a.name === "executeButton")?.value).toBe("true");+ expect(labels.find((a) => a.name === "executeDescription")?.value).toBe("Now executable");+ });++ it("does not set execute labels when absent from metadata", () => {+ const meta = { id: "no-exec", type: "backend", title: "Plain" };+ deployScript(meta, content, mime, becca, notesService);++ const labels = becca.notes[codeNoteId(meta.id)].getLabels();+ expect(labels.find((a) => a.name === "executeButton")).toBeUndefined();+ expect(labels.find((a) => a.name === "executeDescription")).toBeUndefined();+ });+ });});diff --git a/apps/script-deployer/src/deploy.ts b/apps/script-deployer/src/deploy.tsindex eb3da15444..862f7ba8f6 100644--- a/apps/script-deployer/src/deploy.ts+++ b/apps/script-deployer/src/deploy.ts@@ -145,6 +145,17 @@ export interface DeployResult {type: string;}+/** Labels that map directly from front-matter keys to note attributes. */+const PASSTHROUGH_LABELS = ["run", "executeButton", "executeDescription", "executeTitle"] as const;++function applyLabels(note: BeccaLike["notes"][string], meta: ScriptMeta) {+ for (const label of PASSTHROUGH_LABELS) {+ if (meta[label]) {+ note.setLabel(label, meta[label]);+ }+ }+}+/*** Deploys a single script file into the Trilium note tree.*@@ -168,6 +179,7 @@ export function deployScript(existing.title = meta.title;existing.save();existing.setContent(content);+ applyLabels(existing, meta);return { action: "updated", codeNoteId: codeId, title: meta.title, type: meta.type };}@@ -207,19 +219,7 @@ export function deployScript(content,});- const codeNote = becca.notes[codeId];-- // Backend scripts need a #run label to be executed by the scheduler.- if (meta.type === "backend" && meta.run) {- codeNote.setLabel("run", meta.run);- }-- // Labels that map directly from front-matter to note attributes.- for (const label of ["executeButton", "executeDescription", "executeTitle"] as const) {- if (meta[label]) {- codeNote.setLabel(label, meta[label]);- }- }+ applyLabels(becca.notes[codeId], meta);return { action: "created", codeNoteId: codeId, title: meta.title, type: meta.type };}