mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
now bee run can specify main files
This commit is contained in:
parent
1a352bc6b3
commit
7da30d1b35
16
run.go
16
run.go
@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var cmdRun = &Command{
|
var cmdRun = &Command{
|
||||||
UsageLine: "run [appname] [watchall]",
|
UsageLine: "run [appname] [watchall] [-main=*.go]",
|
||||||
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
|
||||||
@ -44,8 +44,11 @@ when the file has changed bee will auto go build and restart the app
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mainFiles ListOpts
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmdRun.Run = runApp
|
cmdRun.Run = runApp
|
||||||
|
cmdRun.Flag.Var(&mainFiles, "main", "specify main go files")
|
||||||
}
|
}
|
||||||
|
|
||||||
var appname string
|
var appname string
|
||||||
@ -89,8 +92,15 @@ func runApp(cmd *Command, args []string) {
|
|||||||
paths = append(paths, strings.Replace(p, "$GOPATH", gopath, -1))
|
paths = append(paths, strings.Replace(p, "$GOPATH", gopath, -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
NewWatcher(paths)
|
files := []string{}
|
||||||
Autobuild()
|
for _, arg := range mainFiles {
|
||||||
|
if len(arg) > 0 {
|
||||||
|
files = append(files, arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NewWatcher(paths, files)
|
||||||
|
Autobuild(files)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-exit:
|
case <-exit:
|
||||||
|
4
test.go
4
test.go
@ -71,9 +71,9 @@ func testApp(cmd *Command, args []string) {
|
|||||||
// and ignore non-go files.
|
// and ignore non-go files.
|
||||||
paths = append(paths, conf.DirStruct.Others...)
|
paths = append(paths, conf.DirStruct.Others...)
|
||||||
|
|
||||||
NewWatcher(paths)
|
NewWatcher(paths, nil)
|
||||||
appname = args[0]
|
appname = args[0]
|
||||||
Autobuild()
|
Autobuild(nil)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-started:
|
case <-started:
|
||||||
|
12
watch.go
12
watch.go
@ -34,7 +34,7 @@ var (
|
|||||||
buildPeriod time.Time
|
buildPeriod time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewWatcher(paths []string) {
|
func NewWatcher(paths []string, files []string) {
|
||||||
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) {
|
|||||||
|
|
||||||
if isbuild {
|
if isbuild {
|
||||||
ColorLog("[EVEN] %s\n", e)
|
ColorLog("[EVEN] %s\n", e)
|
||||||
go Autobuild()
|
go Autobuild(files)
|
||||||
}
|
}
|
||||||
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() {
|
func Autobuild(files []string) {
|
||||||
state.Lock()
|
state.Lock()
|
||||||
defer state.Unlock()
|
defer state.Unlock()
|
||||||
|
|
||||||
@ -154,7 +154,11 @@ func Autobuild() {
|
|||||||
appName += ".exe"
|
appName += ".exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
bcmd := exec.Command(cmdName, "build")
|
args := []string{"build"}
|
||||||
|
args = append(args, "-o", appName)
|
||||||
|
args = append(args, files...)
|
||||||
|
|
||||||
|
bcmd := exec.Command(cmdName, args...)
|
||||||
bcmd.Stdout = os.Stdout
|
bcmd.Stdout = os.Stdout
|
||||||
bcmd.Stderr = os.Stderr
|
bcmd.Stderr = os.Stderr
|
||||||
err = bcmd.Run()
|
err = bcmd.Run()
|
||||||
|
Loading…
Reference in New Issue
Block a user