diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 98758d163..5aee5ea42 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,9 +1,12 @@ #### Features ๐Ÿš€ - Many non-Latin languages (e.g. Chinese, Japanese, Korean) are usable now that multi-byte characters are measured correctly. [#817](https://github.com/terrastruct/d2/pull/817) +- Fix duplicate success logs in watch mode. [830](https://github.com/terrastruct/d2/pull/830) #### Improvements ๐Ÿงน +- Cleaner watch mode logs without timestamps. [830](https://github.com/terrastruct/d2/pull/830) + #### Bugfixes โ›‘๏ธ - Fixes edge case where layouts with dagre show a connection from the bottom side of shapes being slightly disconnected from the shape. [#820](https://github.com/terrastruct/d2/pull/820) diff --git a/main.go b/main.go index 5303a9b2c..6634e25a8 100644 --- a/main.go +++ b/main.go @@ -198,7 +198,6 @@ func run(ctx context.Context, ms *xmain.State) (err error) { if inputPath == "-" { return xmain.UsageErrorf("-w[atch] cannot be combined with reading input from stdin") } - ms.Log.SetTS(true) w, err := newWatcher(ctx, ms, watcherOpts{ layoutPlugin: plugin, sketch: *sketchFlag, @@ -232,6 +231,7 @@ func run(ctx context.Context, ms *xmain.State) (err error) { } func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketch bool, pad, themeID int64, inputPath, outputPath string, bundle, forceAppendix bool, page playwright.Page) (_ []byte, written bool, _ error) { + start := time.Now() input, err := ms.ReadPath(inputPath) if err != nil { return nil, false, err @@ -256,38 +256,41 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc return nil, false, err } - svg, err := render(ctx, ms, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, diagram) + compileDir := time.Since(start) + svg, err := render(ctx, ms, compileDir, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, diagram) if err != nil { return svg, false, err } return svg, true, nil } -func render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketch bool, pad int64, inputPath, outputPath string, bundle, forceAppendix bool, page playwright.Page, ruler *textmeasure.Ruler, diagram *d2target.Diagram) ([]byte, error) { +func render(ctx context.Context, ms *xmain.State, compileDur time.Duration, plugin d2plugin.Plugin, sketch bool, pad int64, inputPath, outputPath string, bundle, forceAppendix bool, page playwright.Page, ruler *textmeasure.Ruler, diagram *d2target.Diagram) ([]byte, error) { outputPath = layerOutputPath(outputPath, diagram) for _, dl := range diagram.Layers { - _, err := render(ctx, ms, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, dl) + _, err := render(ctx, ms, compileDur, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, dl) if err != nil { return nil, err } } for _, dl := range diagram.Scenarios { - _, err := render(ctx, ms, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, dl) + _, err := render(ctx, ms, compileDur, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, dl) if err != nil { return nil, err } } for _, dl := range diagram.Steps { - _, err := render(ctx, ms, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, dl) + _, err := render(ctx, ms, compileDur, plugin, sketch, pad, inputPath, outputPath, bundle, forceAppendix, page, ruler, dl) if err != nil { return nil, err } } + start := time.Now() svg, err := _render(ctx, ms, plugin, sketch, pad, outputPath, bundle, forceAppendix, page, ruler, diagram) if err != nil { return svg, err } - ms.Log.Success.Printf("successfully compiled %v to %v", inputPath, outputPath) + dur := compileDur + time.Since(start) + ms.Log.Success.Printf("successfully compiled %s to %s in %s", inputPath, outputPath, dur) return svg, nil } diff --git a/watch.go b/watch.go index 8872551bc..85c88de82 100644 --- a/watch.go +++ b/watch.go @@ -367,8 +367,6 @@ func (w *watcher) compileLoop(ctx context.Context) error { } errs = err.Error() w.ms.Log.Error.Print(errs) - } else { - w.ms.Log.Success.Printf("successfully %scompiled %v to %v", recompiledPrefix, w.inputPath, w.outputPath) } w.broadcast(&compileResult{ SVG: string(svg),