Class: Aircana::PluginManifest
- Inherits:
-
Object
- Object
- Aircana::PluginManifest
- 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
-
#plugin_root ⇒ Object
readonly
Returns the value of attribute plugin_root.
Class Method Summary collapse
-
.default_plugin_name(directory) ⇒ Object
Creates a default plugin name from a directory path.
Instance Method Summary collapse
-
#bump_version(type = :patch) ⇒ Object
Bumps the version number (major, minor, or patch).
-
#create(attributes = {}) ⇒ Object
Creates a new plugin manifest with the given attributes.
-
#exists? ⇒ Boolean
Checks if the plugin manifest exists.
-
#initialize(plugin_root) ⇒ PluginManifest
constructor
A new instance of PluginManifest.
-
#manifest_dir ⇒ Object
Returns the directory containing the manifest.
-
#manifest_path ⇒ Object
Returns the path to the plugin manifest.
-
#read ⇒ Object
Reads the existing plugin manifest.
-
#update(attributes = {}) ⇒ Object
Updates the plugin manifest with new values.
-
#validate! ⇒ Object
Validates the current manifest structure.
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_root ⇒ Object (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)
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
64 65 66 |
# File 'lib/aircana/plugin_manifest.rb', line 64 def exists? File.exist?(manifest_path) end |
#manifest_dir ⇒ Object
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_path ⇒ Object
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 |
#read ⇒ Object
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.}" 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
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 |