mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
Added support to watch all folders with Go files
This commit is contained in:
parent
89ed4f92e7
commit
da150b9b10
45
run.go
45
run.go
@ -15,6 +15,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
path "path/filepath"
|
path "path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -22,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var cmdRun = &Command{
|
var cmdRun = &Command{
|
||||||
UsageLine: "run [appname]",
|
UsageLine: "run [appname] [watchall]",
|
||||||
Short: "run the app which can hot compile",
|
Short: "run the app which can hot compile",
|
||||||
Long: `
|
Long: `
|
||||||
start the appname throw exec.Command
|
start the appname throw exec.Command
|
||||||
@ -52,7 +53,8 @@ var appname string
|
|||||||
func runApp(cmd *Command, args []string) {
|
func runApp(cmd *Command, args []string) {
|
||||||
exit := make(chan bool)
|
exit := make(chan bool)
|
||||||
crupath, _ := os.Getwd()
|
crupath, _ := os.Getwd()
|
||||||
if len(args) != 1 {
|
|
||||||
|
if len(args) == 0 || args[0] == "watchall" {
|
||||||
appname = path.Base(crupath)
|
appname = path.Base(crupath)
|
||||||
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
|
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
|
||||||
} else {
|
} else {
|
||||||
@ -66,10 +68,15 @@ func runApp(cmd *Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var paths []string
|
var paths []string
|
||||||
paths = append(paths,
|
|
||||||
path.Join(crupath, conf.DirStruct.Controllers),
|
if len(args) > 0 && args[len(args)-1] == "watchall" {
|
||||||
path.Join(crupath, conf.DirStruct.Models),
|
readAppDirectories(crupath, &paths)
|
||||||
path.Join(crupath, "./")) // Current path.
|
} 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()
|
||||||
@ -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