Skip to content

Commit

Permalink
Merge pull request #25 from silenceper/f-support-external-cmd
Browse files Browse the repository at this point in the history
support prev build cmds
  • Loading branch information
silenceper authored Sep 7, 2020
2 parents d5d7b02 + ffa6f72 commit 9e7caea
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ build_pkg: ""
# build tags
build_tags: ""
# Commands that can be executed before build the app
#prev_build_cmds:
# - swag init
# Whether to prohibit automatic operation
disable_run: false
Expand Down
4 changes: 4 additions & 0 deletions README_ZH_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ build_pkg: ""
# build tags
build_tags: ""
#在build app执行的命令 ,例如 swag init
#prev_build_cmds:
# - swag init
# 是否禁止自动运行
disable_run: false
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type config struct {
WatchExts []string `yaml:"watch_exts"`
//需要追加监听的目录,默认是当前文件夹,
WatchPaths []string `yaml:"watch_paths"`
//build前额外执行的命令
PrevBuildCmds []string `yaml:"prev_build_cmds"`
//执行时的额外参数
CmdArgs []string `yaml:"cmd_args"`
//构建时的额外参数
Expand Down
14 changes: 14 additions & 0 deletions gowatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ func Autobuild(files []string) {
return
}

for _, prevCmd := range cfg.PrevBuildCmds {
log.Infof("Run external cmd '%s'", prevCmd)
cmdArr := strings.Split(prevCmd, " ")
prevCmdExec := exec.Command(cmdArr[0])
prevCmdExec.Env = append(os.Environ(), cfg.Envs...)
prevCmdExec.Args = cmdArr
prevCmdExec.Stdout = os.Stdout
prevCmdExec.Stderr = os.Stderr
err := prevCmdExec.Run()
if err != nil {
panic(err)
}
}

cmdName := "go"

var err error
Expand Down

0 comments on commit 9e7caea

Please sign in to comment.