import (
"fmt"
"io/ioutil"
+ "os/signal"
"sort"
"sync/atomic"
+ "syscall"
"golang.org/x/sync/errgroup"
})
}
-func (c *commandeer) fullBuild(watches ...bool) error {
+func (c *commandeer) fullBuild() error {
var (
g errgroup.Group
langCount map[string]uint64
}
-func (c *commandeer) build(watches ...bool) error {
+func (c *commandeer) build() error {
defer c.timeTrack(time.Now(), "Total")
- if err := c.fullBuild(watches...); err != nil {
+ if err := c.fullBuild(); err != nil {
return err
}
}
c.Logger.FEEDBACK.Println("Watching for changes in", c.PathSpec().AbsPathify(c.Cfg.GetString("contentDir")))
c.Logger.FEEDBACK.Println("Press Ctrl+C to stop")
- utils.CheckErr(c.Logger, c.newWatcher(watchDirs...))
+ watcher, err := c.newWatcher(watchDirs...)
+ utils.CheckErr(c.Logger, err)
+ defer watcher.Close()
+
+ var sigs = make(chan os.Signal)
+ signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
+
+ <-sigs
+ }
+
+ return nil
+}
+
+func (c *commandeer) serverBuild() error {
+ defer c.timeTrack(time.Now(), "Total")
+
+ if err := c.fullBuild(); err != nil {
+ return err
+ }
+
+ // TODO(bep) Feedback?
+ if !quiet {
+ fmt.Println()
+ Hugo.PrintProcessingStats(os.Stdout)
+ fmt.Println()
}
return nil
}
// newWatcher creates a new watcher to watch filesystem events.
-func (c *commandeer) newWatcher(dirList ...string) error {
+func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
if runtime.GOOS == "darwin" {
tweakLimit()
}
staticSyncer, err := newStaticSyncer(c)
if err != nil {
- return err
+ return nil, err
}
watcher, err := watcher.New(1 * time.Second)
if err != nil {
- return err
+ return nil, err
}
- defer watcher.Close()
-
for _, d := range dirList {
if d != "" {
_ = watcher.Add(d)
}
}()
- return nil
+ return watcher, nil
}
func pickOneWriteOrCreatePath(events []fsnotify.Event) string {
return err
}
- if err := c.build(serverWatch); err != nil {
+ if err := c.serverBuild(); err != nil {
return err
}
rootWatchDirs := strings.Join(helpers.UniqueStrings(helpers.ExtractRootPaths(relWatchDirs)), ",")
jww.FEEDBACK.Printf("Watching for changes in %s%s{%s}\n", baseWatchDir, helpers.FilePathSeparator, rootWatchDirs)
- err = c.newWatcher(watchDirs...)
+ watcher, err := c.newWatcher(watchDirs...)
if err != nil {
return err
}
+ defer watcher.Close()
+
}
return c.serve()