Sha256: c20566105d1c9a94a1cb496ee100978f3996fa2f44edb86a979399af32ef1ed7

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Bridgetown
  module Commands
    class Configure < Thor::Group
      include Thor::Actions
      extend Summarizable

      Registrations.register do
        register(Configure, "configure", "configure CONFIGURATION", Configure.summary)
      end

      def self.banner
        "bridgetown configure CONFIGURATION(S)"
      end
      summary "Set up bundled Bridgetown configurations"

      def self.exit_on_failure?
        true
      end

      def perform_configurations
        logger = Bridgetown.logger
        list_configurations if args.empty?

        args.each do |configuration|
          configure configuration
        rescue Thor::Error
          logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
        end
      end

      def self.source_root
        File.expand_path("../configurations", __dir__)
      end

      protected

      def configure(configuration)
        configuration_file = find_in_source_paths("#{configuration}.rb")

        inside(New.created_site_dir || Dir.pwd) do
          Apply.new.invoke(:apply_automation, [configuration_file])
        end
      end

      def list_configurations
        say "Please specify a valid packaged configuration from the below list:\n\n"
        configurations.each do |configuration|
          configuration = set_color configuration, :blue, :bold
          say configuration
        end
        say "\n"

        docs_url = "https://www.bridgetownrb.com/docs/bundled-configurations".yellow.bold
        say "For more info, check out the docs at: #{docs_url}"
      end

      def configurations
        inside self.class.source_root do
          return Dir.glob("*.rb").map { |file| file.sub(".rb", "") }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bridgetown-core-0.21.0.beta2 lib/bridgetown-core/commands/configure.rb
bridgetown-core-0.21.0.beta1 lib/bridgetown-core/commands/configure.rb
bridgetown-core-0.20.0 lib/bridgetown-core/commands/configure.rb