From 8f0badc630fe11514030255f6f894ad0d415dbac Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Thu, 10 Sep 2020 19:35:44 +0800 Subject: [PATCH 1/9] add command "bee pro toml" for create beegopro.toml --- cmd/commands/beegopro/beegopro.go | 2 ++ internal/app/module/beegopro/container.go | 32 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/cmd/commands/beegopro/beegopro.go b/cmd/commands/beegopro/beegopro.go index e30567e..eca1036 100644 --- a/cmd/commands/beegopro/beegopro.go +++ b/cmd/commands/beegopro/beegopro.go @@ -47,6 +47,8 @@ func BeegoPro(cmd *commands.Command, args []string) int { switch gcmd { case "gen": beegopro.DefaultBeegoPro.Run() + case "toml": + beegopro.DefaultBeegoPro.InitToml() case "config": beegopro.DefaultBeegoPro.GenConfig() case "migration": diff --git a/internal/app/module/beegopro/container.go b/internal/app/module/beegopro/container.go index 3046698..cbeb9b6 100644 --- a/internal/app/module/beegopro/container.go +++ b/internal/app/module/beegopro/container.go @@ -2,16 +2,18 @@ package beegopro import ( "fmt" + "io/ioutil" + "sync" + "time" + + "github.com/davecgh/go-spew/spew" + "github.com/pelletier/go-toml" + "github.com/spf13/viper" + "github.com/beego/bee/internal/pkg/git" "github.com/beego/bee/internal/pkg/system" beeLogger "github.com/beego/bee/logger" "github.com/beego/bee/utils" - "github.com/davecgh/go-spew/spew" - "github.com/pelletier/go-toml" - "github.com/spf13/viper" - "io/ioutil" - "sync" - "time" ) const MDateFormat = "20060102_150405" @@ -60,6 +62,24 @@ func (c *Container) Run() { c.flushTimestamp() } +func (c *Container) InitToml() { + if exist := utils.IsExist(c.BeegoProFile); exist { + beeLogger.Log.Fatalf("file beegopro.toml already exists") + } + sourceFile := c.UserOption.GitLocalPath + "/beegopro.toml" + input, err := ioutil.ReadFile(sourceFile) + if err != nil { + beeLogger.Log.Fatalf("read beegopro.toml file err, %s", err.Error()) + return + } + err = ioutil.WriteFile(c.BeegoProFile, input, 0644) + if err != nil { + beeLogger.Log.Fatalf("create beegopro.toml file err, %s", err.Error()) + return + } + beeLogger.Log.Success("Successfully created file beegopro.toml") +} + func (c *Container) initUserOption() { if !utils.IsExist(c.BeegoProFile) { beeLogger.Log.Fatalf("beego pro config is not exist, beego json path: %s", c.BeegoProFile) From 81ed06ea016f15b2b93c5c06097993754d858625 Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Fri, 11 Sep 2020 01:03:44 +0800 Subject: [PATCH 2/9] get template from git when run 'bee pro toml' if template dose not exit --- internal/app/module/beegopro/container.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/app/module/beegopro/container.go b/internal/app/module/beegopro/container.go index cbeb9b6..7f99cfb 100644 --- a/internal/app/module/beegopro/container.go +++ b/internal/app/module/beegopro/container.go @@ -67,6 +67,9 @@ func (c *Container) InitToml() { beeLogger.Log.Fatalf("file beegopro.toml already exists") } sourceFile := c.UserOption.GitLocalPath + "/beegopro.toml" + if !utils.IsExist(c.UserOption.GitLocalPath) { + c.getTemplateFromGit() + } input, err := ioutil.ReadFile(sourceFile) if err != nil { beeLogger.Log.Fatalf("read beegopro.toml file err, %s", err.Error()) @@ -80,6 +83,14 @@ func (c *Container) InitToml() { beeLogger.Log.Success("Successfully created file beegopro.toml") } +func (c *Container) getTemplateFromGit() { + err := git.CloneORPullRepo(c.UserOption.GitRemotePath, c.UserOption.GitLocalPath) + if err != nil { + beeLogger.Log.Fatalf("beego pro git clone or pull repo error, err: %s", err) + return + } + c.Timestamp.GitCacheLastRefresh = c.GenerateTimeUnix +} func (c *Container) initUserOption() { if !utils.IsExist(c.BeegoProFile) { beeLogger.Log.Fatalf("beego pro config is not exist, beego json path: %s", c.BeegoProFile) @@ -124,12 +135,7 @@ func (c *Container) initUserOption() { func (c *Container) initTemplateOption() { if c.UserOption.EnableGitPull && (c.GenerateTimeUnix-c.Timestamp.GitCacheLastRefresh > c.UserOption.RefreshGitTime) { - err := git.CloneORPullRepo(c.UserOption.GitRemotePath, c.UserOption.GitLocalPath) - if err != nil { - beeLogger.Log.Fatalf("beego pro git clone or pull repo error, err: %s", err) - return - } - c.Timestamp.GitCacheLastRefresh = c.GenerateTimeUnix + c.getTemplateFromGit() } tree, err := toml.LoadFile(c.UserOption.GitLocalPath + "/" + c.UserOption.ProType + "/bee.toml") From 7a7357a983aac9afc2686c7a7ea48ec6f5f982c1 Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Mon, 14 Sep 2020 23:27:33 +0800 Subject: [PATCH 3/9] print lastPushedTime & update readme.md --- README.md | 242 +++++++++++++++---------- cmd/commands/update/update.go | 5 +- cmd/commands/version/banner.go | 3 + cmd/commands/version/version.go | 3 +- config/conf.go | 3 +- internal/app/module/beegopro/config.go | 2 + internal/app/module/beegopro/render.go | 3 +- internal/app/module/beegopro/util.go | 10 +- utils/utils.go | 69 ++++++- 9 files changed, 230 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index 04fd01c..8381f7d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Bee provides a variety of commands which can be helpful at various stages of dev api Creates a Beego API application bale Transforms non-Go files to Go source files fix Fixes your application by making it compatible with newer versions of Beego + pro Source code generator dlv Start a debugging session using Delve dockerize Generates a Dockerfile for your Beego application generate Source code generator @@ -49,7 +50,8 @@ Bee provides a variety of commands which can be helpful at various stages of dev pack Compresses a Beego application into a single file rs Run customized scripts run Run the application by starting a local development server - + server serving static content over HTTP on port + update Update Bee ``` ### bee version @@ -63,17 +65,17 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 +\____/ \___| \___| v1.12.1 -├── Beego : 1.7.2 -├── GoVersion : go1.7.4 -├── GOOS : linux +├── Beego : 1.12.2 +├── GoVersion : go1.14.1 +├── GOOS : darwin ├── GOARCH : amd64 -├── NumCPU : 2 +├── NumCPU : 4 ├── GOPATH : /home/beeuser/.go -├── GOROOT : /usr/lib/go +├── GOROOT : /usr/local/Cellar/go/1.14.1/libexec ├── Compiler : gc -└── Date : Monday, 26 Dec 2016 +└── UpdatedAt : 2020-09-13 ``` You can also change the output format using `-o` flag: @@ -81,15 +83,16 @@ You can also change the output format using `-o` flag: ```bash $ bee version -o json { - "GoVersion": "go1.7.4", - "GOOS": "linux", + "GoVersion": "go1.14.1", + "GOOS": "darwin", "GOARCH": "amd64", - "NumCPU": 2, + "NumCPU": 4, "GOPATH": "/home/beeuser/.go", - "GOROOT": "/usr/lib/go", + "GOROOT": "/usr/local/Cellar/go/1.14.1/libexec", "Compiler": "gc", - "BeeVersion": "1.6.2", - "BeegoVersion": "1.7.2" + "BeeVersion": "1.12.1", + "BeegoVersion": "1.12.2", + "UpdatedAt": "2020-09-13" } ``` @@ -101,31 +104,27 @@ To create a new Beego web application: ```bash $ bee new my-web-app -______ -| ___ \ -| |_/ / ___ ___ -| ___ \ / _ \ / _ \ -| |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 -2016/12/26 22:28:11 INFO ▶ 0001 Creating application... - create /home/beeuser/.go/src/github.com/user/my-web-app/ - create /home/beeuser/.go/src/github.com/user/my-web-app/conf/ - create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/ - create /home/beeuser/.go/src/github.com/user/my-web-app/models/ - create /home/beeuser/.go/src/github.com/user/my-web-app/routers/ - create /home/beeuser/.go/src/github.com/user/my-web-app/tests/ - create /home/beeuser/.go/src/github.com/user/my-web-app/static/ - create /home/beeuser/.go/src/github.com/user/my-web-app/static/js/ - create /home/beeuser/.go/src/github.com/user/my-web-app/static/css/ - create /home/beeuser/.go/src/github.com/user/my-web-app/static/img/ - create /home/beeuser/.go/src/github.com/user/my-web-app/views/ - create /home/beeuser/.go/src/github.com/user/my-web-app/conf/app.conf - create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/default.go - create /home/beeuser/.go/src/github.com/user/my-web-app/views/index.tpl - create /home/beeuser/.go/src/github.com/user/my-web-app/routers/router.go - create /home/beeuser/.go/src/github.com/user/my-web-app/tests/default_test.go - create /home/beeuser/.go/src/github.com/user/my-web-app/main.go -2016/12/26 22:28:11 SUCCESS ▶ 0002 New application successfully created! +2020/09/14 22:28:51 INFO ▶ 0001 generate new project support go modules. +2020/09/14 22:28:51 INFO ▶ 0002 Creating application... + create /Users/beeuser/learn/my-web-app/go.mod + create /Users/beeuser/learn/my-web-app/ + create /Users/beeuser/learn/my-web-app/conf/ + create /Users/beeuser/learn/my-web-app/controllers/ + create /Users/beeuser/learn/my-web-app/models/ + create /Users/beeuser/learn/my-web-app/routers/ + create /Users/beeuser/learn/my-web-app/tests/ + create /Users/beeuser/learn/my-web-app/static/ + create /Users/beeuser/learn/my-web-app/static/js/ + create /Users/beeuser/learn/my-web-app/static/css/ + create /Users/beeuser/learn/my-web-app/static/img/ + create /Users/beeuser/learn/my-web-app/views/ + create /Users/beeuser/learn/my-web-app/conf/app.conf + create /Users/beeuser/learn/my-web-app/controllers/default.go + create /Users/beeuser/learn/my-web-app/views/index.tpl + create /Users/beeuser/learn/my-web-app/routers/router.go + create /Users/beeuser/learn/my-web-app/tests/default_test.go + create /Users/beeuser/learn/my-web-app/main.go +2020/09/14 22:28:51 SUCCESS ▶ 0003 New application successfully created! ``` For more information on the usage, run `bee help new`. @@ -138,12 +137,6 @@ To run the application we just created, you can navigate to the application fold $ cd my-web-app && bee run ``` -Or from anywhere in your machine: - -``` -$ bee run github.com/user/my-web-app -``` - For more information on the usage, run `bee help run`. ### bee pack @@ -157,7 +150,7 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 +\____/ \___| \___| v1.12.1 2016/12/26 22:29:29 INFO ▶ 0001 Packaging application on '/home/beeuser/.go/src/github.com/user/my-web-app'... 2016/12/26 22:29:29 INFO ▶ 0002 Building application... 2016/12/26 22:29:29 INFO ▶ 0003 Using: GOOS=linux GOARCH=amd64 @@ -213,23 +206,25 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 -2016/12/26 22:30:12 INFO ▶ 0001 Creating API... - create /home/beeuser/.go/src/github.com/user/my-api - create /home/beeuser/.go/src/github.com/user/my-api/conf - create /home/beeuser/.go/src/github.com/user/my-api/controllers - create /home/beeuser/.go/src/github.com/user/my-api/tests - create /home/beeuser/.go/src/github.com/user/my-api/conf/app.conf - create /home/beeuser/.go/src/github.com/user/my-api/models - create /home/beeuser/.go/src/github.com/user/my-api/routers/ - create /home/beeuser/.go/src/github.com/user/my-api/controllers/object.go - create /home/beeuser/.go/src/github.com/user/my-api/controllers/user.go - create /home/beeuser/.go/src/github.com/user/my-api/tests/default_test.go - create /home/beeuser/.go/src/github.com/user/my-api/routers/router.go - create /home/beeuser/.go/src/github.com/user/my-api/models/object.go - create /home/beeuser/.go/src/github.com/user/my-api/models/user.go - create /home/beeuser/.go/src/github.com/user/my-api/main.go -2016/12/26 22:30:12 SUCCESS ▶ 0002 New API successfully created! +\____/ \___| \___| v1.12.1 +2020/09/14 22:35:11 INFO ▶ 0001 generate api project support go modules. +2020/09/14 22:35:11 INFO ▶ 0002 Creating API... + create /Users/beeuser/code/learn/my-api/go.mod + create /Users/beeuser/code/learn/my-api + create /Users/beeuser/code/learn/my-api/conf + create /Users/beeuser/code/learn/my-api/controllers + create /Users/beeuser/code/learn/my-api/tests + create /Users/beeuser/code/learn/my-api/conf/app.conf + create /Users/beeuser/code/learn/my-api/models + create /Users/beeuser/code/learn/my-api/routers/ + create /Users/beeuser/code/learn/my-api/controllers/object.go + create /Users/beeuser/code/learn/my-api/controllers/user.go + create /Users/beeuser/code/learn/my-api/tests/default_test.go + create /Users/beeuser/code/learn/my-api/routers/router.go + create /Users/beeuser/code/learn/my-api/models/object.go + create /Users/beeuser/code/learn/my-api/models/user.go + create /Users/beeuser/code/learn/my-api/main.go +2020/09/14 22:35:11 SUCCESS ▶ 0003 New API successfully created! ``` For more information on the usage, run `bee help api`. @@ -245,26 +240,18 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 -2016/12/26 22:30:58 INFO ▶ 0001 Creating application... - create /home/beeuser/.go/src/github.com/user/my-rpc-app/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/conf/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/controllers/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/models/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/routers/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/tests/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/js/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/css/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/static/img/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/views/ - create /home/beeuser/.go/src/github.com/user/my-rpc-app/conf/app.conf - create /home/beeuser/.go/src/github.com/user/my-rpc-app/controllers/default.go - create /home/beeuser/.go/src/github.com/user/my-rpc-app/views/index.tpl - create /home/beeuser/.go/src/github.com/user/my-rpc-app/routers/router.go - create /home/beeuser/.go/src/github.com/user/my-rpc-app/tests/default_test.go - create /home/beeuser/.go/src/github.com/user/my-rpc-app/main.go -2016/12/26 22:30:58 SUCCESS ▶ 0002 New application successfully created! +\____/ \___| \___| v1.12.1 +2020/09/14 22:36:39 INFO ▶ 0001 generate api project support go modules. +2020/09/14 22:36:39 INFO ▶ 0002 Creating Hprose application... + create /Users/beeuser/code/learn/my-rpc-app/go.mod + create /Users/beeuser/code/learn/my-rpc-app + create /Users/beeuser/code/learn/my-rpc-app/conf + create /Users/beeuser/code/learn/my-rpc-app/conf/app.conf + create /Users/beeuser/code/learn/my-rpc-app/models + create /Users/beeuser/code/learn/my-rpc-app/models/object.go + create /Users/beeuser/code/learn/my-rpc-app/models/user.go + create /Users/beeuser/code/learn/my-rpc-app/main.go +2020/09/14 22:36:39 SUCCESS ▶ 0003 New Hprose application successfully created! ``` For more information on the usage, run `bee help hprose`. @@ -280,9 +267,8 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 -2016/12/26 22:32:41 INFO ▶ 0001 Loading configuration from 'bee.json'... -2016/12/26 22:32:41 SUCCESS ▶ 0002 Baled resources successfully! +\____/ \___| \___| v1.12.1 +2020/09/14 22:37:56 SUCCESS ▶ 0001 Baled resources successfully! ``` For more information on the usage, run `bee help bale`. @@ -306,11 +292,11 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 -2016/12/26 22:33:58 INFO ▶ 0001 Using 'Hello' as controller name -2016/12/26 22:33:58 INFO ▶ 0002 Using 'controllers' as package name - create /home/beeuser/.go/src/github.com/user/my-web-app/controllers/hello.go -2016/12/26 22:33:58 SUCCESS ▶ 0003 Controller successfully generated! +\____/ \___| \___| v1.12.1 +2020/09/14 22:38:44 INFO ▶ 0001 Using 'Hello' as controller name +2020/09/14 22:38:44 INFO ▶ 0002 Using 'controllers' as package name + create /Users/beeuser/code/learn/my-api/controllers/hello.go +2020/09/14 22:38:44 SUCCESS ▶ 0003 Controller successfully generated! ``` For more information on the usage, run `bee help generate`. @@ -328,9 +314,9 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.6.2 -2016/12/26 22:34:54 INFO ▶ 0001 Generating Dockerfile... -2016/12/26 22:34:54 SUCCESS ▶ 0002 Dockerfile generated. +\____/ \___| \___| v1.12.1 +2020/09/14 22:40:12 INFO ▶ 0001 Generating Dockerfile... +2020/09/14 22:40:12 SUCCESS ▶ 0002 Dockerfile generated. ``` For more information on the usage, run `bee help dockerize`. @@ -345,8 +331,8 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v1.8.0 -2017/03/22 11:17:05 INFO ▶ 0001 Starting Delve Debugger... +\____/ \___| \___| v1.12.1 +2020/09/14 22:40:12 INFO ▶ 0001 Starting Delve Debugger... Type 'help' for list of commands. (dlv) break main.main Breakpoint 1 set at 0x40100f for main.main() ./main.go:8 @@ -366,6 +352,68 @@ Breakpoint 1 set at 0x40100f for main.main() ./main.go:8 For more information on the usage, run `bee help dlv`. +### bee pro + +#### bee pro toml + +To create a beegopro.toml file + +```bash +$ bee pro toml +2020/09/14 22:51:18 SUCCESS ▶ 0001 Successfully created file beegopro.toml +2020/09/14 22:51:18 SUCCESS ▶ 0002 Toml successfully generated! +``` + +#### bee pro gen + +Source code generator by beegopro.toml + +```bash +$ bee pro gen +2020/09/14 23:01:13 INFO ▶ 0001 Create /Users/beeuser/.beego/beego-pro Success! +2020/09/14 23:01:13 INFO ▶ 0002 git pull /Users/beeuser/.beego/beego-pro +2020/09/14 23:01:15 INFO ▶ 0003 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0004 Using 'example' as package name from controllers +2020/09/14 23:01:15 INFO ▶ 0005 create file '/Users/beeuser/code/learn/my-web-app/controllers/bee_default_controller.go' from controllers +2020/09/14 23:01:15 INFO ▶ 0006 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0007 Using 'example' as package name from controllers +2020/09/14 23:01:15 INFO ▶ 0008 create file '/Users/beeuser/code/learn/my-web-app/controllers/example.go' from controllers +2020/09/14 23:01:15 INFO ▶ 0009 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0010 Using 'example' as package name from models +2020/09/14 23:01:15 INFO ▶ 0011 create file '/Users/beeuser/code/learn/my-web-app/models/bee_default_model.go' from models +2020/09/14 23:01:15 INFO ▶ 0012 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0013 Using 'example' as package name from models +2020/09/14 23:01:15 INFO ▶ 0014 create file '/Users/beeuser/code/learn/my-web-app/models/example.go' from models +2020/09/14 23:01:15 INFO ▶ 0015 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0016 Using 'example' as package name from routers +2020/09/14 23:01:15 INFO ▶ 0017 create file '/Users/beeuser/code/learn/my-web-app/routers/example.go' from routers +2020/09/14 23:01:15 INFO ▶ 0018 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0019 Using 'example' as package name from example +2020/09/14 23:01:15 INFO ▶ 0020 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/list.tsx' from example +2020/09/14 23:01:15 INFO ▶ 0021 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0022 Using 'example' as package name from example +2020/09/14 23:01:15 INFO ▶ 0023 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/formconfig.tsx' from example +2020/09/14 23:01:15 INFO ▶ 0024 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0025 Using 'example' as package name from example +2020/09/14 23:01:15 INFO ▶ 0026 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/create.tsx' from example +2020/09/14 23:01:15 INFO ▶ 0027 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0028 Using 'example' as package name from example +2020/09/14 23:01:15 INFO ▶ 0029 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/update.tsx' from example +2020/09/14 23:01:15 INFO ▶ 0030 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0031 Using 'example' as package name from example +2020/09/14 23:01:15 INFO ▶ 0032 create file '/Users/beeuser/code/learn/my-web-app/ant/src/pages/example/info.tsx' from example +2020/09/14 23:01:15 INFO ▶ 0033 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0034 Using 'example' as package name from sql +2020/09/14 23:01:15 INFO ▶ 0035 create file '/Users/beeuser/code/learn/my-web-app/sql/example_up.sql' from sql +2020/09/14 23:01:15 INFO ▶ 0036 2020/09/14 23:01:15 INFO ▶ 0001 db exec info ./sql/example_up.sql +2020/09/14 23:01:15 SUCCESS ▶ 0002 Migration successfully generated! +2020/09/14 23:01:15 INFO ▶ 0037 Using 'example' as name +2020/09/14 23:01:15 INFO ▶ 0038 Using 'example' as package name from sql +2020/09/14 23:01:15 INFO ▶ 0039 create file '/Users/beeuser/code/learn/my-web-app/sql/example_down.sql' from sql +2020/09/14 23:01:15 SUCCESS ▶ 0040 Gen successfully generated! +``` + +#### ## Shortcuts Because you'll likely type these generator commands over and over, it makes sense to create aliases: @@ -520,7 +568,7 @@ Rebasing will update your branch with the most recent code and make your changes ## Licence ```text -Copyright 2016 bee authors +Copyright 2020 bee authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cmd/commands/update/update.go b/cmd/commands/update/update.go index 3e5a87a..53fbae1 100644 --- a/cmd/commands/update/update.go +++ b/cmd/commands/update/update.go @@ -8,6 +8,7 @@ import ( "github.com/beego/bee/cmd/commands" "github.com/beego/bee/config" beeLogger "github.com/beego/bee/logger" + "github.com/beego/bee/utils" ) var CmdUpdate = &commands.Command{ @@ -32,7 +33,9 @@ func updateBee(cmd *commands.Command, args []string) int { cmdUp.Stdout = os.Stdout cmdUp.Stderr = os.Stderr if err := cmdUp.Run(); err != nil { - beeLogger.Log.Warnf("Run cmd err:%s",err) + beeLogger.Log.Warnf("Run cmd err:%s", err) } + // update the pushedTime when updateBee every time + utils.UpdateLastPushedTime() return 0 } diff --git a/cmd/commands/version/banner.go b/cmd/commands/version/banner.go index 0ab367d..34e423f 100644 --- a/cmd/commands/version/banner.go +++ b/cmd/commands/version/banner.go @@ -10,6 +10,7 @@ import ( "time" beeLogger "github.com/beego/bee/logger" + "github.com/beego/bee/utils" ) // RuntimeInfo holds information about the current runtime. @@ -23,6 +24,7 @@ type RuntimeInfo struct { Compiler string BeeVersion string BeegoVersion string + UpdatedAt string } // InitBanner loads the banner and prints it to output @@ -60,6 +62,7 @@ func show(out io.Writer, content string) { runtime.Compiler, version, GetBeegoVersion(), + utils.GetLastPushedTime(), }) if err != nil { beeLogger.Log.Error(err.Error()) diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index 32862a7..45ee688 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -38,7 +38,7 @@ const verboseVersionBanner string = `%s%s______ ├── GOPATH : {{ .GOPATH }} ├── GOROOT : {{ .GOROOT }} ├── Compiler : {{ .Compiler }} -└── Date : {{ Now "Monday, 2 Jan 2006" }}%s +└── UpdatedAt : {{ .UpdatedAt }}%s ` const shortVersionBanner = `______ @@ -84,6 +84,7 @@ func versionCmd(cmd *commands.Command, args []string) int { runtime.Compiler, version, GetBeegoVersion(), + utils.GetLastPushedTime(), } switch outputFormat { case "json": diff --git a/config/conf.go b/config/conf.go index e0603e9..80fa2a2 100644 --- a/config/conf.go +++ b/config/conf.go @@ -27,11 +27,10 @@ import ( const confVer = 0 const ( - Version = "1.12.0" + Version = "1.12.1" GitRemotePath = "github.com/beego/bee" ) - var Conf = struct { Version int WatchExts []string `json:"watch_ext" yaml:"watch_ext"` diff --git a/internal/app/module/beegopro/config.go b/internal/app/module/beegopro/config.go index 7fbdc2c..716533c 100644 --- a/internal/app/module/beegopro/config.go +++ b/internal/app/module/beegopro/config.go @@ -5,7 +5,9 @@ import ( beeLogger "github.com/beego/bee/logger" "io/ioutil" ) + var CompareExcept = []string{"@BeeGenerateTime"} + func (c *Container) GenConfig() { if utils.IsExist(c.BeegoProFile) { beeLogger.Log.Fatalf("beego pro toml exist") diff --git a/internal/app/module/beegopro/render.go b/internal/app/module/beegopro/render.go index 7ca1464..3721621 100644 --- a/internal/app/module/beegopro/render.go +++ b/internal/app/module/beegopro/render.go @@ -123,7 +123,7 @@ func (r *RenderFile) Exec(name string) { var orgContent []byte if err == nil { if org, err := os.OpenFile(r.Descriptor.DstPath, os.O_RDONLY, 0666); err == nil { - orgContent,_ = ioutil.ReadAll(org) + orgContent, _ = ioutil.ReadAll(org) org.Close() } else { beeLogger.Log.Infof("file err %s", err) @@ -151,4 +151,3 @@ func (r *RenderFile) Exec(name string) { beeLogger.Log.Infof("create file '%s' from %s", r.FlushFile, r.PackageName) } } - diff --git a/internal/app/module/beegopro/util.go b/internal/app/module/beegopro/util.go index 604e404..22a668a 100644 --- a/internal/app/module/beegopro/util.go +++ b/internal/app/module/beegopro/util.go @@ -173,14 +173,14 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) { return } -func FileContentChange(org,new []byte, seg string) bool { +func FileContentChange(org, new []byte, seg string) bool { if len(org) == 0 { return true } - orgContent := GetFilterContent(string(org),seg) - newContent := GetFilterContent(string(new),seg) + orgContent := GetFilterContent(string(org), seg) + newContent := GetFilterContent(string(new), seg) orgMd5 := md5.Sum([]byte(orgContent)) - newMd5:= md5.Sum([]byte(newContent)) + newMd5 := md5.Sum([]byte(newContent)) if orgMd5 != newMd5 { return true } @@ -193,7 +193,7 @@ func GetFilterContent(content string, seg string) string { for _, s := range strings.Split(content, "\n") { s = strings.TrimSpace(strings.TrimPrefix(s, seg)) var have bool - for _,except := range CompareExcept{ + for _, except := range CompareExcept { if strings.HasPrefix(s, except) { have = true } diff --git a/utils/utils.go b/utils/utils.go index e9656dc..13ce892 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -39,7 +39,12 @@ import ( ) type tagName struct { - Name string `json:"name"` + Name string `json:"name"` +} + +type Repos struct { + UpdatedAt time.Time `json:"updated_at"` + PushedAt time.Time `json:"pushed_at"` } func GetBeeWorkPath() string { @@ -521,7 +526,7 @@ func NoticeUpdateBee() { beeLogger.Log.Info("Getting bee latest version...") versionLast := BeeLastVersion() versionNow := config.Version - if versionLast == ""{ + if versionLast == "" { beeLogger.Log.Warn("Get latest version err") return } @@ -559,3 +564,63 @@ func BeeLastVersion() (version string) { beeLogger.Log.Warn("There is no tags!") return } + +// get info of repos bee +func BeeReposInfo() (repos Repos) { + var url = "https://api.github.com/repos/beego/bee" + resp, err := http.Get(url) + if err != nil { + beeLogger.Log.Warnf("Get bee repos from github error: %s", err) + return + } + defer resp.Body.Close() + bodyContent, _ := ioutil.ReadAll(resp.Body) + if err = json.Unmarshal(bodyContent, &repos); err != nil { + beeLogger.Log.Warnf("Unmarshal repos body error: %s", err) + return + } + return +} + +//TODO UpdateLastTime and NoticeUpdateBee +func UpdateLastPushedTime() { + info := BeeReposInfo() + createdAt := info.PushedAt.Format("2006-01-02") + beeHome := system.BeegoHome + if !IsExist(beeHome) { + if err := os.MkdirAll(beeHome, 0755); err != nil { + beeLogger.Log.Fatalf("Could not create the directory: %s", err) + return + } + } + fp := beeHome + "/.lastUpdatedAt" + w, err := os.OpenFile(fp, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) + if err != nil { + beeLogger.Log.Warnf("Open .lastUpdatedAt file err: %s", err) + return + } + defer w.Close() + if _, err := w.WriteString(createdAt); err != nil { + beeLogger.Log.Warnf("Update lastUpdatedAt file err: %s", err) + return + } +} + +func GetLastPushedTime() string { + fp := system.BeegoHome + "/.lastUpdatedAt" + if !IsExist(fp) { + UpdateLastPushedTime() + } + w, err := os.OpenFile(fp, os.O_RDONLY, 0644) + if err != nil { + beeLogger.Log.Warnf("Open .lastUpdatedAt file err: %s", err) + return "unknown" + } + t := make([]byte, 1024) + read, err := w.Read(t) + if err != nil { + beeLogger.Log.Warnf("read .lastUpdatedAt file err: %s", err) + return "unknown" + } + return string(t[:read]) +} From 674b52a73293020962da23e140b6b25e7956f8fe Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Tue, 15 Sep 2020 00:05:38 +0800 Subject: [PATCH 4/9] change updatedTime to publishedTime --- cmd/commands/update/update.go | 4 +-- cmd/commands/version/banner.go | 4 +-- cmd/commands/version/version.go | 4 +-- utils/utils.go | 53 +++++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/cmd/commands/update/update.go b/cmd/commands/update/update.go index 53fbae1..cc28ff6 100644 --- a/cmd/commands/update/update.go +++ b/cmd/commands/update/update.go @@ -35,7 +35,7 @@ func updateBee(cmd *commands.Command, args []string) int { if err := cmdUp.Run(); err != nil { beeLogger.Log.Warnf("Run cmd err:%s", err) } - // update the pushedTime when updateBee every time - utils.UpdateLastPushedTime() + // update the Time when updateBee every time + utils.UpdateLastPublishedTime() return 0 } diff --git a/cmd/commands/version/banner.go b/cmd/commands/version/banner.go index 34e423f..a78b714 100644 --- a/cmd/commands/version/banner.go +++ b/cmd/commands/version/banner.go @@ -24,7 +24,7 @@ type RuntimeInfo struct { Compiler string BeeVersion string BeegoVersion string - UpdatedAt string + Published string } // InitBanner loads the banner and prints it to output @@ -62,7 +62,7 @@ func show(out io.Writer, content string) { runtime.Compiler, version, GetBeegoVersion(), - utils.GetLastPushedTime(), + utils.GetLastPublishedTime(), }) if err != nil { beeLogger.Log.Error(err.Error()) diff --git a/cmd/commands/version/version.go b/cmd/commands/version/version.go index 45ee688..7b00939 100644 --- a/cmd/commands/version/version.go +++ b/cmd/commands/version/version.go @@ -38,7 +38,7 @@ const verboseVersionBanner string = `%s%s______ ├── GOPATH : {{ .GOPATH }} ├── GOROOT : {{ .GOROOT }} ├── Compiler : {{ .Compiler }} -└── UpdatedAt : {{ .UpdatedAt }}%s +└── Published : {{ .Published }}%s ` const shortVersionBanner = `______ @@ -84,7 +84,7 @@ func versionCmd(cmd *commands.Command, args []string) int { runtime.Compiler, version, GetBeegoVersion(), - utils.GetLastPushedTime(), + utils.GetLastPublishedTime(), } switch outputFormat { case "json": diff --git a/utils/utils.go b/utils/utils.go index 13ce892..2dd5a47 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -47,6 +47,11 @@ type Repos struct { PushedAt time.Time `json:"pushed_at"` } +type Releases struct { + PublishedAt time.Time `json:"published_at"` + TagName string `json:"tag_name"` +} + func GetBeeWorkPath() string { curpath, err := os.Getwd() if err != nil { @@ -565,7 +570,7 @@ func BeeLastVersion() (version string) { return } -// get info of repos bee +// get info of bee repos func BeeReposInfo() (repos Repos) { var url = "https://api.github.com/repos/beego/bee" resp, err := http.Get(url) @@ -582,10 +587,32 @@ func BeeReposInfo() (repos Repos) { return } -//TODO UpdateLastTime and NoticeUpdateBee -func UpdateLastPushedTime() { - info := BeeReposInfo() - createdAt := info.PushedAt.Format("2006-01-02") +// get info of bee releases +func BeeReleasesInfo() (repos []Releases) { + var url = "https://api.github.com/repos/beego/bee/releases" + resp, err := http.Get(url) + if err != nil { + beeLogger.Log.Warnf("Get bee releases from github error: %s", err) + return + } + defer resp.Body.Close() + bodyContent, _ := ioutil.ReadAll(resp.Body) + if err = json.Unmarshal(bodyContent, &repos); err != nil { + beeLogger.Log.Warnf("Unmarshal releases body error: %s", err) + return + } + return +} + +//TODO merge UpdateLastPublishedTime and NoticeUpdateBee +func UpdateLastPublishedTime() { + info := BeeReleasesInfo() + fmt.Printf("%+v", info) + if len(info) == 0 { + beeLogger.Log.Warn("Has no releases") + return + } + createdAt := info[0].PublishedAt.Format("2006-01-02") beeHome := system.BeegoHome if !IsExist(beeHome) { if err := os.MkdirAll(beeHome, 0755); err != nil { @@ -593,33 +620,33 @@ func UpdateLastPushedTime() { return } } - fp := beeHome + "/.lastUpdatedAt" + fp := beeHome + "/.lastPublishedAt" w, err := os.OpenFile(fp, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) if err != nil { - beeLogger.Log.Warnf("Open .lastUpdatedAt file err: %s", err) + beeLogger.Log.Warnf("Open .lastPublishedAt file err: %s", err) return } defer w.Close() if _, err := w.WriteString(createdAt); err != nil { - beeLogger.Log.Warnf("Update lastUpdatedAt file err: %s", err) + beeLogger.Log.Warnf("Update .lastPublishedAt file err: %s", err) return } } -func GetLastPushedTime() string { - fp := system.BeegoHome + "/.lastUpdatedAt" +func GetLastPublishedTime() string { + fp := system.BeegoHome + "/.lastPublishedAt" if !IsExist(fp) { - UpdateLastPushedTime() + UpdateLastPublishedTime() } w, err := os.OpenFile(fp, os.O_RDONLY, 0644) if err != nil { - beeLogger.Log.Warnf("Open .lastUpdatedAt file err: %s", err) + beeLogger.Log.Warnf("Open .lastPublishedAt file err: %s", err) return "unknown" } t := make([]byte, 1024) read, err := w.Read(t) if err != nil { - beeLogger.Log.Warnf("read .lastUpdatedAt file err: %s", err) + beeLogger.Log.Warnf("read .lastPublishedAt file err: %s", err) return "unknown" } return string(t[:read]) From 3ea61a89262c970b8a4669a71a86c0ad06c13a8b Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Tue, 15 Sep 2020 00:09:05 +0800 Subject: [PATCH 5/9] update readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8381f7d..49dc995 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ ______ ├── GOPATH : /home/beeuser/.go ├── GOROOT : /usr/local/Cellar/go/1.14.1/libexec ├── Compiler : gc -└── UpdatedAt : 2020-09-13 +└── Published : 2020-09-13 ``` You can also change the output format using `-o` flag: @@ -92,7 +92,7 @@ $ bee version -o json "Compiler": "gc", "BeeVersion": "1.12.1", "BeegoVersion": "1.12.2", - "UpdatedAt": "2020-09-13" + "Published": "2020-09-13" } ``` From 1605bacc9e203d4fcf1d6929abc52cf98a1a880b Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Tue, 15 Sep 2020 00:14:34 +0800 Subject: [PATCH 6/9] fix --- utils/utils.go | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 2dd5a47..a233231 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -607,7 +607,6 @@ func BeeReleasesInfo() (repos []Releases) { //TODO merge UpdateLastPublishedTime and NoticeUpdateBee func UpdateLastPublishedTime() { info := BeeReleasesInfo() - fmt.Printf("%+v", info) if len(info) == 0 { beeLogger.Log.Warn("Has no releases") return From 62abed87e95fe90cae0cc2620c10406a6c1be97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8E=9A=E4=BC=9F?= Date: Thu, 26 Nov 2020 14:01:59 +0800 Subject: [PATCH 7/9] change readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 97acc53..24926c2 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ ______ | |_/ /| __/| __/ \____/ \___| \___| v2.0.0 -├── Beego : 2.0.02 +├── Beego : 2.0.0 ├── GoVersion : go1.14.1 ├── GOOS : darwin ├── GOARCH : amd64 @@ -91,7 +91,7 @@ $ bee version -o json "GOROOT": "/usr/local/Cellar/go/1.14.1/libexec", "Compiler": "gc", "BeeVersion": "2.0.0", - "BeegoVersion": "2.0.02", + "BeegoVersion": "2.0.0", "Published": "2020-09-13" } ``` @@ -331,7 +331,7 @@ ______ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v2.0.01 +\____/ \___| \___| v2.0.0 2020/09/14 22:40:12 INFO ▶ 0001 Starting Delve Debugger... Type 'help' for list of commands. (dlv) break main.main From b8213eba24f1fed956a8a34dc189544dba4bee96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8E=9A=E4=BC=9F?= Date: Thu, 26 Nov 2020 14:15:00 +0800 Subject: [PATCH 8/9] add InitToml and fmt code --- cmd/commands/beefix/fix.go | 2 +- cmd/commands/beefix/fix1To2.go | 4 ++-- cmd/commands/beefix/fixTo1.6.go | 3 +-- internal/app/module/beegopro/container.go | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/commands/beefix/fix.go b/cmd/commands/beefix/fix.go index 5090881..9cde22e 100644 --- a/cmd/commands/beefix/fix.go +++ b/cmd/commands/beefix/fix.go @@ -36,7 +36,7 @@ func init() { func runFix(cmd *commands.Command, args []string) int { t := target.String() - if t == "" || t == "1.6"{ + if t == "" || t == "1.6" { return fixTo16(cmd, args) } else if strings.HasPrefix(t, "2") { // upgrade to v2 diff --git a/cmd/commands/beefix/fix1To2.go b/cmd/commands/beefix/fix1To2.go index 28365f7..30cd06b 100644 --- a/cmd/commands/beefix/fix1To2.go +++ b/cmd/commands/beefix/fix1To2.go @@ -1,4 +1,4 @@ -// Copyright 2020 +// Copyright 2020 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,4 +46,4 @@ func runShell(cmdStr string) error { return err } return nil -} \ No newline at end of file +} diff --git a/cmd/commands/beefix/fixTo1.6.go b/cmd/commands/beefix/fixTo1.6.go index 8e38f67..400ad1e 100644 --- a/cmd/commands/beefix/fixTo1.6.go +++ b/cmd/commands/beefix/fixTo1.6.go @@ -1,4 +1,4 @@ -// Copyright 2020 +// Copyright 2020 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -228,4 +228,3 @@ func fixFile(file string) error { } return ioutil.WriteFile(file, []byte(fixed), 0666) } - diff --git a/internal/app/module/beegopro/container.go b/internal/app/module/beegopro/container.go index 69c9084..b579671 100644 --- a/internal/app/module/beegopro/container.go +++ b/internal/app/module/beegopro/container.go @@ -208,3 +208,21 @@ func (c *Container) flushTimestamp() { beeLogger.Log.Fatalf("flush timestamp tmpl parse error, err: %s", err) } } + +func (c *Container) InitToml() { + if exist := utils.IsExist(c.BeegoProFile); exist { + beeLogger.Log.Fatalf("file beegopro.toml already exists") + } + sourceFile := c.UserOption.GitLocalPath + "/beegopro.toml" + input, err := ioutil.ReadFile(sourceFile) + if err != nil { + beeLogger.Log.Fatalf("read beegopro.toml file err, %s", err.Error()) + return + } + err = ioutil.WriteFile(c.BeegoProFile, input, 0644) + if err != nil { + beeLogger.Log.Fatalf("create beegopro.toml file err, %s", err.Error()) + return + } + beeLogger.Log.Success("Successfully created file beegopro.toml") +} \ No newline at end of file From f1509569812ffc5c1afc2cf40a21b500fbc41335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8E=9A=E4=BC=9F?= Date: Tue, 22 Dec 2020 23:52:19 +0800 Subject: [PATCH 9/9] fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8846f47..cb8dbe1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Bee is a command-line tool facilitating development of Beego-based application. ## Requirements -- Go version >= 2.0.0 +- Go version >= 1.13 ## Installation