Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support prev build cmds #25

Merged
merged 4 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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