Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watch: Fix duplicate logs and remove timestamps #830

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
17 changes: 10 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
2 changes: 0 additions & 2 deletions watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down