1
0
mirror of https://github.com/beego/bee.git synced 2025-06-12 15:10:39 +00:00

1. new,api,hprose 命令增加两个参数 [-module=true] [-beego=v1.12.1] 用于生成go module项目

2. generate,migrate命令不再打印GOPATH.
3. pack命令排除。
4. run命令支持传递ldflags参数
5. fix watch file bug.ignoredFilesRegExps数组对每个文件增加$,防止目录存在tmp的情况
6. getPackagePath函数被调用时如果找不到GOPATH,则看看工程有没有go.mod 有就当做go module项目处理。
7. .travis.yml检查时排除/pkg/mod/目录
This commit is contained in:
qiantao
2020-06-25 22:29:27 +08:00
parent 1334a99810
commit 9433a7b66f
13 changed files with 237 additions and 72 deletions

View File

@ -18,6 +18,7 @@ import (
"fmt"
"os"
path "path/filepath"
"runtime"
"strings"
"github.com/beego/bee/cmd/commands"
@ -27,15 +28,19 @@ import (
"github.com/beego/bee/utils"
)
var module utils.DocValue
var beegoVersion utils.DocValue
var CmdNew = &commands.Command{
UsageLine: "new [appname]",
UsageLine: "new [appname] [-module=true] [-beego=v1.12.1]",
Short: "Creates a Beego application",
Long: `
Creates a Beego application for the given app name in the current directory.
The command 'new' creates a folder named [appname] and generates the following structure:
now supoort generate a go modules project
The command 'new' creates a folder named [appname] [-module=true] [-beego=v1.12.1] and generates the following structure:
├── main.go
├── go.mod
├── {{"conf"|foldername}}
│ └── app.conf
├── {{"controllers"|foldername}}
@ -53,7 +58,7 @@ Creates a Beego application for the given app name in the current directory.
└── index.tpl
`,
PreRun: func(cmd *commands.Command, args []string) { version.ShowShortVersionBanner() },
PreRun: nil,
Run: CreateApp,
}
@ -85,7 +90,14 @@ func init() {
beego.Router("/", &controllers.MainController{})
}
`
var goMod = `
module %s
go %s
require github.com/astaxie/beego %s
require github.com/smartystreets/goconvey v1.6.4
`
var test = `package test
import (
@ -245,18 +257,39 @@ var reloadJsClient = `function b(a){var c=new WebSocket(a);c.onclose=function(){
`
func init() {
CmdNew.Flag.Var(&module, "module", "Support go modules")
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
commands.AvailableCommands = append(commands.AvailableCommands, CmdNew)
}
func CreateApp(cmd *commands.Command, args []string) int {
output := cmd.Out()
if len(args) != 1 {
if len(args) == 0 {
beeLogger.Log.Fatal("Argument [appname] is missing")
}
appPath, packPath, err := utils.CheckEnv(args[0])
if err != nil {
beeLogger.Log.Fatalf("%s", err)
if len(args) >= 2 {
cmd.Flag.Parse(args[1:])
} else {
module = "false"
}
var appPath string
var packPath string
var err error
if module != `true` {
beeLogger.Log.Info("generate new project support GOPATH")
version.ShowShortVersionBanner()
appPath, packPath, err = utils.CheckEnv(args[0])
if err != nil {
beeLogger.Log.Fatalf("%s", err)
}
} else {
beeLogger.Log.Info("generate new project support go modules.")
appPath = path.Join(utils.GetBeeWorkPath(), args[0])
packPath = args[0]
if beegoVersion.String() == `` {
beegoVersion.Set(`v1.12.1`)
}
}
if utils.IsExist(appPath) {
@ -270,6 +303,10 @@ func CreateApp(cmd *commands.Command, args []string) int {
beeLogger.Log.Info("Creating application...")
os.MkdirAll(appPath, 0755)
if module == `true` {
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, runtime.Version()[2:], beegoVersion.String()))
}
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", appPath+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "conf"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "conf")+string(path.Separator), "\x1b[0m")