Sha256: dd1c0669f1f80167fd048ec255c0627d68afc42d88a522db2a8661d3b83deab6

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require 'ftools'
require 'yaml'

class FeaturePackager
  include RunCommand
  include YAMLConfig
  include Logging

  attr_accessor :source_dir, :package_dir, :valid_file_types

  def initialize()
    @valid_file_types = ['aspx', 'ascx', 'js', 'css', 'png', 'gif', 'jpeg', 'dll']
  end

  def execute()
    raise "Please specify the directory where the features to package exist" if @source_dir.nil?
    raise "Please specify the directory packages should be placed into" if @package_dir.nil?

    Dir[@source_dir + '/**/.feature'].each do |feature|
      next if File.basename(File.dirname(feature)).downcase == File.basename(@source_dir).downcase

      feature_config = YAML.load(File.read(feature))
      raise "The feature config does not contain the destination name" if !feature_config.has_key?('destination_name')

      destination = File.expand_path(File.join(@package_dir, feature_config['destination_name']))
      FileUtils.mkdir_p(destination)

      feature_root = File.expand_path(File.dirname(feature) + '/../')

      Dir[feature_root  + '/**/**'].each do |file|
        next if File.directory?(file)
        next if is_not_valid_file_type(file)
        file_destination = File.join(destination, file.gsub(/#{feature_root}/, ''))
        FileUtils.mkdir_p(File.dirname(file_destination)) if(!File.exists?(File.dirname(file_destination)))
        File.copy(file, file_destination)
      end
    end
  end

  private

  def is_not_valid_file_type(file)
    @valid_file_types.each do |v|
      return false if !file.match(/\.#{v}$/).nil?
    end
    return true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seabass-0.2.2 lib/seabass/feature_packager.rb