2026-03-30 00:54:20 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
2026-03-29 23:59:48 +00:00
|
|
|
|
2026-03-06 13:20:12 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-29 23:59:48 +00:00
|
|
|
json "dappco.re/go/core/scm/internal/ax/jsonx"
|
2026-03-06 13:20:12 +00:00
|
|
|
|
2026-03-21 23:54:23 +00:00
|
|
|
"dappco.re/go/core/io"
|
2026-03-29 23:59:48 +00:00
|
|
|
coreerr "dappco.re/go/core/log"
|
2026-03-06 13:20:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Manifest represents a plugin.json manifest file.
|
|
|
|
|
// Each plugin repository must contain a plugin.json at its root.
|
|
|
|
|
type Manifest struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
Author string `json:"author"`
|
|
|
|
|
Entrypoint string `json:"entrypoint"`
|
|
|
|
|
Dependencies []string `json:"dependencies,omitempty"`
|
|
|
|
|
MinVersion string `json:"min_version,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadManifest reads and parses a plugin.json file from the given path.
|
2026-03-30 14:11:15 +00:00
|
|
|
// Usage: LoadManifest(...)
|
2026-03-06 13:20:12 +00:00
|
|
|
func LoadManifest(m io.Medium, path string) (*Manifest, error) {
|
|
|
|
|
content, err := m.Read(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, coreerr.E("plugin.LoadManifest", "failed to read manifest", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var manifest Manifest
|
|
|
|
|
if err := json.Unmarshal([]byte(content), &manifest); err != nil {
|
|
|
|
|
return nil, coreerr.E("plugin.LoadManifest", "failed to parse manifest JSON", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &manifest, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate checks the manifest for required fields.
|
|
|
|
|
// Returns an error if name, version, or entrypoint are missing.
|
2026-03-30 06:37:20 +00:00
|
|
|
// Usage: Validate(...)
|
2026-03-06 13:20:12 +00:00
|
|
|
func (m *Manifest) Validate() error {
|
|
|
|
|
if m.Name == "" {
|
|
|
|
|
return coreerr.E("plugin.Manifest.Validate", "name is required", nil)
|
|
|
|
|
}
|
|
|
|
|
if m.Version == "" {
|
|
|
|
|
return coreerr.E("plugin.Manifest.Validate", "version is required", nil)
|
|
|
|
|
}
|
|
|
|
|
if m.Entrypoint == "" {
|
|
|
|
|
return coreerr.E("plugin.Manifest.Validate", "entrypoint is required", nil)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|