- 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
132 lines
3.6 KiB
Cheetah
132 lines
3.6 KiB
Cheetah
{{define "plugin.go"}}package {{.Package}}
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/bonfire"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
"git.golem15.com/golem15/summercms/modules/party"
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
)
|
|
|
|
var (
|
|
_ pact.HasConfig = (*Plugin)(nil)
|
|
_ pact.HasLang = (*Plugin)(nil)
|
|
_ pact.HasMailTemplates = (*Plugin)(nil)
|
|
_ pact.HasModels = (*Plugin)(nil)
|
|
_ pact.HasMigrations = (*Plugin)(nil)
|
|
_ pact.HasCommands = (*Plugin)(nil)
|
|
_ pact.HasJobs = (*Plugin)(nil)
|
|
_ pact.HasAdminControllers = (*Plugin)(nil)
|
|
)
|
|
|
|
//go:embed config
|
|
var configFS embed.FS
|
|
|
|
//go:embed lang
|
|
var langFS embed.FS
|
|
|
|
//go:embed views/mail
|
|
var mailFS embed.FS
|
|
|
|
// Plugin is the {{.ID}} plugin.
|
|
type Plugin struct{}
|
|
|
|
func (p *Plugin) ID() string { return {{printf "%q" .ID}} }
|
|
func (p *Plugin) Requires() []string { return nil }
|
|
|
|
func (p *Plugin) Register(*backpack.App) error { return nil }
|
|
func (p *Plugin) Boot(*backpack.App) error { return nil }
|
|
|
|
func (p *Plugin) ConfigFS() fs.FS { return configFS }
|
|
func (p *Plugin) LangFS() fs.FS { return langFS }
|
|
|
|
func (p *Plugin) MailTemplatesFS() fs.FS { return mailFS }
|
|
func (p *Plugin) MailTemplates() []string { return nil }
|
|
func (p *Plugin) MailLayouts() map[string]string { return nil }
|
|
|
|
func (p *Plugin) Models() []any { return generatedModels() }
|
|
func (p *Plugin) Migrations() []*gormigrate.Migration { return generatedMigrations() }
|
|
func (p *Plugin) Commands() []bonfire.Command { return generatedCommands() }
|
|
func (p *Plugin) Jobs() []pact.Job { return generatedJobs() }
|
|
func (p *Plugin) AdminControllers() []pact.AdminController {
|
|
return generatedAdminControllers()
|
|
}
|
|
|
|
func init() {
|
|
party.Register(&Plugin{})
|
|
}
|
|
{{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}}
|
|
|
|
{{define "go.mod"}}module {{.Module}}
|
|
|
|
{{.GoVersion}}
|
|
|
|
{{.Toolchain}}
|
|
|
|
require {{.Framework}} v0.0.0
|
|
{{if .Replace}}
|
|
replace {{.Framework}} => {{.Replace}}
|
|
{{end}}{{end}}
|
|
|
|
{{define "models/doc.go"}}// Package models holds GORM models for the {{.ID}} plugin.
|
|
package models
|
|
{{end}}
|
|
|
|
{{define "classes/doc.go"}}// Package classes holds services and hooks for the {{.ID}} plugin.
|
|
package classes
|
|
{{end}}
|
|
|
|
{{define "controllers/doc.go"}}// Package controllers holds HTTP handlers and admin controllers for the {{.ID}} plugin.
|
|
package controllers
|
|
{{end}}
|
|
|
|
{{define "console/doc.go"}}// Package console holds bonfire commands for the {{.ID}} plugin.
|
|
package console
|
|
{{end}}
|
|
|
|
{{define "jobs/doc.go"}}// Package jobs holds background jobs for the {{.ID}} plugin.
|
|
package jobs
|
|
{{end}}
|
|
|
|
{{define "middleware/doc.go"}}// Package middleware holds named HTTP middleware for the {{.ID}} plugin.
|
|
package middleware
|
|
{{end}}
|
|
|
|
{{define "updates/doc.go"}}// Package updates holds the gormigrate set for the {{.ID}} plugin.
|
|
package updates
|
|
{{end}}
|