2 Star 1 Fork 1

mosache/YFrame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
create.go 3.27 KB
一键复制 编辑 原始数据 按行查看 历史
ヤ沒脩袮兲︶ 提交于 2023-03-14 17:52 . init
// Package create /*
package create
import (
"fmt"
"gitee.com/mosache/YFrame/tools/Y/create/apigen"
"gitee.com/mosache/YFrame/tools/Y/create/configgen"
"gitee.com/mosache/YFrame/tools/Y/create/etcgen"
"gitee.com/mosache/YFrame/tools/Y/create/gomodgen"
"gitee.com/mosache/YFrame/tools/Y/create/responsegen"
"gitee.com/mosache/YFrame/tools/Y/create/tplGen"
"gitee.com/mosache/YFrame/tools/Y/utils/cobraErr"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"os"
"os/exec"
)
var Cmd = &cobra.Command{Use: "create",
Long: `create is for create a project.
modName will use as the dir name and in go.mod as module name`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
modName := args[0]
if err := createProjectDir(modName); err != nil {
cobraErr.Err(cmd, err.Error())
}
},
}
func createProjectDir(modName string) error {
if _, err := os.Stat(fmt.Sprintf("./%s", modName)); err != nil && !os.IsNotExist(err) {
return err
} else {
/// create the project dir
if err = os.Mkdir(modName, os.ModePerm); err != nil {
return fmt.Errorf("[create project dir err] : %s", err.Error())
}
if err := os.Chdir(modName); err != nil {
return fmt.Errorf("[cd to project dir err] : %s", err.Error())
}
/// go.mod
if err = gomodgen.CreateGoModFile(modName); err != nil {
return fmt.Errorf("[go.mod create err] : %s", err.Error())
}
/// config
if err = configgen.GenConfig(); err != nil {
return fmt.Errorf("[config config err] : %s", err.Error())
}
/// etc
if err = etcgen.GenEtc(modName); err != nil {
return fmt.Errorf("[create etc err] : %s", err.Error())
}
/// api
if err = apigen.GenApiDir(); err != nil {
return fmt.Errorf("[create api dir err] : %s", err.Error())
}
/// copy .tpl
if err = tplGen.TplGen(); err != nil {
return fmt.Errorf("[copy tpl dir err] : %s", err.Error())
}
/// response
if err = responsegen.GenResponse(); err != nil {
return err
}
///// doc
//if err = docgen.GenDoc(); err != nil {
// return fmt.Errorf("[create doc err] : %s", err.Error())
//}
///// logic
//if err = logicgen.GenLogic(); err != nil {
// return fmt.Errorf("[create logic dir err] : %s", err.Error())
//}
//
///// middleware
//if err = middlewaregen.Gen(); err != nil {
// return fmt.Errorf("[create middleWare dir err] : %s", err.Error())
//}
//
///// router
//if err = routergen.GenRouter(); err != nil {
// return fmt.Errorf("[create router dir err] : %s", err.Error())
//}
///// main.go
//if err = maingen.GenMain(modName); err != nil {
// return fmt.Errorf("[create main file err] : %s", err.Error())
//}
/// fetch deps
if err = fetchDeps(); err != nil {
return fmt.Errorf("[fetch deps err] : %s", err.Error())
}
fmt.Println(aurora.Green(fmt.Sprintf("project [%s] create success...", modName)))
}
return nil
}
func fetchDeps() error {
os.Setenv("GOPRIVATE", "gitee.com/mosache")
os.Setenv("GOPROXY", "https://goproxy.cn")
/// YFrame
if err := exec.Command("go", "get", "-u", "gitee.com/mosache/YFrame").Run(); err != nil {
return err
}
/// go-zero
if err := exec.Command("go", "get", "-u", "github.com/zeromicro/go-zero").Run(); err != nil {
return err
}
if err := exec.Command("go", "mod", "tidy").Run(); err != nil {
return err
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mosache/YFrame.git
git@gitee.com:mosache/YFrame.git
mosache
YFrame
YFrame
v0.1.36

搜索帮助