1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 18:40: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
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

View File

@ -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 {

View File

@ -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" {