feat(04-01): scaffold Winter-shaped plugins with generated registry
Render plugin.go, routes.go, leaf packages and go.mod from embedded templates, emit empty registry accessors, and define job, admin, lang and mail capability contracts so a new plugin compiles before artifacts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
109
internal/build/stubs/plugin.tmpl
Normal file
109
internal/build/stubs/plugin.tmpl
Normal file
@@ -0,0 +1,109 @@
|
||||
{{define "plugin.go"}}package {{.Package}}
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
|
||||
"git.golem15.com/golem15/summercms/backpack"
|
||||
"git.golem15.com/golem15/summercms/bonfire"
|
||||
"git.golem15.com/golem15/summercms/pact"
|
||||
"git.golem15.com/golem15/summercms/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}}
|
||||
|
||||
import "git.golem15.com/golem15/summercms/pact"
|
||||
|
||||
var _ pact.HasRoutes = (*Plugin)(nil)
|
||||
|
||||
func (p *Plugin) Routes(pact.Router) error { return nil }
|
||||
{{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}}
|
||||
73
internal/build/stubs/registry.tmpl
Normal file
73
internal/build/stubs/registry.tmpl
Normal file
@@ -0,0 +1,73 @@
|
||||
{{define "registry.go"}}// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package {{.Package}}
|
||||
|
||||
import (
|
||||
"git.golem15.com/golem15/summercms/bonfire"
|
||||
"git.golem15.com/golem15/summercms/pact"
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
{{- range .Imports}}
|
||||
{{printf "%q" .}}
|
||||
{{- end}}
|
||||
)
|
||||
|
||||
func generatedModels() []any {
|
||||
{{- if .Models}}
|
||||
return []any{
|
||||
{{- range .Models}}
|
||||
&{{.Package}}.{{.Ident}}{},
|
||||
{{- end}}
|
||||
}
|
||||
{{- else}}
|
||||
return nil
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
func generatedMigrations() []*gormigrate.Migration {
|
||||
{{- if .Migrations}}
|
||||
return []*gormigrate.Migration{
|
||||
{{- range .Migrations}}
|
||||
{{.Package}}.{{.Ident}}(),
|
||||
{{- end}}
|
||||
}
|
||||
{{- else}}
|
||||
return nil
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
func generatedCommands() []bonfire.Command {
|
||||
{{- if .Commands}}
|
||||
return []bonfire.Command{
|
||||
{{- range .Commands}}
|
||||
{{.Package}}.{{.Ident}}(),
|
||||
{{- end}}
|
||||
}
|
||||
{{- else}}
|
||||
return nil
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
func generatedJobs() []pact.Job {
|
||||
{{- if .Jobs}}
|
||||
return []pact.Job{
|
||||
{{- range .Jobs}}
|
||||
{{.Package}}.{{.Ident}}(),
|
||||
{{- end}}
|
||||
}
|
||||
{{- else}}
|
||||
return nil
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
func generatedAdminControllers() []pact.AdminController {
|
||||
{{- if .AdminControllers}}
|
||||
return []pact.AdminController{
|
||||
{{- range .AdminControllers}}
|
||||
{{.Package}}.{{.Ident}}(),
|
||||
{{- end}}
|
||||
}
|
||||
{{- else}}
|
||||
return nil
|
||||
{{- end}}
|
||||
}
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user