diff --git a/d2cli/main.go b/d2cli/main.go index 635a5e440..546a5a977 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -331,7 +331,7 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { ctx, cancel := timelib.WithTimeout(ctx, time.Minute*2) defer cancel() - _, written, err := compile(ctx, ms, plugins, layoutFlag, renderOpts, fontFamily, *animateIntervalFlag, inputPath, outputPath, *bundleFlag, *forceAppendixFlag, pw.Page) + _, written, err := compile(ctx, ms, plugins, layoutFlag, renderOpts, fontFamily, *animateIntervalFlag, inputPath, outputPath, "", *bundleFlag, *forceAppendixFlag, pw.Page) if err != nil { if written { return fmt.Errorf("failed to fully compile (partial render written): %w", err) @@ -366,7 +366,7 @@ func LayoutResolver(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plu } } -func compile(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plugin, layout *string, renderOpts d2svg.RenderOpts, fontFamily *d2fonts.FontFamily, animateInterval int64, inputPath, outputPath string, bundle, forceAppendix bool, page playwright.Page) (_ []byte, written bool, _ error) { +func compile(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plugin, layout *string, renderOpts d2svg.RenderOpts, fontFamily *d2fonts.FontFamily, animateInterval int64, inputPath, outputPath, boardPath string, bundle, forceAppendix bool, page playwright.Page) (_ []byte, written bool, _ error) { start := time.Now() input, err := ms.ReadPath(inputPath) if err != nil { @@ -500,7 +500,12 @@ func compile(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plugin, la } } - boards, err := render(ctx, ms, compileDur, plugin, renderOpts, inputPath, outputPath, bundle, forceAppendix, page, ruler, diagram) + board := diagram.GetBoard(boardPath) + if board == nil { + return nil, false, fmt.Errorf("Diagram with path %s not found", boardPath) + } + + boards, err := render(ctx, ms, compileDur, plugin, renderOpts, inputPath, outputPath, bundle, forceAppendix, page, ruler, board) if err != nil { return nil, false, err } diff --git a/d2cli/static/watch.js b/d2cli/static/watch.js index a95403971..9da3e630a 100644 --- a/d2cli/static/watch.js +++ b/d2cli/static/watch.js @@ -9,7 +9,7 @@ function init(reconnectDelay) { const devMode = document.body.dataset.d2DevMode === "true"; const ws = new WebSocket( - `ws://${window.location.host}${window.location.pathname}watch` + `ws://${window.location.host}/watch` ); let isInit = true; let ratio; @@ -28,7 +28,7 @@ function init(reconnectDelay) { // we can't just set `d2SVG.innerHTML = msg.svg` need to parse this as xml not html const parsedXML = new DOMParser().parseFromString(msg.svg, "text/xml"); d2SVG.replaceChildren(parsedXML.documentElement); - changeFavicon("./static/favicon.ico"); + changeFavicon("/static/favicon.ico"); const svgEl = d2SVG.querySelector("#d2-svg"); // just use inner SVG in watch mode svgEl.parentElement.replaceWith(svgEl); @@ -60,7 +60,7 @@ function init(reconnectDelay) { if (msg.err) { d2ErrDiv.innerText = msg.err; d2ErrDiv.style.display = "block"; - changeFavicon("./static/favicon-err.ico"); + changeFavicon("/static/favicon-err.ico"); d2ErrDiv.scrollIntoView(); } }; diff --git a/d2cli/watch.go b/d2cli/watch.go index 0fefabd61..b370a4d16 100644 --- a/d2cli/watch.go +++ b/d2cli/watch.go @@ -12,6 +12,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "sync" "time" @@ -49,6 +50,7 @@ type watcherOpts struct { port string inputPath string outputPath string + boardPath string pwd string bundle bool forceAppendix bool @@ -362,7 +364,7 @@ func (w *watcher) compileLoop(ctx context.Context) error { w.pw = newPW } - svg, _, err := compile(ctx, w.ms, w.plugins, w.layout, w.renderOpts, w.fontFamily, w.animateInterval, w.inputPath, w.outputPath, w.bundle, w.forceAppendix, w.pw.Page) + svg, _, err := compile(ctx, w.ms, w.plugins, w.layout, w.renderOpts, w.fontFamily, w.animateInterval, w.inputPath, w.outputPath, w.boardPath, w.bundle, w.forceAppendix, w.pw.Page) errs := "" if err != nil { if len(svg) > 0 { @@ -430,15 +432,23 @@ func (w *watcher) handleRoot(hw http.ResponseWriter, r *http.Request) {