feat(sdk): add Kind and Categories to ModPlugin; writeMod emits them
This commit is contained in:
parent
aafdc44f6f
commit
08be22ec34
@ -503,6 +503,16 @@ func writeMod(path string, m *core.ModFile) error {
|
|||||||
b.WriteString(fmt.Sprintf("name = %q\n", m.Plugin.Name))
|
b.WriteString(fmt.Sprintf("name = %q\n", m.Plugin.Name))
|
||||||
b.WriteString(fmt.Sprintf("scope = %q\n", m.Plugin.Scope))
|
b.WriteString(fmt.Sprintf("scope = %q\n", m.Plugin.Scope))
|
||||||
b.WriteString(fmt.Sprintf("version = %q\n", m.Plugin.Version))
|
b.WriteString(fmt.Sprintf("version = %q\n", m.Plugin.Version))
|
||||||
|
if m.Plugin.Kind != "" {
|
||||||
|
b.WriteString(fmt.Sprintf("kind = %q\n", m.Plugin.Kind))
|
||||||
|
}
|
||||||
|
if len(m.Plugin.Categories) > 0 {
|
||||||
|
quoted := make([]string, len(m.Plugin.Categories))
|
||||||
|
for i, c := range m.Plugin.Categories {
|
||||||
|
quoted[i] = fmt.Sprintf("%q", c)
|
||||||
|
}
|
||||||
|
b.WriteString(fmt.Sprintf("categories = [%s]\n", strings.Join(quoted, ", ")))
|
||||||
|
}
|
||||||
if m.Compatibility != nil {
|
if m.Compatibility != nil {
|
||||||
b.WriteString("\n[compatibility]\n")
|
b.WriteString("\n[compatibility]\n")
|
||||||
b.WriteString(fmt.Sprintf("block_core = %q\n", m.Compatibility.BlockCore))
|
b.WriteString(fmt.Sprintf("block_core = %q\n", m.Compatibility.BlockCore))
|
||||||
|
|||||||
@ -14,6 +14,8 @@ type ModPlugin struct {
|
|||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
Scope string `toml:"scope"`
|
Scope string `toml:"scope"`
|
||||||
Version string `toml:"version"`
|
Version string `toml:"version"`
|
||||||
|
Kind string `toml:"kind,omitempty"`
|
||||||
|
Categories []string `toml:"categories,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModCompat struct {
|
type ModCompat struct {
|
||||||
|
|||||||
@ -64,6 +64,42 @@ func TestParseModFull_EmptyInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseModFull_KindAndCategories(t *testing.T) {
|
||||||
|
src := []byte(`
|
||||||
|
[plugin]
|
||||||
|
name = "analyser"
|
||||||
|
scope = "blockninja"
|
||||||
|
version = "0.1.0"
|
||||||
|
kind = "plugin"
|
||||||
|
categories = ["analytics", "seo"]
|
||||||
|
`)
|
||||||
|
m, err := ParseModFull(src)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseModFull err: %v", err)
|
||||||
|
}
|
||||||
|
if m.Plugin.Kind != "plugin" {
|
||||||
|
t.Errorf("Kind = %q, want plugin", m.Plugin.Kind)
|
||||||
|
}
|
||||||
|
if got := m.Plugin.Categories; len(got) != 2 || got[0] != "analytics" || got[1] != "seo" {
|
||||||
|
t.Errorf("Categories = %v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseModFull_KindDefaultsEmpty(t *testing.T) {
|
||||||
|
src := []byte(`
|
||||||
|
[plugin]
|
||||||
|
name = "legacy"
|
||||||
|
version = "0.1.0"
|
||||||
|
`)
|
||||||
|
m, err := ParseModFull(src)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseModFull err: %v", err)
|
||||||
|
}
|
||||||
|
if m.Plugin.Kind != "" {
|
||||||
|
t.Errorf("Kind should be empty for legacy mod, got %q", m.Plugin.Kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseModFull_RequiresAndCompat(t *testing.T) {
|
func TestParseModFull_RequiresAndCompat(t *testing.T) {
|
||||||
src := []byte(`
|
src := []byte(`
|
||||||
[plugin]
|
[plugin]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user