Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add API and documentation tasks

  • Loading branch information...
commit d837c9bc7d8aba48a3ccce4769389e25f033eeea 1 parent d8e381e
@lsegal lsegal authored
View
115 Rakefile
@@ -1,119 +1,16 @@
-require 'json'
-
-def write_configuration
- config = {}
- if File.exist?('configuration')
- config = JSON.parse(File.read('configuration'))
- config['accessKeyId'] ||= ENV['AWS_ACCESS_KEY_ID']
- config['secretAccessKey'] ||= ENV['AWS_SECRET_ACCESS_KEY']
- end
- File.open('test/configuration.js', 'w') do |f|
- config_json = JSON.generate(config).inspect
- f.puts "module.exports = JSON.parse(#{config_json});"
- end
-end
-
-def sdk_version
- JSON.parse(File.read('package.json'))['version']
-end
+require 'bundler/setup'
LOGLEVEL = ($DEBUG || ENV['DEBUG']) ? '' : '-s'
task :default => 'test:all'
-desc 'Install dependencies'
-task :setup do
- system "npm #{LOGLEVEL} install"
-end
-
-namespace :browser do
- $BUILDER = "./dist-tools/browser-builder.js"
- $BROWSERIFY = "./dist-tools/node_modules/.bin/browserify"
- $BROWSERIFY_ARGS = "-i domain -t ./dist-tools/bundle-transform lib/aws.js"
- $BROWSERIFY_DIST = "dist/aws-sdk-#{sdk_version}.js"
- $BROWSERIFY_DIST_LATEST = "dist/aws-sdk.js"
- $BROWSERIFY_TEST = "dist/tests.js"
-
- task :all => [:build, :test]
-
- desc 'Builds browser distributable (SERVICES=s3,dynamodb,...)'
- task :build => :build_complete do
- sh "MINIFY=1 #{$BUILDER} > #{$BROWSERIFY_DIST.sub('.js', '.min.js')}"
- end
-
- task :build_complete => :dist_path do
- sh "MINIFY='' #{$BUILDER} > #{$BROWSERIFY_DIST}"
- cp $BROWSERIFY_DIST, $BROWSERIFY_DIST_LATEST
- end
-
- task :build_server do
- pkg_file = File.dirname(__FILE__) + '/dist-tools/package.json'
- json = JSON.parse(File.read(pkg_file))
- local_json = JSON.parse(File.read(File.dirname(__FILE__) + '/package.json'))
- json['dependencies'].update(local_json['dependencies'])
- File.open(pkg_file, 'w') do |f|
- f.puts(JSON.pretty_generate(json, indent: ' '))
- end
-
- rm_f "#{json['name']}.tar.gz"
- rm_f "#{json['name']}.zip"
- cp_r 'dist-tools', 'server'
- cp_r 'lib', 'server/aws-sdk'
- Dir.chdir('server') do
- sh "npm install"
- sh "zip -rq ../#{json['name']}.zip *"
- sh "tar cfz ../#{json['name']}.tgz *"
- end
- rm_rf 'server'
- end
-
- desc 'Builds browser test harness and runner'
- task :test => :dist_path do
- write_configuration
- sh "coffee -c test/helpers.coffee"
- sh "find test -name '*.coffee' | SERVICES=all xargs #{$BROWSERIFY} " +
- "-t coffeeify #{$BROWSERIFY_ARGS} > #{$BROWSERIFY_TEST}"
- rm_f "test/helpers.js"
- rm_f "test/configuration.js"
- puts "Now run `testem`"
- sh "open dist/tests.html" if ENV['OPEN']
- end
-
- task :dist_path do
- mkdir_p 'dist'
- end
-end
-
-namespace :test do
- desc "Runs all tests"
- task :all => :build do
- sh "npm #{LOGLEVEL} test"
- end
-
- desc "Runs unit tests"
- task :unit => :build do
- sh "npm #{LOGLEVEL} run-script unit"
- end
-
- desc "Runs integration tests"
- task :integration => :build do
- sh "npm #{LOGLEVEL} run-script integration"
- end
-
-end
-
-desc 'Runs JSHint'
-task :lint do
- sh "npm #{LOGLEVEL} run-script lint"
-end
-
-desc 'Interactive console'
-task :console do
- system './scripts/console'
-end
-
# Vendor tasks
root = File.dirname(__FILE__)
Dir[File.join(root, 'vendor', '*', 'Rakefile')].each do |vendor_rakefile|
load vendor_rakefile
end
+
+# Local tasks
+Dir[File.join(root, 'tasks', '**', '*.rake')].each do |task_file|
+ load task_file
+end
View
144 tasks/apis.rake
@@ -0,0 +1,144 @@
+require 'fileutils'
+require 'json'
+
+require_relative './lib/service_generator'
+require_relative './lib/services_loader_generator'
+require_relative './lib/cucumber_generator'
+
+$apis = {}
+
+def root
+ File.expand_path(File.dirname(__FILE__) + '/../')
+end
+
+def models_path
+ File.join(root, 'apis', 'source')
+end
+
+def service_name(api)
+ name = api['service_abbreviation'] || api['service_full_name']
+ name = name.gsub(/^Amazon|AWS\s*|\(.*|\s+|\W+/, '')
+
+ # Hack for special service names
+ case name
+ when 'ElasticLoadBalancing'; 'ELB'
+ when 'SWF'; 'SimpleWorkflow'
+ else name
+ end
+end
+
+def add_tasks model
+ model = model.gsub(/\.json$/, '')
+ model_path = File.join(models_path, "#{model}.json")
+ api = JSON.parse(File.read(model_path), :max_nesting => false)
+ klass = service_name(api)
+ service = klass.downcase
+ version = api['api_version']
+
+ namespace :api do
+ task :versions
+
+ namespace(service) do
+ task(:class) do
+ target = "#{root}/lib/services/#{service}.js"
+ unless File.exist?(target)
+ File.open(target, 'w') do |file|
+ file.write ServiceGenerator.new(klass, service, version).to_s
+ end
+ end
+ end
+
+ task(:loader_file) do
+ target = "#{root}/lib/services.js"
+ File.open(target, 'w') do |file|
+ file.write ServicesLoaderGenerator.new(root).to_s
+ end
+ end
+
+ task(:api) do
+ verbose(false) do
+ sh "#{root}/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['service_full_name'], version])
+ end
+
+ task(:'version:internal') do
+ ($apis[api['service_full_name']] ||= []) << [version, klass]
+ end
+
+ task(:'version:html') do
+ puts "<tr>\n <td>#{api['service_full_name']}</td>"
+ puts " <td>#{version}</td>\n <td>AWS.#{klass}</td>\n</tr>"
+ end
+
+ task(:'version:md') do
+ base = "http://docs.amazonwebservices.com/AWSJavaScriptSDK/latest/frames.html"
+ anchor = "#!AWS/#{klass}.html"
+ puts "* [AWS.#{klass}](#{base}#{anchor})"
+ end
+ end
+
+ desc "Builds the API for #{service}."
+ task service => [
+ "#{service}:class",
+ "#{service}:api",
+ "#{service}:cucumber",
+ "#{service}:loader_file",
+ ]
+
+ task :api => "#{service}:api"
+ task :versions => ["api:#{service}:version"]
+ task :'versions:md' => ["api:#{service}:version:md"]
+ task :'versions:internal' => ["api:#{service}:version:internal"]
+
+ task :all => service
+ end
+end
+
+namespace :api do
+ task :'versions:html' => :'api:versions:internal' do
+ # 1 row per service (with rowspan to deal with multiple api versions)
+ rows = ''
+ $apis.sort_by{|svc,apis| svc.downcase }.each do |(svc,apis)|
+ rowspan = apis.length > 1 ? " rowspan=\"#{apis.length}\"" : ''
+ rows << "<tr>"
+ rows << "<td#{rowspan}>#{svc}</td>"
+ rows << "<td#{rowspan}>AWS.#{apis.first.last}</td>" if ENV['README']
+ rows << "<td>#{apis.first.first}</td>"
+ rows << "</tr>\n"
+ apis[1..-1].each do |api|
+ rows << "<tr>"
+ rows << "<td>#{api.first}</td>"
+ rows << "</tr>\n"
+ end
+ end
+ puts rows
+ end
+end
+
+desc 'Builds the API for each service.'
+task :api => 'api:all'
+
+Dir.glob(File.join(models_path, '*.json')).sort.each do |file|
+ add_tasks(File.basename(file))
+end
View
76 tasks/browser.rake
@@ -0,0 +1,76 @@
+require 'json'
+
+def write_configuration
+ config = {}
+ if File.exist?('configuration')
+ config = JSON.parse(File.read('configuration'))
+ config['accessKeyId'] ||= ENV['AWS_ACCESS_KEY_ID']
+ config['secretAccessKey'] ||= ENV['AWS_SECRET_ACCESS_KEY']
+ end
+ File.open('test/configuration.js', 'w') do |f|
+ config_json = JSON.generate(config).inspect
+ f.puts "module.exports = JSON.parse(#{config_json});"
+ end
+end
+
+def sdk_version
+ JSON.parse(File.read('package.json'))['version']
+end
+
+namespace :browser do
+ $BUILDER = "./dist-tools/browser-builder.js"
+ $BROWSERIFY = "./dist-tools/node_modules/.bin/browserify"
+ $BROWSERIFY_ARGS = "-i domain -t ./dist-tools/bundle-transform lib/aws.js"
+ $BROWSERIFY_DIST = "dist/aws-sdk-#{sdk_version}.js"
+ $BROWSERIFY_DIST_LATEST = "dist/aws-sdk.js"
+ $BROWSERIFY_TEST = "dist/tests.js"
+
+ task :all => [:build, :test]
+
+ desc 'Builds browser distributable (SERVICES=s3,dynamodb,...)'
+ task :build => :build_complete do
+ sh "MINIFY=1 #{$BUILDER} > #{$BROWSERIFY_DIST.sub('.js', '.min.js')}"
+ end
+
+ task :build_complete => :dist_path do
+ sh "MINIFY='' #{$BUILDER} > #{$BROWSERIFY_DIST}"
+ cp $BROWSERIFY_DIST, $BROWSERIFY_DIST_LATEST
+ end
+
+ task :build_server do
+ pkg_file = File.dirname(__FILE__) + '/dist-tools/package.json'
+ json = JSON.parse(File.read(pkg_file))
+ local_json = JSON.parse(File.read(File.dirname(__FILE__) + '/package.json'))
+ json['dependencies'].update(local_json['dependencies'])
+ File.open(pkg_file, 'w') do |f|
+ f.puts(JSON.pretty_generate(json, indent: ' '))
+ end
+
+ rm_f "#{json['name']}.tar.gz"
+ rm_f "#{json['name']}.zip"
+ cp_r 'dist-tools', 'server'
+ cp_r 'lib', 'server/aws-sdk'
+ Dir.chdir('server') do
+ sh "npm install"
+ sh "zip -rq ../#{json['name']}.zip *"
+ sh "tar cfz ../#{json['name']}.tgz *"
+ end
+ rm_rf 'server'
+ end
+
+ desc 'Builds browser test harness and runner'
+ task :test => :dist_path do
+ write_configuration
+ sh "coffee -c test/helpers.coffee"
+ sh "find test -name '*.coffee' | SERVICES=all xargs #{$BROWSERIFY} " +
+ "-t coffeeify #{$BROWSERIFY_ARGS} > #{$BROWSERIFY_TEST}"
+ rm_f "test/helpers.js"
+ rm_f "test/configuration.js"
+ puts "Now run `testem`"
+ sh "open dist/tests.html" if ENV['OPEN']
+ end
+
+ task :dist_path do
+ mkdir_p 'dist'
+ end
+end
View
30 tasks/docs.rake
@@ -0,0 +1,30 @@
+namespace :docs do
+ task :directory do
+ mkdir_p "doc"
+ end
+
+ desc "Build API documentation"
+ task :api => :directory do
+ ENV['SITEMAP_BASEURL'] = 'http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/'
+
+ rm_rf "doc/latest"
+ args = ENV['ARGS'] ? ENV['ARGS'] : []
+ sh "bundle exec yard #{args.join(' ')}"
+ end
+
+ desc "Build guide documentation"
+ task :guide => :directory do
+ ENV['SITEMAP_BASEURL'] = 'http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/'
+
+ rm_rf "doc/guide"
+ args = %w(-q --yardopts .yardopts_guide)
+ args += ENV['ARGS'].split(/\s+/) if ENV['ARGS']
+ sh "bundle exec yard #{args.join(' ')}"
+ end
+
+ desc "Builds API and guide documentation"
+ task :all => [:api, :guide]
+end
+
+desc "Builds all documentation"
+task :docs => ['docs:all']
View
40 tasks/lib/cucumber_generator.rb
@@ -0,0 +1,40 @@
+# Generates features/service/* files
+class CucumberGenerator
+ def initialize(klass, service, api)
+ @klass = klass
+ @service = service
+ @api = api
+ end
+
+ def features_file
+ <<-eof
+# language: en
+@#{@service}
+Feature: #{@api['service_full_name']}
+
+ I want to use #{@api['service_full_name']}
+
+ Scenario: Feature
+ Given I create something with the service
+ Then the request should be successful
+ And I delete the thing I created
+
+ Scenario: Error handling
+ Given I do something with the service
+ Then the error code should be "ValidationError"
+ eof
+ end
+
+ def step_definitions_file
+ <<-eof
+module.exports = function() {
+ this.Before("@#{@service}", function (callback) {
+ this.service = new this.AWS.#{@klass}();
+ callback();
+ });
+
+ // Add step definitions
+};
+ eof
+ end
+end
View
18 tasks/lib/service_generator.rb
@@ -0,0 +1,18 @@
+# Generates a boilerplate service class file
+class ServiceGenerator
+ def initialize(klass, service, api)
+ @klass = klass
+ @service = service
+ @api = api
+ end
+
+ def to_s
+ <<-eof
+var AWS = require('../core');
+
+AWS.#{@klass} = AWS.Service.defineService('#{@service}', ['#{@api}']);
+
+module.exports = AWS.#{@klass};
+ eof
+ end
+end
View
20 tasks/lib/services_loader_generator.rb
@@ -0,0 +1,20 @@
+# Generates lib/aws.rb which requires all service files
+class ServicesLoaderGenerator
+ def initialize(root)
+ @requires = []
+
+ apis = Dir.glob(File.join(root, 'lib', 'services', '*.js'))
+ apis.sort.each do |api|
+ service = File.basename(api).split('.').first
+ @requires << "require('./services/#{service}');"
+ end
+ end
+
+ def to_s
+ <<-eof
+/* This file is auto-generated. DO NOT EDIT. */
+
+#{@requires.join("\n")}
+ eof
+ end
+end
View
33 tasks/util.rake
@@ -0,0 +1,33 @@
+desc 'Install dependencies'
+task :setup do
+ system "npm #{LOGLEVEL} install"
+ system "bundle install"
+end
+
+namespace :test do
+ desc "Runs all tests"
+ task :all => :build do
+ sh "npm #{LOGLEVEL} test"
+ end
+
+ desc "Runs unit tests"
+ task :unit => :build do
+ sh "npm #{LOGLEVEL} run-script unit"
+ end
+
+ desc "Runs integration tests"
+ task :integration => :build do
+ sh "npm #{LOGLEVEL} run-script integration"
+ end
+
+end
+
+desc 'Runs JSHint'
+task :lint do
+ sh "npm #{LOGLEVEL} run-script lint"
+end
+
+desc 'Interactive console'
+task :console do
+ system './scripts/console'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.