require 'fileutils' require 'json' require_relative './lib/cucumber_generator' $apis = {} def root File.expand_path(File.dirname(__FILE__) + '/../') end def models_path File.join(root, 'vendor', 'apis', 'apis') end def service_name(api) name = api['metadata']['serviceAbbreviation'] || api['metadata']['serviceFullName'] name = name.gsub(/^Amazon|AWS\s*|\(.*|\s+|\W+/, '') # Hack for special service names case name when 'ElasticLoadBalancing'; 'ELB' else name end end def add_tasks(model) model_path = File.join(models_path, model) api = JSON.parse(File.read(model_path), :max_nesting => false) klass = service_name(api) service = klass.downcase version = api['metadata']['apiVersion'] namespace :api do task :versions namespace(service) do task(:api) do verbose(false) do sh "#{root}/vendor/apis/scripts/translate-api #{model}" end end task(:cucumber) do unless File.exist?("#{root}/features/#{service}") sh "mkdir -p #{root}/features/#{service}/step_definitions" features = "#{root}/features/#{service}/#{service}.feature" step_defns = "#{root}/features/#{service}/step_definitions/#{service}.js" generator = CucumberGenerator.new(klass, service, api) File.open(features, "w") do |file| file.write(generator.features_file) end File.open(step_defns, "w") do |file| file.write(generator.step_definitions_file) end end end task(:version) do puts("%-40s\t%s" % [api['metadata']['serviceFullName'], version]) end task(:'version:internal') do ($apis[api['metadata']['serviceFullName']] ||= []) << [version, klass] end task(:'version:html') do puts "