feat(plugins): add rudimentary plugin system

This commit is contained in:
kolaente
2025-07-24 12:14:19 +02:00
parent 813bdb58ff
commit b08b43953b
10 changed files with 297 additions and 0 deletions

View File

@@ -73,6 +73,7 @@ var (
"dev:make-event": Dev.MakeEvent,
"dev:make-listener": Dev.MakeListener,
"dev:make-notification": Dev.MakeNotification,
"plugins:build": Plugins.Build,
"lint": Check.Golangci,
"lint:fix": Check.GolangciFix,
"generate:config-yaml": Generate.ConfigYAML,
@@ -1393,3 +1394,26 @@ func generateConfigYAMLFromJSON(yamlPath string, commented bool) {
func (Generate) ConfigYAML(commented bool) {
generateConfigYAMLFromJSON(DefaultConfigYAMLSamplePath, commented)
}
type Plugins mg.Namespace
// Build compiles a Go plugin at the provided path.
func (Plugins) Build(pathToSourceFiles string) error {
mg.Deps(initVars)
if pathToSourceFiles == "" {
return fmt.Errorf("please provide a plugin path")
}
// Convert relative path to absolute path
if !strings.HasPrefix(pathToSourceFiles, "/") {
absPath, err := filepath.Abs(pathToSourceFiles)
if err != nil {
return fmt.Errorf("failed to resolve absolute path: %v", err)
}
pathToSourceFiles = absPath
}
out := filepath.Join(RootPath, "plugins", filepath.Base(pathToSourceFiles)+".so")
runAndStreamOutput("go", "build", "-buildmode=plugin", "-o", out, pathToSourceFiles)
return nil
}