remove makefile generation
This commit is contained in:
@@ -22,7 +22,7 @@ func getParentPackage(dir string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
absDir = strings.ReplaceAll(absDir, `\`, `/`)
|
absDir = strings.ReplaceAll(absDir, `\`, `/`)
|
||||||
var rootPath, hasGoMod = goctlutil.FindGoModPath(dir)
|
rootPath, hasGoMod := goctlutil.FindGoModPath(dir)
|
||||||
if hasGoMod {
|
if hasGoMod {
|
||||||
return rootPath, nil
|
return rootPath, nil
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func getParentPackage(dir string) (string, error) {
|
|||||||
pos := strings.Index(absDir, parent)
|
pos := strings.Index(absDir, parent)
|
||||||
if pos < 0 {
|
if pos < 0 {
|
||||||
fmt.Printf("%s not in go.mod project path, or not in GOPATH of %s directory\n", absDir, gopath)
|
fmt.Printf("%s not in go.mod project path, or not in GOPATH of %s directory\n", absDir, gopath)
|
||||||
var tempPath = filepath.Dir(absDir)
|
tempPath := filepath.Dir(absDir)
|
||||||
rootPath = absDir[len(tempPath)+1:]
|
rootPath = absDir[len(tempPath)+1:]
|
||||||
} else {
|
} else {
|
||||||
rootPath = absDir[len(parent)+1:]
|
rootPath = absDir[len(parent)+1:]
|
||||||
@@ -61,7 +61,7 @@ func writeProperty(writer io.Writer, name, tp, tag, comment string, indent int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAuths(api *spec.ApiSpec) []string {
|
func getAuths(api *spec.ApiSpec) []string {
|
||||||
var authNames = collection.NewSet()
|
authNames := collection.NewSet()
|
||||||
for _, g := range api.Service.Groups {
|
for _, g := range api.Service.Groups {
|
||||||
if value, ok := util.GetAnnotationValue(g.Annotations, "server", "jwt"); ok {
|
if value, ok := util.GetAnnotationValue(g.Annotations, "server", "jwt"); ok {
|
||||||
authNames.Add(value)
|
authNames.Add(value)
|
||||||
@@ -78,5 +78,6 @@ func formatCode(code string) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(ret)
|
return string(ret)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,9 @@ import (
|
|||||||
|
|
||||||
func DockerCommand(c *cli.Context) error {
|
func DockerCommand(c *cli.Context) error {
|
||||||
goFile := c.String("go")
|
goFile := c.String("go")
|
||||||
namespace := c.String("namespace")
|
if len(goFile) == 0 {
|
||||||
if len(goFile) == 0 || len(namespace) == 0 {
|
return errors.New("-go can't be empty")
|
||||||
return errors.New("-go and -namespace can't be empty")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gen.GenerateDockerfile(goFile, "-f", "etc/config.json"); err != nil {
|
return gen.GenerateDockerfile(goFile, "-f", "etc/config.yaml")
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return gen.GenerateMakefile(goFile, namespace)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GenerateDockerfile(goFile string, args ...string) error {
|
func GenerateDockerfile(goFile string, args ...string) error {
|
||||||
relPath, err := util.PathFromGoSrc()
|
projPath, err := getFilePath(goFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ func GenerateDockerfile(goFile string, args ...string) error {
|
|||||||
t := template.Must(template.New("dockerfile").Parse(dockerTemplate))
|
t := template.Must(template.New("dockerfile").Parse(dockerTemplate))
|
||||||
return t.Execute(out, map[string]string{
|
return t.Execute(out, map[string]string{
|
||||||
"projectName": vars.ProjectName,
|
"projectName": vars.ProjectName,
|
||||||
"goRelPath": relPath,
|
"goRelPath": projPath,
|
||||||
"goFile": goFile,
|
"goFile": goFile,
|
||||||
"exeFile": util.FileNameWithoutExt(goFile),
|
"exeFile": util.FileNameWithoutExt(goFile),
|
||||||
"argument": builder.String(),
|
"argument": builder.String(),
|
||||||
|
|||||||
26
tools/goctl/gen/filepath.go
Normal file
26
tools/goctl/gen/filepath.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package gen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getFilePath(file string) (string, error) {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
projPath, ok := util.FindGoModPath(filepath.Join(wd, file))
|
||||||
|
if !ok {
|
||||||
|
projPath, err = util.PathFromGoSrc()
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.New("no go.mod found, or not in GOPATH")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return projPath, nil
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package gen
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GenerateMakefile(goFile, namespace string) error {
|
|
||||||
relPath, err := util.PathFromGoSrc()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
movePath, err := getMovePath()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := util.CreateIfNotExist("Makefile")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
t := template.Must(template.New("makefile").Parse(makefileTemplate))
|
|
||||||
return t.Execute(out, map[string]string{
|
|
||||||
"rootRelPath": movePath,
|
|
||||||
"relPath": relPath,
|
|
||||||
"exeFile": util.FileNameWithoutExt(goFile),
|
|
||||||
"namespace": namespace,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMovePath() (string, error) {
|
|
||||||
relPath, err := util.PathFromGoSrc()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder strings.Builder
|
|
||||||
for range strings.Split(relPath, "/") {
|
|
||||||
builder.WriteString("../")
|
|
||||||
}
|
|
||||||
|
|
||||||
if move := builder.String(); len(move) == 0 {
|
|
||||||
return ".", nil
|
|
||||||
} else {
|
|
||||||
return move, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user