diff --git a/cmd/ninja/cmd/plugin.go b/cmd/ninja/cmd/plugin.go index e833b54..09eaf99 100644 --- a/cmd/ninja/cmd/plugin.go +++ b/cmd/ninja/cmd/plugin.go @@ -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("scope = %q\n", m.Plugin.Scope)) 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 { b.WriteString("\n[compatibility]\n") b.WriteString(fmt.Sprintf("block_core = %q\n", m.Compatibility.BlockCore)) diff --git a/plugin/mod.go b/plugin/mod.go index 5f82f3c..9a8c993 100644 --- a/plugin/mod.go +++ b/plugin/mod.go @@ -11,9 +11,11 @@ type ModFile struct { } type ModPlugin struct { - Name string `toml:"name"` - Scope string `toml:"scope"` - Version string `toml:"version"` + Name string `toml:"name"` + Scope string `toml:"scope"` + Version string `toml:"version"` + Kind string `toml:"kind,omitempty"` + Categories []string `toml:"categories,omitempty"` } type ModCompat struct { diff --git a/plugin/mod_test.go b/plugin/mod_test.go index 8d645dd..a88368e 100644 --- a/plugin/mod_test.go +++ b/plugin/mod_test.go @@ -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) { src := []byte(` [plugin]