Class: Aircana::PluginManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/aircana/plugin_manifest.rb

Overview

Manages Claude Code plugin manifest (plugin.json) files

Constant Summary collapse

REQUIRED_FIELDS =

rubocop:disable Metrics/ClassLength

%w[name version].freeze
OPTIONAL_FIELDS =
%w[description author homepage repository license keywords commands agents hooks
mcpServers].freeze
ALL_FIELDS =
(REQUIRED_FIELDS + OPTIONAL_FIELDS).freeze
PATH_OVERRIDE_FIELDS =
%w[commands agents hooks mcpServers].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin_root) ⇒ PluginManifest

Returns a new instance of PluginManifest.



17
18
19
# File 'lib/aircana/plugin_manifest.rb', line 17

def initialize(plugin_root)
  @plugin_root = plugin_root
end

Instance Attribute Details

#plugin_rootObject (readonly)

Returns the value of attribute plugin_root.



15
16
17
# File 'lib/aircana/plugin_manifest.rb', line 15

def plugin_root
  @plugin_root
end

Class Method Details

.default_plugin_name(directory) ⇒ Object

Creates a default plugin name from a directory path



171
172
173
# File 'lib/aircana/plugin_manifest.rb', line 171

def default_plugin_name(directory)
  File.basename(directory).downcase.gsub(/[^a-z0-9]+/, "-")
end

Instance Method Details

#bump_version(type = :patch) ⇒ Object

Bumps the version number (major, minor, or patch)

Raises:



52
53
54
55
56
57
58
59
60
61
# File 'lib/aircana/plugin_manifest.rb', line 52

def bump_version(type = :patch)
  current_data = read
  raise Aircana::Error, "No plugin manifest found at #{manifest_path}" unless current_data

  current_version = current_data["version"]
  new_version = bump_semantic_version(current_version, type)

  update("version" => new_version)
  new_version
end

#create(attributes = {}) ⇒ Object

Creates a new plugin manifest with the given attributes



22
23
24
25
26
27
28
29
# File 'lib/aircana/plugin_manifest.rb', line 22

def create(attributes = {})
  validate_required_fields!(attributes)

  manifest_data = build_manifest_data(attributes)
  write_manifest(manifest_data)

  manifest_path
end

#exists?Boolean

Checks if the plugin manifest exists

Returns:

  • (Boolean)


64
65
66
# File 'lib/aircana/plugin_manifest.rb', line 64

def exists?
  File.exist?(manifest_path)
end

#manifest_dirObject

Returns the directory containing the manifest



74
75
76
# File 'lib/aircana/plugin_manifest.rb', line 74

def manifest_dir
  File.join(plugin_root, ".claude-plugin")
end

#manifest_pathObject

Returns the path to the plugin manifest



69
70
71
# File 'lib/aircana/plugin_manifest.rb', line 69

def manifest_path
  File.join(plugin_root, ".claude-plugin", "plugin.json")
end

#readObject

Reads the existing plugin manifest



32
33
34
35
36
37
38
# File 'lib/aircana/plugin_manifest.rb', line 32

def read
  return nil unless exists?

  JSON.parse(File.read(manifest_path))
rescue JSON::ParserError => e
  raise Aircana::Error, "Invalid JSON in plugin manifest: #{e.message}"
end

#update(attributes = {}) ⇒ Object

Updates the plugin manifest with new values



41
42
43
44
45
46
47
48
49
# File 'lib/aircana/plugin_manifest.rb', line 41

def update(attributes = {})
  current_data = read || {}
  updated_data = current_data.merge(attributes.transform_keys(&:to_s))

  validate_required_fields!(updated_data)
  write_manifest(updated_data)

  manifest_path
end

#validate!Object

Validates the current manifest structure

Raises:



79
80
81
82
83
84
85
86
87
# File 'lib/aircana/plugin_manifest.rb', line 79

def validate!
  data = read
  raise Aircana::Error, "No plugin manifest found" unless data

  validate_required_fields!(data)
  validate_version_format!(data["version"])

  true
end