From 4ac9fb0dacc4b944cce867d04a46f6c26f6c482a Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 18 Jun 2014 21:31:54 +0800 Subject: [PATCH] bee default support watchall support generate doc bee run appname true --- run.go | 22 ++++++++++++---------- test.go | 2 +- watch.go | 14 +++++++++++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/run.go b/run.go index c992652..37e95a1 100644 --- a/run.go +++ b/run.go @@ -72,14 +72,8 @@ func runApp(cmd *Command, args []string) { var paths []string - if conf.DirStruct.WatchAll || (len(args) > 0 && args[len(args)-1] == "watchall") { - readAppDirectories(crupath, &paths) - } else { - paths = append(paths, - path.Join(crupath, conf.DirStruct.Controllers), - path.Join(crupath, conf.DirStruct.Models), - path.Join(crupath, "./")) // Current path. - } + readAppDirectories(crupath, &paths) + // Because monitor files has some issues, we watch current directory // and ignore non-go files. gps := GetGOPATHs() @@ -99,8 +93,13 @@ func runApp(cmd *Command, args []string) { } } - NewWatcher(paths, files) - Autobuild(files) + if len(args) >= 2 && args[1] == "true" { + NewWatcher(paths, files, true) + Autobuild(files, true) + } else { + NewWatcher(paths, files, false) + Autobuild(files, false) + } for { select { case <-exit: @@ -117,6 +116,9 @@ func readAppDirectories(directory string, paths *[]string) { useDiectory := false for _, fileInfo := range fileInfos { + if strings.HasSuffix(fileInfo.Name(), "docs") { + continue + } if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' { readAppDirectories(directory+"/"+fileInfo.Name(), paths) continue diff --git a/test.go b/test.go index c1b1d0c..d8b8aff 100644 --- a/test.go +++ b/test.go @@ -65,7 +65,7 @@ func testApp(cmd *Command, args []string) { var paths []string readAppDirectories(crupath, &paths) - NewWatcher(paths, nil) + NewWatcher(paths, nil, false) appname = args[0] for { select { diff --git a/watch.go b/watch.go index d047bb8..1e41718 100644 --- a/watch.go +++ b/watch.go @@ -34,7 +34,7 @@ var ( buildPeriod time.Time ) -func NewWatcher(paths []string, files []string) { +func NewWatcher(paths []string, files []string, isgenerate bool) { watcher, err := fsnotify.NewWatcher() if err != nil { ColorLog("[ERRO] Fail to create new Watcher[ %s ]\n", err) @@ -71,7 +71,7 @@ func NewWatcher(paths []string, files []string) { if isbuild { ColorLog("[EVEN] %s\n", e) - go Autobuild(files) + go Autobuild(files, isgenerate) } case err := <-watcher.Error: ColorLog("[WARN] %s\n", err.Error()) // No need to exit here @@ -110,7 +110,7 @@ func getFileModTime(path string) int64 { return fi.ModTime().Unix() } -func Autobuild(files []string) { +func Autobuild(files []string, isgenerate bool) { state.Lock() defer state.Unlock() @@ -148,6 +148,14 @@ func Autobuild(files []string) { } } + if isgenerate { + icmd := exec.Command("bee", "generate", "docs") + icmd.Stdout = os.Stdout + icmd.Stderr = os.Stderr + icmd.Run() + ColorLog("============== generate docs ===================\n") + } + if err == nil { appName := appname if runtime.GOOS == "windows" {