mirror of
https://github.com/beego/bee.git
synced 2024-12-22 15:10:49 +00:00
Merge pull request #13 from goinggo/master
Added support to watch all folders with Go files
This commit is contained in:
commit
1421e371a8
45
run.go
45
run.go
@ -15,6 +15,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
"runtime"
|
||||
@ -22,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
var cmdRun = &Command{
|
||||
UsageLine: "run [appname]",
|
||||
UsageLine: "run [appname] [watchall]",
|
||||
Short: "run the app which can hot compile",
|
||||
Long: `
|
||||
start the appname throw exec.Command
|
||||
@ -52,7 +53,8 @@ var appname string
|
||||
func runApp(cmd *Command, args []string) {
|
||||
exit := make(chan bool)
|
||||
crupath, _ := os.Getwd()
|
||||
if len(args) != 1 {
|
||||
|
||||
if len(args) == 0 || args[0] == "watchall" {
|
||||
appname = path.Base(crupath)
|
||||
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
|
||||
} else {
|
||||
@ -66,10 +68,15 @@ func runApp(cmd *Command, args []string) {
|
||||
}
|
||||
|
||||
var paths []string
|
||||
paths = append(paths,
|
||||
path.Join(crupath, conf.DirStruct.Controllers),
|
||||
path.Join(crupath, conf.DirStruct.Models),
|
||||
path.Join(crupath, "./")) // Current path.
|
||||
|
||||
if 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.
|
||||
}
|
||||
// Because monitor files has some issues, we watch current directory
|
||||
// and ignore non-go files.
|
||||
gps := GetGOPATHs()
|
||||
@ -91,3 +98,29 @@ func runApp(cmd *Command, args []string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func readAppDirectories(directory string, paths *[]string) {
|
||||
fileInfos, err := ioutil.ReadDir(directory)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
useDiectory := false
|
||||
for _, fileInfo := range fileInfos {
|
||||
if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' {
|
||||
readAppDirectories(directory+"/"+fileInfo.Name(), paths)
|
||||
continue
|
||||
}
|
||||
|
||||
if useDiectory == true {
|
||||
continue
|
||||
}
|
||||
|
||||
if path.Ext(fileInfo.Name()) == ".go" {
|
||||
*paths = append(*paths, directory)
|
||||
useDiectory = true
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user