Class: Bridgetown::Commands::Plugins::List

Inherits:
Bridgetown::Command show all
Includes:
ConfigurationOverridable
Defined in:
bridgetown-core/lib/bridgetown-core/commands/plugins.rb

Instance Method Summary collapse

Methods included from ConfigurationOverridable

#configuration_with_overrides, include_options

Methods inherited from Bridgetown::Command

command_line, start, summary

Instance Method Details

#callObject

rubocop:disable Metrics



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'bridgetown-core/lib/bridgetown-core/commands/plugins.rb', line 13

def call # rubocop:disable Metrics
  config_options = configuration_with_overrides(@options)
  config_options.run_initializers! context: :static
  site = Bridgetown::Site.new(config_options)
  site.reset
  Bridgetown::Hooks.trigger :site, :pre_read, site

  plugins_list = config_options.initializers.values.sort_by(&:name)

  pm = site.plugin_manager

  plugins_list += pm.class.registered_plugins.to_a

  plugins_list.reject! do |plugin|
    plugin.to_s.end_with?("site_builder.rb") || plugin.to_s == "init (Initializer)"
  end

  Bridgetown.logger.info("Registered Plugins:", plugins_list.length.to_s.yellow.bold)

  plugins_list.each do |plugin|
    plugin_desc = plugin.to_s

    if plugin.is_a?(Bridgetown::Configuration::Initializer)
      Bridgetown.logger.info("", plugin_desc)
      Bridgetown.logger.debug(
        "", "PATH: #{plugin.block.source_location[0]}"
      )
    elsif plugin.is_a?(Bundler::StubSpecification) || plugin.is_a?(Gem::Specification)
      Bridgetown.logger.info("", "#{plugin.name} (Rubygem)")
      Bridgetown.logger.debug(
        "", "PATH: #{plugin.full_gem_path}"
      )
    else
      Bridgetown.logger.info("", plugin_desc.sub(site.in_root_dir("/"), ""))
    end

    Bridgetown.logger.debug("")
  end

  unless site.config.source_manifests.empty?
    Bridgetown.logger.info("Source Manifests:", "----")
  end

  site.config.source_manifests.each do |manifest|
    Bridgetown.logger.info("Origin:", (manifest.origin || "n/a").to_s.green)
    Bridgetown.logger.info("Components:", (manifest.components || "n/a").to_s.cyan)
    Bridgetown.logger.info("Contents:", (
      manifest.contents&.map { |k, v| "#{v} (#{k})" }&.join(", ") || "n/a"
    ).to_s.cyan)
    Bridgetown.logger.info("Layouts:", (manifest.layouts || "n/a").to_s.cyan)

    Bridgetown.logger.info("", "----")
  end

  unless Bridgetown.autoload? :Builder
    builders = Bridgetown::Builder.descendants
    Bridgetown.logger.info("Builders:", builders.length.to_s.yellow.bold)

    builders.sort.each do |builder|
      name = plugin_name_for(builder)
      name_components = name.split("::")
      last_name = name_components.pop
      name_components.push last_name.magenta
      Bridgetown.logger.info("", name_components.join("::"))
      Bridgetown.logger.debug(
        "", "PATH: #{builder_path_for(builder)}"
      )
      Bridgetown.logger.debug("")
    end
    Bridgetown.logger.info("", "----")
  end

  Bridgetown.logger.info("Converters:", site.converters.length.to_s.yellow.bold)

  site.converters.each do |converter|
    name = plugin_name_for(converter)
    name_components = name.split("::")
    last_name = name_components.pop
    name_components.push last_name.magenta
    Bridgetown.logger.info("", name_components.join("::"))
    Bridgetown.logger.debug(
      "", "PATH: #{converter_path_for(converter)}"
    )
    Bridgetown.logger.debug("")
  end

  Bridgetown.logger.info("", "----")

  Bridgetown.logger.info("Generators:", site.generators.length.to_s.yellow.bold)

  site.generators.each do |generator|
    name = plugin_name_for(generator)
    name_components = name.split("::")
    last_name = name_components.pop
    name_components.push last_name.magenta
    Bridgetown.logger.info("", name_components.join("::"))
    Bridgetown.logger.debug(
      "", "PATH: #{generator_path_for(generator)}"
    )
    Bridgetown.logger.debug("")
  end
end