53 lines
1.2 KiB
Ruby
53 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'json'
|
|
require 'fileutils'
|
|
require_relative '../file_locations'
|
|
require_relative '../file_verifier'
|
|
|
|
module PluginConfig
|
|
module Operations
|
|
class Base
|
|
attr_reader :plugin, :marketplace, :project, :marketplace_file
|
|
|
|
def initialize(params)
|
|
@plugin = params[:plugin]
|
|
@marketplace = params[:marketplace]
|
|
@project = params[:project]
|
|
@marketplace_file = params[:marketplace_file]
|
|
end
|
|
|
|
private
|
|
|
|
def plugin_key
|
|
"#{plugin}@#{marketplace}"
|
|
end
|
|
|
|
def read_json(path)
|
|
return nil unless File.exist?(path)
|
|
|
|
JSON.parse(File.read(path))
|
|
rescue JSON::ParserError
|
|
nil
|
|
end
|
|
|
|
def write_json(path, data)
|
|
FileUtils.mkdir_p(File.dirname(path))
|
|
content = JSON.pretty_generate(data, indent: ' ') + "\n"
|
|
File.write(path, content)
|
|
|
|
verifier = FileVerifier.new(path)
|
|
verifier.verify_written(content)
|
|
end
|
|
|
|
def settings_path
|
|
File.join(project, '.claude', 'settings.json')
|
|
end
|
|
|
|
def installed_plugins_path
|
|
File.join(Dir.home, '.claude', 'plugins', 'installed_plugins.json')
|
|
end
|
|
end
|
|
end
|
|
end
|