watch: Fix duplicate logs and remove timestamps
Instead we log the duration each layer's full compilation took.
This commit is contained in:
parent
92ee929f21
commit
0bb56a83ef
3 changed files with 13 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
17
main.go
17
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
|
||||
}
|
||||
|
||||
|
|
|
|||
2
watch.go
2
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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue