lib/aws/cfn/compiler.rb in aws-cfn-compiler-0.0.8 vs lib/aws/cfn/compiler.rb in aws-cfn-compiler-0.1.0

- old
+ new

@@ -49,21 +49,21 @@ Mappings: @items['mappings'], Resources: @items['resources'], Outputs: @items['outputs'], } - output_file = @opts[:output] || 'compiled.json' puts - puts "Writing compiled file to #{output_file}..." - save(compiled, output_file) - - puts puts 'Validating compiled file...' validate(compiled) + output_file = @opts[:output] || 'compiled.json' puts + puts "Writing compiled file to #{output_file}..." + save(compiled, output_file) + + puts puts '*** Compiled Successfully ***' end def validate(compiled) raise 'No resources!?' unless compiled[:Resources] @@ -120,11 +120,11 @@ @spec = spec else raise "Unable to open specification: #{abs}" end end - %w{params mappings resources outputs}.each do |dir| + %w{Params Mappings Resources Outputs}.each do |dir| load_dir(dir,spec) end end protected @@ -151,13 +151,22 @@ end end def load_dir(dir,spec=nil) puts "Loading #{dir}..." - @items[dir] = {} raise "No such directory: #{@opts[:directory]}" unless File.directory?(@opts[:directory]) - (Dir[File.join(@opts[:directory], "#{dir}.*")] | Dir[File.join(@opts[:directory], dir, "**", "*")]).collect do |filename| + set = [] + if File.directory?(File.join(@opts[:directory], dir)) + @items[dir] = {} + set = get_file_set(dir) + else + if File.directory?(File.join(@opts[:directory], dir.downcase)) + @items[dir] = {} + set = get_file_set(dir.downcase) + end + end + set.collect do |filename| next unless filename =~ /\.(json|ya?ml)\z/i if spec and spec[dir] base = File.basename(filename).gsub(%r/\.(rb|yaml)/, '') next unless spec[dir].include?(base) puts "\tUsing #{dir}/#{base}" @@ -179,9 +188,13 @@ rescue puts " !! error: #{$!}" abort! end end + end + + def get_file_set(dir) + Dir[File.join(@opts[:directory], "#{dir}.*")] | Dir[File.join(@opts[:directory], dir, "**", "*")] end end end end