1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 23:50:54 +00:00

bee default support watchall support generate doc

bee run appname true
This commit is contained in:
astaxie 2014-06-18 21:31:54 +08:00
parent 37badb1411
commit 4ac9fb0dac
3 changed files with 24 additions and 14 deletions

22
run.go
View File

@ -72,14 +72,8 @@ func runApp(cmd *Command, args []string) {
var paths []string var paths []string
if conf.DirStruct.WatchAll || (len(args) > 0 && args[len(args)-1] == "watchall") { readAppDirectories(crupath, &paths)
readAppDirectories(crupath, &paths)
} else {
paths = append(paths,
path.Join(crupath, conf.DirStruct.Controllers),
path.Join(crupath, conf.DirStruct.Models),
path.Join(crupath, "./")) // Current path.
}
// Because monitor files has some issues, we watch current directory // Because monitor files has some issues, we watch current directory
// and ignore non-go files. // and ignore non-go files.
gps := GetGOPATHs() gps := GetGOPATHs()
@ -99,8 +93,13 @@ func runApp(cmd *Command, args []string) {
} }
} }
NewWatcher(paths, files) if len(args) >= 2 && args[1] == "true" {
Autobuild(files) NewWatcher(paths, files, true)
Autobuild(files, true)
} else {
NewWatcher(paths, files, false)
Autobuild(files, false)
}
for { for {
select { select {
case <-exit: case <-exit:
@ -117,6 +116,9 @@ func readAppDirectories(directory string, paths *[]string) {
useDiectory := false useDiectory := false
for _, fileInfo := range fileInfos { for _, fileInfo := range fileInfos {
if strings.HasSuffix(fileInfo.Name(), "docs") {
continue
}
if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' { if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' {
readAppDirectories(directory+"/"+fileInfo.Name(), paths) readAppDirectories(directory+"/"+fileInfo.Name(), paths)
continue continue

View File

@ -65,7 +65,7 @@ func testApp(cmd *Command, args []string) {
var paths []string var paths []string
readAppDirectories(crupath, &paths) readAppDirectories(crupath, &paths)
NewWatcher(paths, nil) NewWatcher(paths, nil, false)
appname = args[0] appname = args[0]
for { for {
select { select {

View File

@ -34,7 +34,7 @@ var (
buildPeriod time.Time buildPeriod time.Time
) )
func NewWatcher(paths []string, files []string) { func NewWatcher(paths []string, files []string, isgenerate bool) {
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
ColorLog("[ERRO] Fail to create new Watcher[ %s ]\n", err) ColorLog("[ERRO] Fail to create new Watcher[ %s ]\n", err)
@ -71,7 +71,7 @@ func NewWatcher(paths []string, files []string) {
if isbuild { if isbuild {
ColorLog("[EVEN] %s\n", e) ColorLog("[EVEN] %s\n", e)
go Autobuild(files) go Autobuild(files, isgenerate)
} }
case err := <-watcher.Error: case err := <-watcher.Error:
ColorLog("[WARN] %s\n", err.Error()) // No need to exit here ColorLog("[WARN] %s\n", err.Error()) // No need to exit here
@ -110,7 +110,7 @@ func getFileModTime(path string) int64 {
return fi.ModTime().Unix() return fi.ModTime().Unix()
} }
func Autobuild(files []string) { func Autobuild(files []string, isgenerate bool) {
state.Lock() state.Lock()
defer state.Unlock() 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 { if err == nil {
appName := appname appName := appname
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {