mirror of
https://github.com/beego/bee.git
synced 2024-11-22 20:20:55 +00:00
commit
4cf209144a
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@
|
|||||||
# Folders
|
# Folders
|
||||||
_obj
|
_obj
|
||||||
_test
|
_test
|
||||||
|
.idea
|
||||||
|
|
||||||
# Architecture specific extensions/prefixes
|
# Architecture specific extensions/prefixes
|
||||||
*.[568vq]
|
*.[568vq]
|
||||||
|
20
Makefile
Normal file
20
Makefile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
.PHONY: all test clean build install
|
||||||
|
|
||||||
|
GOFLAGS ?= $(GOFLAGS:)
|
||||||
|
|
||||||
|
all: install test
|
||||||
|
|
||||||
|
build:
|
||||||
|
go build $(GOFLAGS) ./...
|
||||||
|
|
||||||
|
install:
|
||||||
|
go get $(GOFLAGS) ./...
|
||||||
|
|
||||||
|
test: install
|
||||||
|
go test $(GOFLAGS) ./...
|
||||||
|
|
||||||
|
bench: install
|
||||||
|
go test -run=NONE -bench=. $(GOFLAGS) ./...
|
||||||
|
|
||||||
|
clean:
|
||||||
|
go clean $(GOFLAGS) -i ./...
|
79
run.go
79
run.go
@ -15,6 +15,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
path "path/filepath"
|
path "path/filepath"
|
||||||
@ -32,18 +33,25 @@ it will recompile and restart the app after any modifications.
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
var mainFiles ListOpts
|
var (
|
||||||
|
mainFiles ListOpts
|
||||||
var downdoc docValue
|
downdoc docValue
|
||||||
var gendoc docValue
|
gendoc docValue
|
||||||
|
|
||||||
// The flags list of the paths excluded from watching
|
// The flags list of the paths excluded from watching
|
||||||
var excludedPaths strFlags
|
excludedPaths strFlags
|
||||||
|
|
||||||
// Pass through to -tags arg of "go build"
|
// Pass through to -tags arg of "go build"
|
||||||
var buildTags string
|
buildTags string
|
||||||
|
// Application path
|
||||||
var vendorWatch bool
|
currpath string
|
||||||
|
// Application name
|
||||||
|
appname string
|
||||||
|
// Channel to signal an Exit
|
||||||
|
exit chan bool
|
||||||
|
// Flag to watch the vendor folder
|
||||||
|
vendorWatch bool
|
||||||
|
// Current user workspace
|
||||||
|
currentGoPath string
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmdRun.Run = runApp
|
cmdRun.Run = runApp
|
||||||
@ -53,31 +61,44 @@ func init() {
|
|||||||
cmdRun.Flag.Var(&excludedPaths, "e", "Excluded paths[].")
|
cmdRun.Flag.Var(&excludedPaths, "e", "Excluded paths[].")
|
||||||
cmdRun.Flag.BoolVar(&vendorWatch, "vendor", false, "Watch vendor folder")
|
cmdRun.Flag.BoolVar(&vendorWatch, "vendor", false, "Watch vendor folder")
|
||||||
cmdRun.Flag.StringVar(&buildTags, "tags", "", "Build tags (https://golang.org/pkg/go/build/)")
|
cmdRun.Flag.StringVar(&buildTags, "tags", "", "Build tags (https://golang.org/pkg/go/build/)")
|
||||||
|
exit = make(chan bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
var appname string
|
|
||||||
|
|
||||||
func runApp(cmd *Command, args []string) int {
|
func runApp(cmd *Command, args []string) int {
|
||||||
ShowShortVersionBanner()
|
ShowShortVersionBanner()
|
||||||
|
|
||||||
exit := make(chan bool)
|
|
||||||
crupath, _ := os.Getwd()
|
|
||||||
|
|
||||||
if len(args) == 0 || args[0] == "watchall" {
|
if len(args) == 0 || args[0] == "watchall" {
|
||||||
appname = path.Base(crupath)
|
currpath, _ = os.Getwd()
|
||||||
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
|
|
||||||
|
if found, _gopath, _ := SearchGOPATHs(currpath); found {
|
||||||
|
appname = path.Base(currpath)
|
||||||
|
currentGoPath = _gopath
|
||||||
} else {
|
} else {
|
||||||
appname = args[0]
|
exitPrint(fmt.Sprintf("Bee does not support non Beego project: %s", currpath))
|
||||||
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
|
}
|
||||||
if strings.HasSuffix(appname, ".go") && isExist(path.Join(crupath, appname)) {
|
ColorLog("[INFO] Using '%s' as 'appname'\n", appname)
|
||||||
ColorLog("[WARN] The appname has conflic with crupath's file, do you want to build appname as %s\n", appname)
|
} else {
|
||||||
|
// Check if passed Bee application path/name exists in the GOPATH(s)
|
||||||
|
if found, _gopath, _path := SearchGOPATHs(args[0]); found {
|
||||||
|
currpath = _path
|
||||||
|
currentGoPath = _gopath
|
||||||
|
appname = path.Base(currpath)
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("No Beego application '%s' found in your GOPATH", args[0]))
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorLog("[INFO] Using '%s' as 'appname'\n", appname)
|
||||||
|
|
||||||
|
if strings.HasSuffix(appname, ".go") && isExist(currpath) {
|
||||||
|
ColorLog("[WARN] The appname is in conflict with currpath's file, do you want to build appname as %s\n", appname)
|
||||||
ColorLog("[INFO] Do you want to overwrite it? [yes|no]] ")
|
ColorLog("[INFO] Do you want to overwrite it? [yes|no]] ")
|
||||||
if !askForConfirmation() {
|
if !askForConfirmation() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debugf("current path:%s\n", crupath)
|
|
||||||
|
Debugf("current path:%s\n", currpath)
|
||||||
|
|
||||||
err := loadConfig()
|
err := loadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,19 +106,12 @@ func runApp(cmd *Command, args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var paths []string
|
var paths []string
|
||||||
|
readAppDirectories(currpath, &paths)
|
||||||
readAppDirectories(crupath, &paths)
|
|
||||||
|
|
||||||
// Because monitor files has some issues, we watch current directory
|
// Because monitor files has some issues, we watch current directory
|
||||||
// and ignore non-go files.
|
// and ignore non-go files.
|
||||||
gps := GetGOPATHs()
|
|
||||||
if len(gps) == 0 {
|
|
||||||
ColorLog("[ERRO] Fail to start[ %s ]\n", "$GOPATH is not set or empty")
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
gopath := gps[0]
|
|
||||||
for _, p := range conf.DirStruct.Others {
|
for _, p := range conf.DirStruct.Others {
|
||||||
paths = append(paths, strings.Replace(p, "$GOPATH", gopath, -1))
|
paths = append(paths, strings.Replace(p, "$GOPATH", currentGoPath, -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
files := []string{}
|
files := []string{}
|
||||||
@ -115,7 +129,7 @@ func runApp(cmd *Command, args []string) int {
|
|||||||
Autobuild(files, false)
|
Autobuild(files, false)
|
||||||
}
|
}
|
||||||
if downdoc == "true" {
|
if downdoc == "true" {
|
||||||
if _, err := os.Stat(path.Join(crupath, "swagger")); err != nil {
|
if _, err := os.Stat(path.Join(currpath, "swagger")); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
downloadFromURL(swaggerlink, "swagger.zip")
|
downloadFromURL(swaggerlink, "swagger.zip")
|
||||||
unzipAndDelete("swagger.zip", "swagger")
|
unzipAndDelete("swagger.zip", "swagger")
|
||||||
@ -164,7 +178,6 @@ func readAppDirectories(directory string, paths *[]string) {
|
|||||||
useDirectory = true
|
useDirectory = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
util.go
31
util.go
@ -15,13 +15,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"path"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Go is a basic promise implementation: it wraps calls a function in a goroutine
|
// Go is a basic promise implementation: it wraps calls a function in a goroutine
|
||||||
@ -173,6 +174,34 @@ func GetGOPATHs() []string {
|
|||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SearchGOPATHs(app string) (bool, string, string) {
|
||||||
|
gps := GetGOPATHs()
|
||||||
|
if len(gps) == 0 {
|
||||||
|
ColorLog("[ERRO] Fail to start [ %s ]\n", "GOPATH environment variable is not set or empty")
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lookup the application inside the user workspace(s)
|
||||||
|
for _, gopath := range gps {
|
||||||
|
var currentPath string
|
||||||
|
|
||||||
|
if !strings.Contains(app, "src") {
|
||||||
|
gopathsrc := path.Join(gopath, "src")
|
||||||
|
currentPath = path.Join(gopathsrc, app)
|
||||||
|
} else {
|
||||||
|
currentPath = app
|
||||||
|
}
|
||||||
|
|
||||||
|
if isExist(currentPath) {
|
||||||
|
if !isBeegoProject(currentPath) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return true, gopath, currentPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, "", ""
|
||||||
|
}
|
||||||
|
|
||||||
// askForConfirmation uses Scanln to parse user input. A user must type in "yes" or "no" and
|
// askForConfirmation uses Scanln to parse user input. A user must type in "yes" or "no" and
|
||||||
// then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as
|
// then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as
|
||||||
// confirmations. If the input is not recognized, it will ask again. The function does not return
|
// confirmations. If the input is not recognized, it will ask again. The function does not return
|
||||||
|
4
watch.go
4
watch.go
@ -121,8 +121,8 @@ func Autobuild(files []string, isgenerate bool) {
|
|||||||
defer state.Unlock()
|
defer state.Unlock()
|
||||||
|
|
||||||
ColorLog("[INFO] Start building...\n")
|
ColorLog("[INFO] Start building...\n")
|
||||||
path, _ := os.Getwd()
|
|
||||||
os.Chdir(path)
|
os.Chdir(currpath)
|
||||||
|
|
||||||
cmdName := "go"
|
cmdName := "go"
|
||||||
if conf.Gopm.Enable {
|
if conf.Gopm.Enable {
|
||||||
|
Loading…
Reference in New Issue
Block a user