Sha256: d29273cada47360748c9cde1efffbbb781efd19fd6504c90327e62e6fd6edd50

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 Bytes

Contents

require 'fileutils'

module Middleman
  module Remover
    # Middleman Remover Extension
    class Extension < ::Middleman::Extension
      option :paths, [], 'List of remove files/directories paths'

      def initialize(app, options_hash = {}, &block)
        super
        paths     = options.paths
        build_dir = app.config.build_dir
        extension = self

        app.after_build do
          extension.remove(paths, build_dir)
        end
      end

      def remove(paths, dir)
        paths.each do |path|
          full_path = File.join(dir, path)
          files     = Dir.glob(full_path)

          if files.length > 0
            FileUtils.rm_rf(files)
            app.logger.info "== middleman-remover: #{path} is removed =="
          else
            app.logger.info "== middleman-remover: #{path} is not exist =="
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-remover-1.1.0 lib/middleman-remover/extension.rb