- plugin/types.go: Pool, EmailSender, JobHandlerFunc, Dependency, AdminPage, AIAction, MasterPageDefinition, status/source constants, MediaAnalyzedEvent, ModerationDecisionEvent, MediaHooksProvider, DirectoryExtensions - plugin/deps.go: ServiceDeps with typed capability interfaces (Content, Settings, Gating, Crypto, ToolRegistry, JobRunner, EmbeddingService, RAGService) - plugin/registration.go: PluginRegistration, RegisterFunc - plugin/service.go: ConnectServiceBinding with generics, ServiceMount, ServiceRegistration - plugin/provisioner.go: Provisioner interface with all config types - plugin/css_manifest.go: CSSManifest, MergedCSSManifest, MergeCSSManifests - plugin/version.go: ParseModVersion, CompareVersions - plugin/topo_sort.go: TopologicalSort (Kahn's algorithm) - plugin/block_registry.go: PluginBlockRegistry (auto-prefixing wrapper) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package plugin
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"strings"
|
|
|
|
"golang.org/x/mod/semver"
|
|
)
|
|
|
|
// ParseModVersion extracts the version string from an embedded plugin.mod file.
|
|
// Returns "0.0.0" if parsing fails or version is not found.
|
|
func ParseModVersion(data []byte) string {
|
|
scanner := bufio.NewScanner(bytes.NewReader(data))
|
|
for scanner.Scan() {
|
|
line := strings.TrimSpace(scanner.Text())
|
|
if strings.HasPrefix(line, "version") {
|
|
parts := strings.SplitN(line, "=", 2)
|
|
if len(parts) != 2 {
|
|
continue
|
|
}
|
|
val := strings.TrimSpace(parts[1])
|
|
val = strings.Trim(val, `"`)
|
|
if val != "" {
|
|
return val
|
|
}
|
|
}
|
|
}
|
|
return "0.0.0"
|
|
}
|
|
|
|
// CompareVersions compares two semver strings.
|
|
// Returns -1 if v1 < v2, 0 if equal, +1 if v1 > v2.
|
|
// Returns 0 if either version is invalid.
|
|
func CompareVersions(v1, v2 string) int {
|
|
if !strings.HasPrefix(v1, "v") {
|
|
v1 = "v" + v1
|
|
}
|
|
if !strings.HasPrefix(v2, "v") {
|
|
v2 = "v" + v2
|
|
}
|
|
if !semver.IsValid(v1) || !semver.IsValid(v2) {
|
|
return 0
|
|
}
|
|
return semver.Compare(v1, v2)
|
|
}
|