Sha256: 0d992ee2fe972aca9289fb461e77fdcb7112d72ef0a71e9554966690c3c12c7b

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Bridgetown
  module Commands
    class Clean < Command
      class << self
        def init_with_program(prog)
          prog.command(:clean) do |c|
            c.syntax "clean [subcommand]"
            c.description "Clean the site " \
                  "(removes site output and metadata file) without building."

            add_build_options(c)

            c.action do |_, options|
              Bridgetown::Commands::Clean.process(options)
            end
          end
        end

        def process(options)
          options = configuration_from_options(options)
          destination = options["destination"]
          metadata_file = File.join(options["source"], ".bridgetown-metadata")
          cache_dir = File.join(options["source"], options["cache_dir"])

          remove(destination, checker_func: :directory?)
          remove(metadata_file, checker_func: :file?)
          remove(cache_dir, checker_func: :directory?)
        end

        def remove(filename, checker_func: :file?)
          if File.public_send(checker_func, filename)
            Bridgetown.logger.info "Cleaner:", "Removing #{filename}..."
            FileUtils.rm_rf(filename)
          else
            Bridgetown.logger.info "Cleaner:", "Nothing to do for #{filename}."
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
bridgetown-core-0.14.1 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.14.0 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.13.0 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.12.1 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.12.0 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.11.2 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.11.1 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.11.0 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.10.2 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.10.1 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.10.0 lib/bridgetown-core/commands/clean.rb
bridgetown-core-0.9.0 lib/bridgetown-core/commands/clean.rb