From 422e2dc7374f0445f0b6f01a56eed5ca9367ce9a Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 25 Jul 2013 16:26:54 +0800 Subject: [PATCH] Add option go install --- bee.json | 1 + run.go | 3 +++ watch.go | 21 +++++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bee.json b/bee.json index 164b7f6..b8e8a23 100644 --- a/bee.json +++ b/bee.json @@ -1,4 +1,5 @@ { + "go_install": false, "dir_structure":{ "controllers": "", "models": "" diff --git a/run.go b/run.go index 4b3b3be..f9ba02e 100644 --- a/run.go +++ b/run.go @@ -36,6 +36,8 @@ func init() { var appname string var conf struct { + // Indicates whether execute "go install" before "go build". + GoInstall bool `json:"go_install"` DirStruct struct { Controllers string Models string @@ -71,6 +73,7 @@ func runApp(cmd *Command, args []string) { // loadConfig loads customized configuration. func loadConfig() error { + fmt.Println("[INFO] Detect bee.json") f, err := os.Open("bee.json") if err != nil { // Use default. diff --git a/watch.go b/watch.go index db6bc0b..98430d2 100644 --- a/watch.go +++ b/watch.go @@ -72,10 +72,23 @@ func Autobuild() { fmt.Println("[INFO] Start building...") path, _ := os.Getwd() os.Chdir(path) - bcmd := exec.Command("go", "build") - bcmd.Stdout = os.Stdout - bcmd.Stderr = os.Stderr - err := bcmd.Run() + + var err error + // For applications use full import path like "github.com/.../.." + // are able to use "go install" to reduce build time. + if conf.GoInstall { + icmd := exec.Command("go", "install") + icmd.Stdout = os.Stdout + icmd.Stderr = os.Stderr + err = icmd.Run() + } + + if err == nil { + bcmd := exec.Command("go", "build") + bcmd.Stdout = os.Stdout + bcmd.Stderr = os.Stderr + err = bcmd.Run() + } if err != nil { fmt.Println("[ERRO] ============== Build failed ===================")