Skip to content

Commit e26e694

Browse files
committed
chore(script_deployer): basic support for backend notes
1 parent 8574593 commit e26e694

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

apps/script-deployer/src/deploy.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,41 @@ describe("deployScript", () => {
300300
});
301301
});
302302
});
303+
304+
describe("backend script", () => {
305+
const meta = { id: "hello-world", type: "backend", run: "backendStartup", title: "Hello World" };
306+
const content = `api.log("Hello from script-deployer!");`;
307+
const mime = "application/javascript;env=backend";
308+
309+
it("creates a code note with #run label", () => {
310+
deployScript(meta, content, mime, becca, notesService);
311+
312+
const codeId = codeNoteId(meta.id);
313+
const codeNote = becca.notes[codeId];
314+
315+
expect(codeNote).toBeDefined();
316+
expect(codeNote.type).toBe("code");
317+
318+
const runLabel = codeNote.getLabels().find((a) => a.name === "run");
319+
expect(runLabel).toBeDefined();
320+
expect(runLabel!.value).toBe("backendStartup");
321+
});
322+
323+
it("places the code note under scripts folder, no render note", () => {
324+
deployScript(meta, content, mime, becca, notesService);
325+
326+
const codeId = codeNoteId(meta.id);
327+
const codeNote = becca.notes[codeId];
328+
expect(codeNote.getParentBranches().some((b) => b.parentNoteId === SCRIPTS_NOTE_ID)).toBe(true);
329+
expect(becca.notes[renderNoteId(meta.id)]).toBeUndefined();
330+
});
331+
332+
it("does not set #run when run field is absent", () => {
333+
const metaNoRun = { id: "no-run", type: "backend", title: "No Run" };
334+
deployScript(metaNoRun, content, mime, becca, notesService);
335+
336+
const codeNote = becca.notes[codeNoteId(metaNoRun.id)];
337+
expect(codeNote.getLabels().find((a) => a.name === "run")).toBeUndefined();
338+
});
339+
});
303340
});

apps/script-deployer/src/deploy.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export interface BeccaLike {
133133
save(): void;
134134
setContent(content: string): void;
135135
setRelation(name: string, targetNoteId: string): void;
136+
setLabel(name: string, value?: string): void;
136137
}>;
137138
}
138139

@@ -196,7 +197,7 @@ export function deployScript(
196197
return { action: "created", codeNoteId: codeId, renderNoteId: renderId, title: meta.title, type: meta.type };
197198
}
198199

199-
// Plain code note.
200+
// Plain code note (backend script, widget, etc.)
200201
notesService.createNewNote({
201202
noteId: codeId,
202203
parentNoteId,
@@ -206,5 +207,11 @@ export function deployScript(
206207
content,
207208
});
208209

210+
// Backend scripts need a #run label to be executed by the scheduler.
211+
if (meta.type === "backend" && meta.run) {
212+
const codeNote = becca.notes[codeId];
213+
codeNote.setLabel("run", meta.run);
214+
}
215+
209216
return { action: "created", codeNoteId: codeId, title: meta.title, type: meta.type };
210217
}

0 commit comments

Comments
 (0)