Generate web slides from Markdoc

feat(server): compile frontend bundle on demand

graham.systems 1ceab877 5c749632

verified
Changed files
+6 -107
packages
cli
core
server
wc
components
scripts
+1 -1
deno.json
··· 8 ], 9 "tasks": { 10 "build": "deno run --allow-env --allow-read --allow-write --allow-run packages/cli/main.ts build", 11 - "dev": "deno run --allow-env --allow-read --allow-write --allow-run packages/cli/main.ts dev" 12 }, 13 "compilerOptions": { 14 "lib": [
··· 8 ], 9 "tasks": { 10 "build": "deno run --allow-env --allow-read --allow-write --allow-run packages/cli/main.ts build", 11 + "dev": "deno run --watch --unstable-broadcast-channel --allow-net --allow-env --allow-read --allow-write --allow-run packages/cli/main.ts dev" 12 }, 13 "compilerOptions": { 14 "lib": [
-2
packages/cli/deno.json
··· 4 "exports": "./main.ts", 5 "imports": { 6 "@cliffy/command": "jsr:@cliffy/command@1.0.0-rc.8", 7 - "@morkdeck/core": "../core/mod.ts", 8 - "@morkdeck/server": "../server/mod.ts" 9 } 10 }
··· 4 "exports": "./main.ts", 5 "imports": { 6 "@cliffy/command": "jsr:@cliffy/command@1.0.0-rc.8", 7 } 8 }
+4 -1
packages/core/renderer.ts
··· 1 import Markdoc, { Node } from "@markdoc/markdoc"; 2 import { createMarkdocConfig } from "./markdoc-config.ts"; 3 import { Eta } from "@eta-dev/eta"; 4 import type { RenderOptions } from "./types.ts"; 5 6 - const eta = new Eta({ views: Deno.cwd() + "/templates" }); 7 8 export async function renderPresentationHtml( 9 path: string,
··· 1 import Markdoc, { Node } from "@markdoc/markdoc"; 2 import { createMarkdocConfig } from "./markdoc-config.ts"; 3 import { Eta } from "@eta-dev/eta"; 4 + import { resolve } from "@std/path"; 5 import type { RenderOptions } from "./types.ts"; 6 7 + const eta = new Eta({ 8 + views: resolve(import.meta.dirname ?? "", "./templates"), 9 + }); 10 11 export async function renderPresentationHtml( 12 path: string,
-1
packages/server/deno.json
··· 9 "@std/http": "jsr:@std/http@^1.0.20", 10 "@std/path": "jsr:@std/path@^1.1.1", 11 "esbuild": "npm:esbuild@^0.25.9", 12 - "@morkdeck/core": "../core/mod.ts" 13 } 14 }
··· 9 "@std/http": "jsr:@std/http@^1.0.20", 10 "@std/path": "jsr:@std/path@^1.1.1", 11 "esbuild": "npm:esbuild@^0.25.9", 12 } 13 }
+1 -1
packages/wc/components/slide.ts
··· 31 align-items: center; 32 33 padding: 6cqmin; 34 - background: #191724; 35 } 36 `; 37
··· 31 align-items: center; 32 33 padding: 6cqmin; 34 + background: #1f1d2e; 35 } 36 `; 37
-1
packages/wc/deno.json
··· 7 "lit": "npm:lit@^3.3.1", 8 "@lit/context": "npm:@lit/context@^1.1.6", 9 "motion": "npm:motion@^12.23.12", 10 - "@morkdeck/runtime": "../runtime/mod.ts" 11 } 12 }
··· 7 "lit": "npm:lit@^3.3.1", 8 "@lit/context": "npm:@lit/context@^1.1.6", 9 "motion": "npm:motion@^12.23.12", 10 } 11 }
-100
scripts/dev.ts
··· 1 - import * as esbuild from "esbuild"; 2 - import { globToRegExp } from "@std/path"; 3 - import { denoPlugin } from "@deno/esbuild-plugin"; 4 - import { debounce } from "@std/async/debounce"; 5 - 6 - const devCommand = new Deno.Command(Deno.execPath(), { 7 - args: [ 8 - "run", 9 - "--unstable-broadcast-channel", 10 - "--allow-env", 11 - "--allow-read", 12 - "--allow-net", 13 - "main.ts", 14 - "dev", 15 - "./slides.mdoc", 16 - ], 17 - }); 18 - 19 - // Watch esbuild watching `runtime/` 20 - async function rebuildRuntime() { 21 - const context = await esbuild.context({ 22 - entryPoints: ["runtime/morkdeck.ts"], 23 - outfile: "dist/morkdeck.js", 24 - bundle: true, 25 - plugins: [denoPlugin()], 26 - }); 27 - 28 - await context.rebuild(); 29 - 30 - return context; 31 - } 32 - 33 - async function dev() { 34 - const watcher = Deno.watchFs("."); 35 - 36 - // Runtime goes first to Morkdeck can serve the output 37 - const ctx = await rebuildRuntime(); 38 - let child = devCommand.spawn(); 39 - 40 - const runtimeGlob = globToRegExp("**/runtime/**/*.ts"); 41 - const rebuild = debounce(async () => { 42 - performance.mark("rebuild-start"); 43 - await ctx.rebuild(); 44 - performance.mark("rebuild-finish"); 45 - const { duration } = performance.measure( 46 - "rebuild-duration", 47 - "rebuild-start", 48 - "rebuild-finish", 49 - ); 50 - 51 - console.log( 52 - `runtime: change detected. rebuilt in ${duration.toFixed(0)}ms`, 53 - ); 54 - }, 150); 55 - 56 - const coreGlob = globToRegExp("**/{core,server,cli}/**/*.ts"); 57 - const restart = debounce(() => { 58 - performance.mark("restart-start"); 59 - child.kill(); 60 - child = devCommand.spawn(); 61 - performance.mark("restart-finish"); 62 - const { duration } = performance.measure( 63 - "restart-duration", 64 - "restart-start", 65 - "restart-finish", 66 - ); 67 - 68 - console.log( 69 - ` core: change detected. restarted in ${duration.toFixed(0)}ms`, 70 - ); 71 - }, 150); 72 - 73 - async function handleEvents() { 74 - for await (const e of watcher) { 75 - if (e.kind === "any" || e.kind === "access" || e.kind === "other") { 76 - continue; 77 - } 78 - 79 - if (e.paths.some((s) => runtimeGlob.test(s))) { 80 - rebuild(); 81 - } 82 - 83 - if (e.paths.some((s) => coreGlob.test(s))) { 84 - restart(); 85 - } 86 - } 87 - } 88 - 89 - handleEvents(); 90 - 91 - Deno.addSignalListener("SIGINT", async () => { 92 - await Promise.all([ 93 - watcher.close(), 94 - child.kill(), 95 - ctx.dispose(), 96 - ]); 97 - }); 98 - } 99 - 100 - if (import.meta.main) await dev();
···