1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 23:14:40 +01:00
gojekyll/commands/build.go
2017-08-16 16:11:29 -04:00

53 lines
1.1 KiB
Go

package commands
import (
"fmt"
"os"
"time"
"github.com/osteele/gojekyll/site"
)
// main sets this
var commandStartTime = time.Now()
var build = app.Command("build", "Build your site").Alias("b")
func init() {
build.Flag("dry-run", "Dry run").Short('n').BoolVar(&options.DryRun)
}
func buildCommand(site *site.Site) error {
watch := site.Config().Watch
logger.path("Destination:", site.DestDir())
logger.label("Generating...", "")
count, err := site.Write()
switch {
case err == nil:
elapsed := time.Since(commandStartTime)
logger.label("", "wrote %d files in %.2fs.", count, elapsed.Seconds())
case watch:
fmt.Fprintln(os.Stderr, err)
default:
return err
}
// FIXME the watch will miss files that changed during the first build
// server watch is implemented inside Server.Run, in contrast to this command
if watch {
events, err := site.WatchRebuild()
if err != nil {
return err
}
logger.label("Auto-regeneration:", "enabled for %q", site.SourceDir())
for event := range events {
fmt.Print(event)
}
} else {
logger.label("Auto-regeneration:", "disabled. Use --watch to enable.")
}
return nil
}