project init
This commit is contained in:
parent
bca3a2be1e
commit
d3e3eb0102
73
cmd/new.go
73
cmd/new.go
@ -2,10 +2,12 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/gookit/color"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golib.gaore.com/GaoreGo/beegoinit-cmd/utils"
|
"golib.gaore.com/GaoreGo/beegoinit-cmd/utils"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gitignore = `# Created by .ignore support plugin (hsz.mobi)
|
var gitignore = `# Created by .ignore support plugin (hsz.mobi)
|
||||||
@ -35,25 +37,52 @@ gen
|
|||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/`
|
# vendor/`
|
||||||
|
|
||||||
var tree = `
|
var tree = `.
|
||||||
.
|
|
||||||
├── applications
|
├── applications
|
||||||
│ ├── _common
|
│ ├── _common
|
||||||
│ ├── api
|
│ ├── api
|
||||||
|
| | ├── base.go
|
||||||
│ | └── index.go
|
│ | └── index.go
|
||||||
│ └── init.go
|
│ └── init.go
|
||||||
├── cli
|
|
||||||
│ └── test
|
|
||||||
├── conf
|
├── conf
|
||||||
│ └──app.conf
|
│ └──app.conf
|
||||||
├── main.go
|
|
||||||
├── runtime
|
├── runtime
|
||||||
│ └── logs
|
│ └── logs
|
||||||
├── static
|
├── static
|
||||||
|
| └── js
|
||||||
|
| └── css
|
||||||
|
├── main.go
|
||||||
├── Makefile
|
├── Makefile
|
||||||
└── README.md
|
└── README.md
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var appconf = `appname = {{ packageName }}
|
||||||
|
|
||||||
|
httpaddr = "${CENTER_HTTP_HOST||127.0.0.1}"
|
||||||
|
|
||||||
|
httpport = "${CENTER_HTTP_PORT||8080}"
|
||||||
|
|
||||||
|
runmode ="${CENTER_RUNMODE||prod}"
|
||||||
|
|
||||||
|
copyrequestbody = true
|
||||||
|
|
||||||
|
sessionon = true
|
||||||
|
|
||||||
|
customviewdir = "views"
|
||||||
|
|
||||||
|
custommodules = "api,web,openapi,admin"
|
||||||
|
|
||||||
|
RouterCaseSensitive = false
|
||||||
|
|
||||||
|
EnableGzip = true
|
||||||
|
|
||||||
|
enablexsrf = true
|
||||||
|
|
||||||
|
xsrfkey = 61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o
|
||||||
|
|
||||||
|
xsrfexpire = 21600
|
||||||
|
`
|
||||||
|
|
||||||
var initfun = `
|
var initfun = `
|
||||||
package applications
|
package applications
|
||||||
|
|
||||||
@ -64,8 +93,8 @@ import (
|
|||||||
router "golib.gaore.com/GaoreGo/beegoinit/routers"
|
router "golib.gaore.com/GaoreGo/beegoinit/routers"
|
||||||
"golib.gaore.com/GaoreGo/grconfig"
|
"golib.gaore.com/GaoreGo/grconfig"
|
||||||
"golib.gaore.com/GaoreGo/grlogs"
|
"golib.gaore.com/GaoreGo/grlogs"
|
||||||
common "jedi.gaore.com/applications/_common/controllers"
|
common "{{ packageName }}/applications/_common/controllers"
|
||||||
api "jedi.gaore.com/applications/api/controllers"
|
api "{{ packageName }}/applications/api/controllers"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -156,7 +185,7 @@ import (
|
|||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/toolbox"
|
"github.com/astaxie/beego/toolbox"
|
||||||
_ "golib.gaore.com/GaoreGo/beegoinit"
|
_ "golib.gaore.com/GaoreGo/beegoinit"
|
||||||
_ "jedi.gaore.com/applications"
|
_ "{{ packageName }}/applications"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -172,27 +201,47 @@ func New(c *cli.Context) error {
|
|||||||
|
|
||||||
var appPath string
|
var appPath string
|
||||||
var packPath string
|
var packPath string
|
||||||
|
var packageName string
|
||||||
|
var err error
|
||||||
|
|
||||||
if packPath == "." {
|
if packPath == "." {
|
||||||
packPath = path.Base(appPath)
|
packPath = path.Base(appPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(tree)
|
fmt.Println(tree)
|
||||||
appPath = "."
|
|
||||||
|
appPath = c.String("apppath")
|
||||||
|
if appPath == "" {
|
||||||
|
if appPath, err = os.Getwd(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
packageName = c.String("package")
|
||||||
|
if packageName == "" {
|
||||||
|
packageName = path.Base(appPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
color.Yellow.Println("Now current working directory is :", appPath)
|
||||||
|
color.Yellow.Println("Now package name is default to :", packageName)
|
||||||
|
|
||||||
os.Mkdir(path.Join(appPath, "static"), 0755)
|
os.Mkdir(path.Join(appPath, "static"), 0755)
|
||||||
os.Mkdir(path.Join(appPath, "conf"), 0755)
|
os.Mkdir(path.Join(appPath, "conf"), 0755)
|
||||||
os.Mkdir(path.Join(appPath, "cli"), 0755)
|
os.Mkdir(path.Join(appPath, "cli"), 0755)
|
||||||
os.MkdirAll(path.Join(appPath, "runtime", "logs"), 0755)
|
os.MkdirAll(path.Join(appPath, "runtime", "logs"), 0755)
|
||||||
os.MkdirAll(path.Join(appPath, "applications", "_common", "controllers"), 0755)
|
os.MkdirAll(path.Join(appPath, "applications", "_common", "controllers"), 0755)
|
||||||
os.MkdirAll(path.Join(appPath, "applications", "_common", "views"), 0755)
|
os.MkdirAll(path.Join(appPath, "applications", "_common", "views"), 0755)
|
||||||
os.MkdirAll(path.Join(appPath, "applications", "api", "controlelrs"), 0755)
|
os.MkdirAll(path.Join(appPath, "applications", "api", "controllers"), 0755)
|
||||||
|
|
||||||
utils.WriteToFile(path.Join(appPath, "main.go"), mainfun)
|
utils.WriteToFile(path.Join(appPath, "main1.go"), strings.ReplaceAll(mainfun, "{{ packageName }}", packageName))
|
||||||
utils.WriteToFile(path.Join(appPath, "applications", "init.go"), initfun)
|
utils.WriteToFile(path.Join(appPath, "applications", "init.go"), strings.ReplaceAll(initfun, "{{ packageName }}", packageName))
|
||||||
|
utils.WriteToFile(path.Join(appPath, "conf", "app.conf"), strings.ReplaceAll(appconf, "{{ packageName }}", packageName))
|
||||||
utils.WriteToFile(path.Join(appPath, "applications", "_common", "views", "404.tpl"), indextpl)
|
utils.WriteToFile(path.Join(appPath, "applications", "_common", "views", "404.tpl"), indextpl)
|
||||||
utils.WriteToFile(path.Join(appPath, "applications", "_common", "views", "403.tpl"), indextpl)
|
utils.WriteToFile(path.Join(appPath, "applications", "_common", "views", "403.tpl"), indextpl)
|
||||||
utils.WriteToFile(path.Join(appPath, "applications", "_common", "controllers", "error.go"), errcontroller)
|
utils.WriteToFile(path.Join(appPath, "applications", "_common", "controllers", "error.go"), errcontroller)
|
||||||
utils.WriteToFile(path.Join(appPath, "applications", "api", "controllers", "base.go"), basecontroller)
|
utils.WriteToFile(path.Join(appPath, "applications", "api", "controllers", "base.go"), basecontroller)
|
||||||
utils.WriteToFile(path.Join(appPath, "applications", "api", "controllers", "index.go"), indexcontroller)
|
utils.WriteToFile(path.Join(appPath, "applications", "api", "controllers", "index.go"), indexcontroller)
|
||||||
|
|
||||||
|
color.Yellow.Println("Finish ...")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user