mirror of
https://github.com/casbin/bee.git
synced 2025-07-19 16:14:19 +08:00
bee
This commit is contained in:
53
start.go
Normal file
53
start.go
Normal file
@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
var cmdStart = &Command{
|
||||
UsageLine: "start [appname]",
|
||||
Short: "start the app which can hot compile",
|
||||
Long: `
|
||||
start the appname throw exec.Command
|
||||
|
||||
then start a inotify watch for current dir
|
||||
|
||||
when the file has changed bee will auto go build and restart the app
|
||||
|
||||
file changed
|
||||
|
|
||||
checked is go file
|
||||
|
|
||||
yes no
|
||||
| |
|
||||
go build do nothing
|
||||
|
|
||||
restart app
|
||||
`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
cmdStart.Run = startapp
|
||||
}
|
||||
|
||||
func startapp(cmd *Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
fmt.Println("error args")
|
||||
os.Exit(2)
|
||||
}
|
||||
crupath, _ := os.Getwd()
|
||||
var paths []string
|
||||
paths = append(paths, path.Join(crupath, "controllers"), path.Join(crupath, "models"))
|
||||
NewWatcher(paths)
|
||||
go Start(args[0])
|
||||
for {
|
||||
select {
|
||||
case <-restart:
|
||||
go Start(args[0])
|
||||
case <-builderror:
|
||||
fmt.Println("build error:", builderror)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user