Skip to content

separate scan dir from executable/build dir #55

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions lib/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ type Builder interface {
}

type builder struct {
execdir string
dir string
binary string
errors string
useGodep bool
}

func NewBuilder(dir string, bin string, useGodep bool) Builder {
func NewBuilder(execdir string, dir string, bin string, useGodep bool) Builder {
if len(bin) == 0 {
bin = "bin"
}
Expand All @@ -32,7 +33,7 @@ func NewBuilder(dir string, bin string, useGodep bool) Builder {
}
}

return &builder{dir: dir, binary: bin, useGodep: useGodep}
return &builder{execdir: execdir, dir: dir, binary: bin, useGodep: useGodep}
}

func (b *builder) Binary() string {
Expand All @@ -50,7 +51,7 @@ func (b *builder) Build() error {
} else {
command = exec.Command("go", "build", "-o", b.binary)
}
command.Dir = b.dir
command.Dir = b.execdir

output, err := command.CombinedOutput()

Expand Down
2 changes: 1 addition & 1 deletion lib/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_Builder_Build_Success(t *testing.T) {
bin += ".exe"
}

builder := gin.NewBuilder(wd, bin, false)
builder := gin.NewBuilder(wd, wd, bin, false)
err := builder.Build()
expect(t, err, nil)

Expand Down
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func main() {
Value: ".",
Usage: "Path to watch files from",
},
cli.StringFlag{
Name: "execpath,e",
Value: "",
Usage: "Path to package that contains buildable artifact",
},
cli.BoolFlag{
Name: "immediate,i",
Usage: "run the server immediately after it's built",
Expand Down Expand Up @@ -82,6 +87,11 @@ func MainAction(c *cli.Context) {
appPort := strconv.Itoa(c.GlobalInt("appPort"))
immediate = c.GlobalBool("immediate")

execpath := c.GlobalString("execpath")
if len(execpath) == 0 {
c.GlobalString("path")
}

// Bootstrap the environment
envy.Bootstrap()

Expand All @@ -93,8 +103,8 @@ func MainAction(c *cli.Context) {
logger.Fatal(err)
}

builder := gin.NewBuilder(c.GlobalString("path"), c.GlobalString("bin"), c.GlobalBool("godep"))
runner := gin.NewRunner(filepath.Join(wd, builder.Binary()), c.Args()...)
builder := gin.NewBuilder(execpath, c.GlobalString("path"), c.GlobalString("bin"), c.GlobalBool("godep"))
runner := gin.NewRunner(filepath.Join(wd, execpath, builder.Binary()), c.Args()...)
runner.SetWriter(os.Stdout)
proxy := gin.NewProxy(builder, runner)

Expand Down Expand Up @@ -170,6 +180,7 @@ func scanChanges(watchPath string, cb scanCallback) {
}

if filepath.Ext(path) == ".go" && info.ModTime().After(startTime) {
log.Printf("%s", path)
cb(path)
startTime = time.Now()
return errors.New("done")
Expand Down