mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
commit
9f1d5fc5eb
@ -21,6 +21,7 @@ import (
|
|||||||
_ "github.com/beego/bee/cmd/commands/bale"
|
_ "github.com/beego/bee/cmd/commands/bale"
|
||||||
_ "github.com/beego/bee/cmd/commands/beefix"
|
_ "github.com/beego/bee/cmd/commands/beefix"
|
||||||
_ "github.com/beego/bee/cmd/commands/beegopro"
|
_ "github.com/beego/bee/cmd/commands/beegopro"
|
||||||
|
_ "github.com/beego/bee/cmd/commands/dev"
|
||||||
_ "github.com/beego/bee/cmd/commands/dlv"
|
_ "github.com/beego/bee/cmd/commands/dlv"
|
||||||
_ "github.com/beego/bee/cmd/commands/dockerize"
|
_ "github.com/beego/bee/cmd/commands/dockerize"
|
||||||
_ "github.com/beego/bee/cmd/commands/generate"
|
_ "github.com/beego/bee/cmd/commands/generate"
|
||||||
|
@ -16,11 +16,12 @@ package apiapp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/bee/logger/colors"
|
|
||||||
"os"
|
"os"
|
||||||
path "path/filepath"
|
path "path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/bee/logger/colors"
|
||||||
|
|
||||||
"github.com/beego/bee/cmd/commands"
|
"github.com/beego/bee/cmd/commands"
|
||||||
"github.com/beego/bee/cmd/commands/version"
|
"github.com/beego/bee/cmd/commands/version"
|
||||||
"github.com/beego/bee/generate"
|
"github.com/beego/bee/generate"
|
||||||
|
@ -14,10 +14,11 @@
|
|||||||
package beegopro
|
package beegopro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/bee/cmd/commands"
|
"github.com/beego/bee/cmd/commands"
|
||||||
"github.com/beego/bee/internal/app/module/beegopro"
|
"github.com/beego/bee/internal/app/module/beegopro"
|
||||||
"github.com/beego/bee/logger"
|
"github.com/beego/bee/logger"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var CmdBeegoPro = &commands.Command{
|
var CmdBeegoPro = &commands.Command{
|
||||||
|
56
cmd/commands/dev/cmd.go
Normal file
56
cmd/commands/dev/cmd.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2020
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package dev
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/beego/bee/cmd/commands"
|
||||||
|
beeLogger "github.com/beego/bee/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CmdDev = &commands.Command{
|
||||||
|
CustomFlags: true,
|
||||||
|
UsageLine: "dev [command]",
|
||||||
|
Short: "Commands which used to help to develop beego and bee",
|
||||||
|
Long: `
|
||||||
|
Commands that help developer develop, build and test beego.
|
||||||
|
- githook Prepare githooks
|
||||||
|
`,
|
||||||
|
Run: Run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
commands.AvailableCommands = append(commands.AvailableCommands, CmdDev)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Run(cmd *commands.Command, args []string) int {
|
||||||
|
if len(args) < 1 {
|
||||||
|
beeLogger.Log.Fatal("Command is missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) >= 2 {
|
||||||
|
cmd.Flag.Parse(args[1:])
|
||||||
|
}
|
||||||
|
|
||||||
|
gcmd := args[0]
|
||||||
|
|
||||||
|
switch gcmd {
|
||||||
|
|
||||||
|
case "githook":
|
||||||
|
initGitHook()
|
||||||
|
default:
|
||||||
|
beeLogger.Log.Fatal("Unknown command")
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
47
cmd/commands/dev/githook.go
Normal file
47
cmd/commands/dev/githook.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2020
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package dev
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
beeLogger "github.com/beego/bee/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
var preCommit = `
|
||||||
|
goimports -w -format-only ./ \
|
||||||
|
ineffassign . \
|
||||||
|
staticcheck -show-ignored -checks "-ST1017,-U1000,-ST1005,-S1034,-S1012,-SA4006,-SA6005,-SA1019,-SA1024" ./ \
|
||||||
|
`
|
||||||
|
|
||||||
|
// for now, we simply override pre-commit file
|
||||||
|
func initGitHook() {
|
||||||
|
// pcf => pre-commit file
|
||||||
|
pcfPath := "./.git/hooks/pre-commit"
|
||||||
|
pcf, err := os.OpenFile(pcfPath, os.O_RDWR|os.O_CREATE, 0777)
|
||||||
|
if err != nil {
|
||||||
|
beeLogger.Log.Errorf("try to create or open file failed: %s, cause: %s", pcfPath, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer pcf.Close()
|
||||||
|
_, err = pcf.Write(([]byte)(preCommit))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
beeLogger.Log.Errorf("could not init githooks: %s", err.Error())
|
||||||
|
} else {
|
||||||
|
beeLogger.Log.Successf("The githooks has been added, the content is:\n %s ", preCommit)
|
||||||
|
}
|
||||||
|
}
|
@ -28,12 +28,12 @@ import (
|
|||||||
"github.com/beego/bee/cmd/commands/version"
|
"github.com/beego/bee/cmd/commands/version"
|
||||||
beeLogger "github.com/beego/bee/logger"
|
beeLogger "github.com/beego/bee/logger"
|
||||||
"github.com/beego/bee/utils"
|
"github.com/beego/bee/utils"
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
|
"github.com/gadelkareem/delve/pkg/terminal"
|
||||||
"github.com/gadelkareem/delve/service"
|
"github.com/gadelkareem/delve/service"
|
||||||
"github.com/gadelkareem/delve/service/debugger"
|
"github.com/gadelkareem/delve/service/debugger"
|
||||||
"github.com/gadelkareem/delve/service/rpc2"
|
"github.com/gadelkareem/delve/service/rpc2"
|
||||||
"github.com/gadelkareem/delve/service/rpccommon"
|
"github.com/gadelkareem/delve/service/rpccommon"
|
||||||
"github.com/gadelkareem/delve/pkg/terminal"
|
|
||||||
"github.com/fsnotify/fsnotify"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdDlv = &commands.Command{
|
var cmdDlv = &commands.Command{
|
||||||
|
@ -2,11 +2,12 @@ package hprose
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/bee/logger/colors"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/bee/logger/colors"
|
||||||
|
|
||||||
"github.com/beego/bee/cmd/commands"
|
"github.com/beego/bee/cmd/commands"
|
||||||
"github.com/beego/bee/cmd/commands/api"
|
"github.com/beego/bee/cmd/commands/api"
|
||||||
"github.com/beego/bee/cmd/commands/version"
|
"github.com/beego/bee/cmd/commands/version"
|
||||||
|
@ -32,7 +32,7 @@ func updateBee(cmd *commands.Command, args []string) int {
|
|||||||
cmdUp.Stdout = os.Stdout
|
cmdUp.Stdout = os.Stdout
|
||||||
cmdUp.Stderr = os.Stderr
|
cmdUp.Stderr = os.Stderr
|
||||||
if err := cmdUp.Run(); err != nil {
|
if err := cmdUp.Run(); err != nil {
|
||||||
beeLogger.Log.Warnf("Run cmd err:%s",err)
|
beeLogger.Log.Warnf("Run cmd err:%s", err)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ const (
|
|||||||
GitRemotePath = "github.com/beego/bee"
|
GitRemotePath = "github.com/beego/bee"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var Conf = struct {
|
var Conf = struct {
|
||||||
Version int
|
Version int
|
||||||
WatchExts []string `json:"watch_ext" yaml:"watch_ext"`
|
WatchExts []string `json:"watch_ext" yaml:"watch_ext"`
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package beegopro
|
package beegopro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/beego/bee/internal/pkg/utils"
|
"github.com/beego/bee/internal/pkg/utils"
|
||||||
beeLogger "github.com/beego/bee/logger"
|
beeLogger "github.com/beego/bee/logger"
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var CompareExcept = []string{"@BeeGenerateTime"}
|
var CompareExcept = []string{"@BeeGenerateTime"}
|
||||||
|
|
||||||
func (c *Container) GenConfig() {
|
func (c *Container) GenConfig() {
|
||||||
if utils.IsExist(c.BeegoProFile) {
|
if utils.IsExist(c.BeegoProFile) {
|
||||||
beeLogger.Log.Fatalf("beego pro toml exist")
|
beeLogger.Log.Fatalf("beego pro toml exist")
|
||||||
|
@ -2,6 +2,10 @@ package beegopro
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/beego/bee/internal/pkg/git"
|
"github.com/beego/bee/internal/pkg/git"
|
||||||
"github.com/beego/bee/internal/pkg/system"
|
"github.com/beego/bee/internal/pkg/system"
|
||||||
beeLogger "github.com/beego/bee/logger"
|
beeLogger "github.com/beego/bee/logger"
|
||||||
@ -9,9 +13,6 @@ import (
|
|||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"io/ioutil"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const MDateFormat = "20060102_150405"
|
const MDateFormat = "20060102_150405"
|
||||||
|
@ -2,11 +2,12 @@ package beegopro
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
beeLogger "github.com/beego/bee/logger"
|
|
||||||
"github.com/beego/bee/utils"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
beeLogger "github.com/beego/bee/logger"
|
||||||
|
"github.com/beego/bee/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var SQL utils.DocValue
|
var SQL utils.DocValue
|
||||||
|
@ -3,6 +3,7 @@ package beegopro
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/beego/bee/internal/pkg/utils"
|
"github.com/beego/bee/internal/pkg/utils"
|
||||||
beeLogger "github.com/beego/bee/logger"
|
beeLogger "github.com/beego/bee/logger"
|
||||||
)
|
)
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package beegopro
|
package beegopro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/beego/bee/utils"
|
|
||||||
"github.com/flosch/pongo2"
|
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/beego/bee/utils"
|
||||||
|
"github.com/flosch/pongo2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -123,7 +123,7 @@ func (r *RenderFile) Exec(name string) {
|
|||||||
var orgContent []byte
|
var orgContent []byte
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if org, err := os.OpenFile(r.Descriptor.DstPath, os.O_RDONLY, 0666); 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()
|
org.Close()
|
||||||
} else {
|
} else {
|
||||||
beeLogger.Log.Infof("file err %s", err)
|
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)
|
beeLogger.Log.Infof("create file '%s' from %s", r.FlushFile, r.PackageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,15 +2,16 @@ package beegopro
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/beego/bee/internal/pkg/command"
|
"github.com/beego/bee/internal/pkg/command"
|
||||||
"github.com/beego/bee/internal/pkg/system"
|
"github.com/beego/bee/internal/pkg/system"
|
||||||
beeLogger "github.com/beego/bee/logger"
|
beeLogger "github.com/beego/bee/logger"
|
||||||
"github.com/beego/bee/utils"
|
"github.com/beego/bee/utils"
|
||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
"github.com/smartwalle/pongo2render"
|
"github.com/smartwalle/pongo2render"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// store all data
|
// store all data
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package beegopro
|
package beegopro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/beego/bee/utils"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/bee/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// parse get the model info
|
// parse get the model info
|
||||||
|
@ -3,6 +3,7 @@ package beegopro
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/beego/bee/logger"
|
"github.com/beego/bee/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -173,14 +173,14 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileContentChange(org,new []byte, seg string) bool {
|
func FileContentChange(org, new []byte, seg string) bool {
|
||||||
if len(org) == 0 {
|
if len(org) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
orgContent := GetFilterContent(string(org),seg)
|
orgContent := GetFilterContent(string(org), seg)
|
||||||
newContent := GetFilterContent(string(new),seg)
|
newContent := GetFilterContent(string(new), seg)
|
||||||
orgMd5 := md5.Sum([]byte(orgContent))
|
orgMd5 := md5.Sum([]byte(orgContent))
|
||||||
newMd5:= md5.Sum([]byte(newContent))
|
newMd5 := md5.Sum([]byte(newContent))
|
||||||
if orgMd5 != newMd5 {
|
if orgMd5 != newMd5 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ func GetFilterContent(content string, seg string) string {
|
|||||||
for _, s := range strings.Split(content, "\n") {
|
for _, s := range strings.Split(content, "\n") {
|
||||||
s = strings.TrimSpace(strings.TrimPrefix(s, seg))
|
s = strings.TrimSpace(strings.TrimPrefix(s, seg))
|
||||||
var have bool
|
var have bool
|
||||||
for _,except := range CompareExcept{
|
for _, except := range CompareExcept {
|
||||||
if strings.HasPrefix(s, except) {
|
if strings.HasPrefix(s, except) {
|
||||||
have = true
|
have = true
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,14 @@ package git
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/beego/bee/internal/pkg/command"
|
|
||||||
"github.com/beego/bee/internal/pkg/utils"
|
|
||||||
beeLogger "github.com/beego/bee/logger"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/bee/internal/pkg/command"
|
||||||
|
"github.com/beego/bee/internal/pkg/utils"
|
||||||
|
beeLogger "github.com/beego/bee/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// git tag
|
// git tag
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
beeLogger "github.com/beego/bee/logger"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
beeLogger "github.com/beego/bee/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mkdir ...
|
// Mkdir ...
|
||||||
|
@ -521,7 +521,7 @@ func NoticeUpdateBee() {
|
|||||||
beeLogger.Log.Info("Getting bee latest version...")
|
beeLogger.Log.Info("Getting bee latest version...")
|
||||||
versionLast := BeeLastVersion()
|
versionLast := BeeLastVersion()
|
||||||
versionNow := config.Version
|
versionNow := config.Version
|
||||||
if versionLast == ""{
|
if versionLast == "" {
|
||||||
beeLogger.Log.Warn("Get latest version err")
|
beeLogger.Log.Warn("Get latest version err")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user