From 2afd897ab3948e34be1b1cb234083bf0ca43c47d Mon Sep 17 00:00:00 2001 From: facundoolano Date: Wed, 6 Mar 2024 11:35:22 -0300 Subject: [PATCH] print site building times --- commands/commands.go | 7 ++++++- commands/serve.go | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index 58bd62d..d889113 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "strings" + "time" "github.com/alecthomas/kong" "github.com/facundoolano/jorge/config" @@ -20,12 +21,16 @@ type Build struct { // Read the files in src/ render them and copy the result to target/ func (cmd *Build) Run(ctx *kong.Context) error { + start := time.Now() + config, err := config.Load(cmd.ProjectDir) if err != nil { return err } - return site.Build(*config) + err = site.Build(*config) + fmt.Printf("done in %.2fs\n", time.Since(start).Seconds()) + return err } // Prompt the user for a string value diff --git a/commands/serve.go b/commands/serve.go index b8eb380..c39ed73 100644 --- a/commands/serve.go +++ b/commands/serve.go @@ -121,6 +121,7 @@ func runWatcher(config *config.Config, broker *EventBroker) (*fsnotify.Watcher, // rebuilding the site and publishing a rebuild event to clients. func rebuildSite(config *config.Config, watcher *fsnotify.Watcher, broker *EventBroker) { fmt.Printf("building site\n") + start := time.Now() // since new nested directories could be triggering this change, and we need to watch those too // and since re-watching files is a noop, I just re-add the entire src everytime there's a change @@ -135,7 +136,8 @@ func rebuildSite(config *config.Config, watcher *fsnotify.Watcher, broker *Event broker.publish("rebuild") - fmt.Println("done\nserving at", config.SiteUrl) + elapsed := time.Since(start) + fmt.Printf("done in %.2fs\nserving at %s\n", elapsed.Seconds(), config.SiteUrl) } // Configure the given watcher to notify for changes in the project source files