class Stimulus::Generators::ComponentGenerator

def create_stimulus_controller

def create_stimulus_controller
  template "component_controller.#{filetype}", destination
end

def destination

def destination
  if sidecar?
    File.join(component_path, class_path, "#{file_name}_component", "#{file_name}_component_controller.#{filetype}")
  else
    File.join(component_path, class_path, "#{file_name}_component_controller.#{filetype}")
  end
end

def filetype

def filetype
  typescript? ? "ts" : "js"
end

def legacy_stimulus?

def legacy_stimulus?
  package_json_pathname = Rails.root.join("package.json")
  package_json_pathname.exist? && JSON.parse(package_json_pathname.read).dig("dependencies", "stimulus").present?
end

def stimulus_module

def stimulus_module
  return "stimulus" if legacy_stimulus?
  "@hotwired/stimulus"
end