mirror of
https://github.com/beego/bee.git
synced 2024-11-22 15:10:54 +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
37
run.go
37
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
|
||||||
|
|
||||||
|
if len(args) > 0 && args[len(args)-1] == "watchall" {
|
||||||
|
readAppDirectories(crupath, &paths)
|
||||||
|
} else {
|
||||||
paths = append(paths,
|
paths = append(paths,
|
||||||
path.Join(crupath, conf.DirStruct.Controllers),
|
path.Join(crupath, conf.DirStruct.Controllers),
|
||||||
path.Join(crupath, conf.DirStruct.Models),
|
path.Join(crupath, conf.DirStruct.Models),
|
||||||
path.Join(crupath, "./")) // Current path.
|
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