feat(14.3-01): add summer new with a starter route and relative go.work
- build.NewApp writes sm-<name>-app: go.mod with a relative framework
replace, go.work, summer.yaml, config/ and a starter plugin
- make:plugin gains an opt-in starter route (GET /{$}) in the same
routes.go template; plain make:plugin output is unchanged
- plugin:add writes go.work use paths relative to the go.work directory
- bonfire accepts new as a bare tool command name
This commit is contained in:
35
internal/build/stubs/new.tmpl
Normal file
35
internal/build/stubs/new.tmpl
Normal file
@@ -0,0 +1,35 @@
|
||||
{{define "new/go.mod"}}module {{.Module}}
|
||||
|
||||
{{.GoVersion}}
|
||||
|
||||
{{.Toolchain}}
|
||||
|
||||
require {{.Framework}} v0.0.0
|
||||
|
||||
replace {{.Framework}} => {{.Replace}}
|
||||
{{end}}
|
||||
|
||||
{{define "new/config/app.yaml"}}name: {{.Name}}
|
||||
debug: false
|
||||
# The application key encrypts data at rest. Set SUMMER_APP__KEY in .env (a
|
||||
# 32-byte base64 value); keep it out of this file and out of git.
|
||||
key: ""
|
||||
{{end}}
|
||||
|
||||
{{define "new/config/database.yaml"}}# Set SUMMER_DATABASE__DSN in .env; compose.yaml runs the matching PostgreSQL.
|
||||
dsn: ""
|
||||
{{end}}
|
||||
|
||||
{{define "new/config/http.yaml"}}body_limits:
|
||||
# Request body limits in bytes. Keep them YAML numbers: values from the
|
||||
# environment are strings and are rejected at boot.
|
||||
default_bytes: 1048576
|
||||
upload_bytes: 10485760
|
||||
{{end}}
|
||||
|
||||
{{define "new/config/storage.yaml"}}# Uploads bucket, required by summer serve. A file:// URL is a local
|
||||
# directory under the application working directory.
|
||||
uploads:
|
||||
bucket_url: "file://./storage/app/uploads"
|
||||
public_path_prefix: "/storage/uploads"
|
||||
{{end}}
|
||||
@@ -61,13 +61,35 @@ func init() {
|
||||
{{end}}
|
||||
|
||||
{{define "routes.go"}}package {{.Package}}
|
||||
{{if .StarterRoute}}
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
)
|
||||
|
||||
var _ pact.HasRoutes = (*Plugin)(nil)
|
||||
|
||||
// Routes registers the starter route: GET / answers with a JSON greeting
|
||||
// naming this plugin.
|
||||
func (p *Plugin) Routes(r pact.Router) error {
|
||||
r.Get("/{$}", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"message": "Hello from SummerCMS",
|
||||
"plugin": p.ID(),
|
||||
})
|
||||
})
|
||||
return nil
|
||||
}
|
||||
{{else}}
|
||||
import "git.golem15.com/golem15/summercms/modules/pact"
|
||||
|
||||
var _ pact.HasRoutes = (*Plugin)(nil)
|
||||
|
||||
func (p *Plugin) Routes(pact.Router) error { return nil }
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
|
||||
{{define "go.mod"}}module {{.Module}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user