Files
summercms/cmd/summer/main.go
Jakub Zych 9b1a25dc94 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
2026-09-16 13:47:27 +02:00

97 lines
2.2 KiB
Go

package main
import (
"context"
"fmt"
"os"
"git.golem15.com/golem15/summercms/bonfire"
"git.golem15.com/golem15/summercms/internal/build"
)
func main() {
root := bonfire.NewRoot("summer", toolCommands(), os.Stdout)
root.SetArgs(os.Args[1:])
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func toolCommands() []bonfire.Command {
return []bonfire.Command{
buildCommand(),
makePluginCommand(),
addPluginCommand(),
}
}
func buildCommand() bonfire.Command {
return bonfire.Command{
Name: "build",
Description: "Generate plugin imports and build the app binary",
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
dir, err := os.Getwd()
if err != nil {
return err
}
return build.App(ctx, dir, out)
},
}
}
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
},
}
}