feat(build): mark scaffolded files with //summer:make and pass the app to generated commands (quick-261028-pq8)

- model, migration, command, job and admin-controller stubs start with
  //summer:make <kind>; registry.gen.go keeps its generated-code header
- the registry scan accepts the directive and the older header
- command functions may take one *backpack.App; generatedCommands takes a
  variadic app, so plugin.go files calling generatedCommands() still compile
- scaffolded plugins keep the app from Boot and return generatedCommands(p.app)
- make:command notes the nil app for an older plugin.go
- docs, help text and the blog example follow
This commit is contained in:
Jakub Zych
2026-10-28 19:04:39 +01:00
parent a95a014b52
commit 70e4b4183c
18 changed files with 355 additions and 61 deletions

View File

@@ -1,4 +1,4 @@
{{define "model.go"}}// Code generated by summer make. DO NOT EDIT.
{{define "model.go"}}//summer:make model
package models
@@ -14,7 +14,7 @@ type {{.Ident}} struct {
func ({{.Ident}}) TableName() string { return {{printf "%q" .Table}} }
{{end}}
{{define "migration.go"}}// Code generated by summer make. DO NOT EDIT.
{{define "migration.go"}}//summer:make migration
package updates
@@ -37,18 +37,21 @@ func {{.Func}}() *gormigrate.Migration {
}
{{end}}
{{define "command.go"}}// Code generated by summer make. DO NOT EDIT.
{{define "command.go"}}//summer:make command
package console
import (
"context"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
)
// {{.Func}} returns the {{.CommandName}} console command.
func {{.Func}}() bonfire.Command {
// {{.Func}} returns the {{.CommandName}} console command. app is the
// application the plugin kept from Boot: it gives the command the config and
// the services plugins publish (app.Lookup).
func {{.Func}}(app *backpack.App) bonfire.Command {
return bonfire.Command{
Name: {{printf "%q" .CommandName}},
Description: {{printf "%q" .Description}},
@@ -60,7 +63,7 @@ func {{.Func}}() bonfire.Command {
}
{{end}}
{{define "job.go"}}// Code generated by summer make. DO NOT EDIT.
{{define "job.go"}}//summer:make job
package jobs
@@ -84,7 +87,7 @@ func {{.Func}}() pact.Job {
}
{{end}}
{{define "admin_controller.go"}}// Code generated by summer make. DO NOT EDIT.
{{define "admin_controller.go"}}//summer:make admin-controller
package controllers

View File

@@ -32,13 +32,20 @@ var langFS embed.FS
var mailFS embed.FS
// Plugin is the {{.ID}} plugin.
type Plugin struct{}
type Plugin struct {
// app is the application, kept from Boot for the generated commands.
app *backpack.App
}
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) Boot(app *backpack.App) error {
p.app = app
return nil
}
func (p *Plugin) ConfigFS() fs.FS { return configFS }
func (p *Plugin) LangFS() fs.FS { return langFS }
@@ -47,10 +54,13 @@ 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) Models() []any { return generatedModels() }
func (p *Plugin) Migrations() []*gormigrate.Migration { return generatedMigrations() }
// Commands is collected after Boot, so p.app is set.
func (p *Plugin) Commands() []bonfire.Command { return generatedCommands(p.app) }
func (p *Plugin) Jobs() []pact.Job { return generatedJobs() }
func (p *Plugin) AdminControllers() []pact.AdminController {
return generatedAdminControllers()
}

View File

@@ -3,6 +3,7 @@
package {{.Package}}
import (
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/pact"
"github.com/go-gormigrate/gormigrate/v2"
@@ -35,11 +36,19 @@ func generatedMigrations() []*gormigrate.Migration {
{{- end}}
}
func generatedCommands() []bonfire.Command {
// generatedCommands returns the plugin's console commands. Commands that
// take a *backpack.App receive the first app passed in, or nil when none is.
func generatedCommands(app ...*backpack.App) []bonfire.Command {
{{- if .Commands}}
{{- if .AppCommands}}
var bootApp *backpack.App
if len(app) > 0 {
bootApp = app[0]
}
{{- end}}
return []bonfire.Command{
{{- range .Commands}}
{{.Package}}.{{.Ident}}(),
{{.Package}}.{{.Ident}}({{if .TakesApp}}bootApp{{end}}),
{{- end}}
}
{{- else}}