1
0
mirror of https://github.com/beego/bee.git synced 2024-11-01 00:00:53 +00:00
bee/cmd/commands/new/new.go

351 lines
78 KiB
Go
Raw Normal View History

2013-09-03 17:23:58 +00:00
// Copyright 2013 bee authors
//
// 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 new
import (
"fmt"
2020-05-22 07:53:22 +00:00
"github.com/beego/bee/cmd/commands/version"
"os"
path "path/filepath"
2020-05-22 07:53:22 +00:00
"runtime"
"strings"
"github.com/beego/bee/cmd/commands"
2020-05-22 07:53:22 +00:00
"github.com/beego/bee/logger"
"github.com/beego/bee/logger/colors"
"github.com/beego/bee/utils"
)
2020-05-22 07:53:22 +00:00
var module utils.DocValue
var beegoVersion utils.DocValue
var CmdNew = &commands.Command{
2020-05-22 07:53:22 +00:00
UsageLine: "new [appname] [-module=true] [-beego=v1.12.1]",
Short: "Creates a Beego application",
Long: `
Creates a Beego application for the given app name in the current directory.
2020-05-22 07:53:22 +00:00
now supoort generate a go modules project
The command 'new' creates a folder named [appname] [-module=true] [-beego=v1.12.1] and generates the following structure:
main.go
2020-05-22 07:53:22 +00:00
go.mod
{{"conf"|foldername}}
app.conf
{{"controllers"|foldername}}
default.go
{{"models"|foldername}}
{{"routers"|foldername}}
router.go
{{"tests"|foldername}}
default_test.go
{{"static"|foldername}}
{{"js"|foldername}}
{{"css"|foldername}}
{{"img"|foldername}}
{{"views"|foldername}}
index.tpl
`,
2020-05-22 07:53:22 +00:00
PreRun: nil,
Run: CreateApp,
}
var appconf = `appname = {{.Appname}}
httpport = 8080
runmode = dev
`
var maingo = `package main
import (
2013-12-23 16:00:52 +00:00
_ "{{.Appname}}/routers"
"github.com/astaxie/beego"
)
func main() {
beego.Run()
}
`
2013-12-23 16:00:52 +00:00
var router = `package routers
2013-12-23 15:28:31 +00:00
import (
"{{.Appname}}/controllers"
"github.com/astaxie/beego"
)
func init() {
beego.Router("/", &controllers.MainController{})
}
`
2020-05-22 07:53:22 +00:00
var goMod = `
module %s
go %s
2013-12-23 15:28:31 +00:00
2020-05-22 07:53:22 +00:00
require github.com/astaxie/beego %s
`
2013-12-23 15:28:31 +00:00
var test = `package test
import (
"net/http"
"net/http/httptest"
"testing"
2014-04-03 08:46:47 +00:00
"runtime"
"path/filepath"
2013-12-23 16:00:52 +00:00
_ "{{.Appname}}/routers"
2013-12-23 15:28:31 +00:00
"github.com/astaxie/beego"
. "github.com/smartystreets/goconvey/convey"
)
2014-04-03 08:41:44 +00:00
func init() {
_, file, _, _ := runtime.Caller(0)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
2014-04-03 08:41:44 +00:00
beego.TestBeegoInit(apppath)
}
2016-11-09 12:17:55 +00:00
// TestBeego is a sample to run an endpoint test
func TestBeego(t *testing.T) {
2013-12-23 16:11:13 +00:00
r, _ := http.NewRequest("GET", "/", nil)
2013-12-23 15:28:31 +00:00
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
2016-11-09 12:17:55 +00:00
beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
2013-12-23 15:28:31 +00:00
Convey("Subject: Test Station Endpoint\n", t, func() {
Convey("Status Code Should Be 200", func() {
So(w.Code, ShouldEqual, 200)
})
Convey("The Result Should Not Be Empty", func() {
So(w.Body.Len(), ShouldBeGreaterThan, 0)
})
})
}
`
var controllers = `package controllers
import (
"github.com/astaxie/beego"
)
type MainController struct {
beego.Controller
}
2014-11-05 14:48:09 +00:00
func (c *MainController) Get() {
c.Data["Website"] = "beego.me"
c.Data["Email"] = "astaxie@gmail.com"
c.TplName = "index.tpl"
}
`
var indextpl = `<!DOCTYPE html>
<html>
2014-12-04 07:14:00 +00:00
<head>
<title>Beego</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpFNTdGOTA3OTczQTgxMUU0QTlEQUM0NEYyRkI1NEQxQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpFNTdGOTA3QTczQTgxMUU0QTlEQUM0NEYyRkI1NEQxQiI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkU1N0Y5M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oBKedDeYtOFZ+WOSNvxgx/Q0/PZQq+6zaZ7c6E0J///MYZh9Wqnz9//sOZWVnKmyguIoJ76qmnfqNWqxlAYeLEievo/kCFORwOVFVWxJrqq/jYKA0SZi/C6sefRtrw4ZDesL5RkZFY8ov/gVebjHaz7YaW4G7cMPCXBcRJOOEgwZVJ7ZQEL0qO7s9SSiS/jYyOTvtBWKA/ix16/X6L2Tz6/nXr5rEFDeb+SBvc9eijj76el5f3K3KB4uSkJJw4ftxMmRgQM/csXTais7pykZ++jQscng2jRIaz+flfbyM6Z9rEyWi3OsCkRP/02X2ebiIaAwNZ8g1CWzlIKwQRnuTEROHC5x9DyfN/yxoyNIU9RwkQbt+2wHJHXoCMDggIX1+zevWvCOQe37Zt23yr1coNzcpcFBkdo0pISBBWdkiaIiAwMGLTo48++OstW/7CylitUq1Cd2d0YFQ0nIFh2P7O/0FyfAIm5UwSJtcvoNgRFBUFCyeC0+MD04lU8fScDB63B+29VhgpCGIKIGeykoa0UzU4IBPxGBMVgYoO3fCRaWk7Y2JjNvzu1VfXeF0uftmKFc/1GAw9+q4uy1db/Y7NUExMjDwtPd1ZVVWVPX369Gw/4nfi7JvMD6sUqgQ/Yo4J9IF/GTV6tNra1RkrETmgHj4KDnqPydCNuXM3oD85g7PktNngpcn7qN85UV8JmDwu1NjdiJ44DbOn5wl029LQiKITR6Gjm5/bgUCqxsywAFxrqc/kVUE739j6QoDXYcPoBO3secufcNY0NT3x4ksvf0q6+78PAItgUlISR66PaQOEkXr7qgwetOY3/J577kkkdacZqglb5Th/Ah6OxyQCvIgIDXIm5nztfSaiz9K
<style type="text/css">
*,body {
margin: 0px;
padding: 0px;
}
body {
margin: 0px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 20px;
background-color: #fff;
}
header,
footer {
width: 960px;
margin-left: auto;
margin-right: auto;
}
.logo {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAg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J5LkorpqamsCzLPXLkyB4hBCdPniRJEs6fP98jpWRufp5UK+I0odZoIITg333gN/b84gd+PVlwx5wW52w6azvUlvHxCeMKnjm9/Vd+5Vf2vPmNb+Qdb3sbQK3Q3f3CZaB2rwPc//rh3++pzc3h2jZe3uN6kmtCQVp0jziOieOrW7qQz+cRQmDbNmF4RcCU/yiEeKCnv4/D3/4mviW5Z8OQcbeCJqSK+UARJJpqGDEThKhUETeilklBayjkXSxL4ubzDHge4/UmTz74IP39/QNCiEc646bvPPook1MTnDx8hHoUEtdg34mjWFLajus+vJKfL4T4W+CnOl/76lfNVIVms/mhToYBWj8K3H0ZcdiXgPWDPQOMHztFef0Im7bdwPXUbPiay6RfbQvSuXiuxLnbNI8OusTi4wqDLgkQmZUQQiyGeAULXUn0EuqIUu2cTZokJGmKSlNUqowl1iamEdnfpkmCXsEyKqXkG153q2tJi5HBPnO+FnFTqTbpMclioq997WtuhjQihKC3twfXddFaJzt37lIXiu/I6C+I1v0WawpyKdLVVQFgYmKC8fGrmy8aGjK7e7FYZG5u7mUf7+mHHzZrfG6aG7rLWAKi0PTSzeXKCCGJ+3xs12awWKSr0sXU1DQPfuPhRcepKY1QgrHJKcZnp5mqNxk/P8nUcZt//WNvBaDbVoYKobNIQ0iEJbFSG3/MuI6/
background-repeat: no-repeat;
-webkit-background-size: 100px 100px;
background-size: 100px 100px;
background-position: center center;
text-align: center;
font-size: 42px;
padding: 250px 0 70px;
font-weight: normal;
text-shadow: 0px 1px 2px #ddd;
}
header {
padding: 100px 0;
}
footer {
line-height: 1.8;
text-align: center;
padding: 50px 0;
color: #999;
}
.description {
text-align: center;
font-size: 16px;
}
a {
color: #444;
text-decoration: none;
}
.backdrop {
position: absolute;
width: 100%;
height: 100%;
box-shadow: inset 0px 0px 100px #ddd;
z-index: -1;
top: 0px;
left: 0px;
}
</style>
</head>
<body>
<header>
<h1 class="logo">Welcome to Beego</h1>
<div class="description">
Beego is a simple & powerful Go web framework which is inspired by tornado and sinatra.
</div>
</header>
<footer>
<div class="author">
Official website:
<a href="http://{{.Website}}">{{.Website}}</a> /
Contact me:
2014-12-04 07:14:00 +00:00
<a class="email" href="mailto:{{.Email}}">{{.Email}}</a>
</div>
</footer>
<div class="backdrop"></div>
2017-01-27 15:57:37 +00:00
<script src="/static/js/reload.min.js"></script>
2014-12-04 07:14:00 +00:00
</body>
</html>
`
2017-01-27 15:57:37 +00:00
var reloadJsClient = `function b(a){var c=new WebSocket(a);c.onclose=function(){setTimeout(function(){b(a)},2E3)};c.onmessage=function(){location.reload()}}try{if(window.WebSocket)try{b("ws://localhost:12450/reload")}catch(a){console.error(a)}else console.log("Your browser does not support WebSockets.")}catch(a){console.error("Exception during connecting to Reload:",a)};
`
func init() {
2020-05-22 07:53:22 +00:00
CmdNew.Flag.Var(&module, "module", "Support go modules")
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
commands.AvailableCommands = append(commands.AvailableCommands, CmdNew)
}
func CreateApp(cmd *commands.Command, args []string) int {
output := cmd.Out()
2020-05-22 07:53:22 +00:00
if len(args) == 0 {
beeLogger.Log.Fatal("Argument [appname] is missing")
}
2020-05-22 07:53:22 +00:00
if len(args) >= 2 {
cmd.Flag.Parse(args[1:])
} else {
module = "false"
}
appPath := ``
packPath := ``
var err error
if module != `true` {
beeLogger.Log.Info("generate new project support GOPATH")
version.ShowShortVersionBanner()
appPath, packPath, err = utils.CheckEnv(args[0])
if err != nil {
beeLogger.Log.Fatalf("%s", err)
}
} else {
beeLogger.Log.Info("generate new project support go modules.")
appPath = path.Join(utils.GetBeeWorkPath(), args[0])
packPath = args[0]
if beegoVersion.String() == `` {
beegoVersion.Set(`v1.12.1`)
}
}
if utils.IsExist(appPath) {
beeLogger.Log.Errorf(colors.Bold("Application '%s' already exists"), appPath)
beeLogger.Log.Warn(colors.Bold("Do you want to overwrite it? [Yes|No] "))
if !utils.AskForConfirmation() {
os.Exit(2)
}
}
beeLogger.Log.Info("Creating application...")
os.MkdirAll(appPath, 0755)
2020-05-26 09:58:56 +00:00
if module == `true` {
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, runtime.Version()[2:], beegoVersion.String()))
}
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", appPath+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "conf"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "conf")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "controllers"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "controllers")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "models"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "models")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "routers"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "routers")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "tests"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "tests")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "static"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "static")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "static", "js"), 0755)
utils.WriteToFile(path.Join(appPath, "static", "js", "reload.min.js"), reloadJsClient)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "static", "js")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "static", "css"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "static", "css")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "static", "img"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "static", "img")+string(path.Separator), "\x1b[0m")
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "views")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(appPath, "views"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "conf", "app.conf"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "conf", "app.conf"), strings.Replace(appconf, "{{.Appname}}", path.Base(args[0]), -1))
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "controllers", "default.go"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "controllers", "default.go"), controllers)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "views", "index.tpl"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "views", "index.tpl"), indextpl)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "routers", "router.go"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "routers", "router.go"), strings.Replace(router, "{{.Appname}}", packPath, -1))
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "tests", "default_test.go"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "tests", "default_test.go"), strings.Replace(test, "{{.Appname}}", packPath, -1))
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "main.go"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "main.go"), strings.Replace(maingo, "{{.Appname}}", packPath, -1))
beeLogger.Log.Success("New application successfully created!")
return 0
}