feat(01-03): add make:plugin and plugin:add scaffolding

- Scaffold a compiling vendor.plugin module with go.mod, plugin.go and config/
- Register the module once in summer.yaml, go.work and the app go.mod
- Keep summer build on the same generate-and-compile path and print elapsed time
This commit is contained in:
Jakub Zych
2026-09-16 13:47:27 +02:00
parent 46a1ce904a
commit 9b1a25dc94
6 changed files with 1077 additions and 150 deletions

View File

@@ -10,7 +10,7 @@ import (
)
func main() {
root := bonfire.NewRoot("summer", []bonfire.Command{buildCommand()}, os.Stdout)
root := bonfire.NewRoot("summer", toolCommands(), os.Stdout)
root.SetArgs(os.Args[1:])
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
@@ -18,6 +18,14 @@ func main() {
}
}
func toolCommands() []bonfire.Command {
return []bonfire.Command{
buildCommand(),
makePluginCommand(),
addPluginCommand(),
}
}
func buildCommand() bonfire.Command {
return bonfire.Command{
Name: "build",
@@ -31,3 +39,58 @@ func buildCommand() bonfire.Command {
},
}
}
func makePluginCommand() bonfire.Command {
return bonfire.Command{
Name: "make:plugin",
Description: "Scaffold a compiling plugin module from a vendor.plugin id",
Args: []bonfire.Arg{{
Name: "id",
Description: "Plugin ID in vendor.plugin form",
Required: true,
}},
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
id, ok := in.Argument("id")
if !ok || id == "" {
return fmt.Errorf("make:plugin requires a vendor.plugin id")
}
dir, err := os.Getwd()
if err != nil {
return err
}
created, err := build.MakePlugin(ctx, dir, id)
if err != nil {
return err
}
out.Printf("created %s\n", created)
return nil
},
}
}
func addPluginCommand() bonfire.Command {
return bonfire.Command{
Name: "plugin:add",
Description: "Register a local plugin module in the app manifest and workspace",
Args: []bonfire.Arg{{
Name: "dir",
Description: "Local plugin directory",
Required: true,
}},
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
pluginDir, ok := in.Argument("dir")
if !ok || pluginDir == "" {
return fmt.Errorf("plugin:add requires a local plugin directory")
}
dir, err := os.Getwd()
if err != nil {
return err
}
if err := build.AddPlugin(ctx, dir, pluginDir); err != nil {
return err
}
out.Printf("added %s\n", pluginDir)
return nil
},
}
}

View File

@@ -1,15 +1,41 @@
package main
import (
"bytes"
"go/parser"
"go/token"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
"testing"
"git.golem15.com/golem15/summercms/bonfire"
)
func TestToolCommandNames(t *testing.T) {
var names []string
for _, c := range toolCommands() {
names = append(names, c.Name)
}
for _, want := range []string{"build", "make:plugin", "plugin:add"} {
if !slices.Contains(names, want) {
t.Fatalf("missing %s in %v", want, names)
}
}
var buf bytes.Buffer
root := bonfire.NewRoot("summer", toolCommands(), &buf)
root.SetArgs([]string{"make:plugin", "--help"})
if err := root.Execute(); err != nil {
t.Fatal(err)
}
if !strings.Contains(buf.String(), "vendor.plugin") {
t.Fatalf("make:plugin help missing argument text:\n%s", buf.String())
}
}
func TestToolDoesNotImportExamplePlugins(t *testing.T) {
roots := []string{".", filepath.Join("..", "..", "internal", "build")}
fset := token.NewFileSet()