2011-06-08 01:46:50 +04:00
|
|
|
require 'erb'
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
def linux?
|
|
|
|
RUBY_PLATFORM.include?("linux")
|
|
|
|
end
|
|
|
|
|
2011-06-08 01:46:50 +04:00
|
|
|
ROOT_DIR = File.expand_path(File.dirname(__FILE__))
|
|
|
|
BUILD_DIR = File.join(ROOT_DIR, "build")
|
|
|
|
SPEC_DIR = File.join(ROOT_DIR, "spec")
|
|
|
|
LIB_DIR = File.join(ROOT_DIR, "lib")
|
|
|
|
TARGET_DIR = File.join(ROOT_DIR, "target")
|
|
|
|
SPEC_RUNNER = File.join(SPEC_DIR, "SpecRunner.html")
|
2013-02-21 19:55:54 +04:00
|
|
|
JSBN_DIR = File.join(LIB_DIR, "jsbn")
|
2011-06-08 01:46:50 +04:00
|
|
|
SJCL_DIR = File.join(LIB_DIR, "sjcl/core")
|
|
|
|
|
2013-05-22 20:14:48 +04:00
|
|
|
BRAINTREE_VERSION = File.read("#{LIB_DIR}/braintree.js")[/version: \"([0-9.]+)\"/, 1]
|
2011-06-08 01:46:50 +04:00
|
|
|
|
|
|
|
task :default => "test:run_default"
|
|
|
|
|
|
|
|
namespace :test do
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "test in all browsers"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :all do
|
|
|
|
%w[chrome safari firefox].each do |browser|
|
|
|
|
Rake::Task["test:run_#{browser}"].invoke
|
|
|
|
sleep 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-25 23:08:54 +04:00
|
|
|
desc "clean up old SpecRunner.html"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :clean do
|
|
|
|
rm_rf "#{File.dirname(__FILE__)}/spec/SpecRunner.html"
|
|
|
|
end
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "prepare to run specs"
|
2013-04-25 23:08:54 +04:00
|
|
|
task :prepare => ["test:clean", "build"] do
|
2011-06-08 01:46:50 +04:00
|
|
|
template = ERB.new(File.read("#{SPEC_DIR}/SpecRunner.html.erb"))
|
|
|
|
spec_files = Dir.glob("#{SPEC_DIR}/*.js")
|
|
|
|
|
|
|
|
result = template.result(binding)
|
|
|
|
|
|
|
|
File.open("#{SPEC_DIR}/SpecRunner.html", "w") do |f|
|
|
|
|
f << result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "test in chrome"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :run_chrome => :prepare do
|
2013-02-21 19:55:54 +04:00
|
|
|
if linux?
|
|
|
|
`google-chrome --incongnito #{SPEC_RUNNER}`
|
|
|
|
else
|
|
|
|
`open -a 'Google Chrome' #{SPEC_RUNNER}`
|
|
|
|
end
|
2011-06-08 01:46:50 +04:00
|
|
|
end
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "test in safari"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :run_safari => :prepare do
|
2013-02-21 19:55:54 +04:00
|
|
|
if linux?
|
|
|
|
puts "Cannot run Safari on this platform: #{RUBY_PLATFORM}"
|
|
|
|
else
|
|
|
|
`open -a Safari #{SPEC_RUNNER}`
|
|
|
|
end
|
2011-06-08 01:46:50 +04:00
|
|
|
end
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "test in firefox"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :run_firefox => :prepare do
|
2013-02-21 19:55:54 +04:00
|
|
|
if linux?
|
|
|
|
`firefox #{SPEC_RUNNER}`
|
|
|
|
else
|
|
|
|
`open -a Firefox #{SPEC_RUNNER}`
|
|
|
|
end
|
2011-06-08 01:46:50 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
task :run_default => :prepare do
|
2013-02-21 19:55:54 +04:00
|
|
|
if linux?
|
|
|
|
`google-chrome --incongnito #{SPEC_RUNNER}`
|
|
|
|
else
|
|
|
|
`open #{SPEC_RUNNER}`
|
|
|
|
end
|
2011-06-08 01:46:50 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :build do
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "clean up the target directory"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :clean do
|
|
|
|
rm_rf TARGET_DIR
|
|
|
|
mkdir TARGET_DIR
|
|
|
|
end
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "compile braintree.js"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :bundle => ["build:clean"] do
|
|
|
|
files = %W[
|
2013-02-21 19:55:54 +04:00
|
|
|
#{BUILD_DIR}/minified_header.js
|
2011-06-08 01:46:50 +04:00
|
|
|
#{BUILD_DIR}/bundle_header.js
|
2013-02-21 19:55:54 +04:00
|
|
|
|
|
|
|
#{LIB_DIR}/asn1.js
|
|
|
|
#{JSBN_DIR}/base64.js
|
|
|
|
#{JSBN_DIR}/jsbn.js
|
|
|
|
#{JSBN_DIR}/rsa.js
|
2011-06-08 01:46:50 +04:00
|
|
|
|
|
|
|
#{SJCL_DIR}/sjcl.js
|
|
|
|
#{SJCL_DIR}/aes.js
|
|
|
|
#{SJCL_DIR}/bitArray.js
|
|
|
|
#{SJCL_DIR}/codecHex.js
|
|
|
|
#{SJCL_DIR}/codecString.js
|
|
|
|
#{SJCL_DIR}/codecBase64.js
|
|
|
|
#{SJCL_DIR}/cbc.js
|
2013-02-21 19:55:54 +04:00
|
|
|
#{SJCL_DIR}/hmac.js
|
2011-06-08 01:46:50 +04:00
|
|
|
#{SJCL_DIR}/sha256.js
|
|
|
|
#{SJCL_DIR}/random.js
|
|
|
|
|
|
|
|
#{LIB_DIR}/braintree.js
|
2013-02-21 19:55:54 +04:00
|
|
|
|
2011-06-08 01:46:50 +04:00
|
|
|
#{BUILD_DIR}/bundle_footer.js
|
|
|
|
]
|
|
|
|
`cat #{files.join(' ')} >> #{TARGET_DIR}/braintree-#{BRAINTREE_VERSION}.js`
|
|
|
|
end
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "minify braintree.js"
|
2011-06-08 01:46:50 +04:00
|
|
|
task :minify => ["build:bundle"] do
|
|
|
|
`cat #{BUILD_DIR}/minified_header.js > #{TARGET_DIR}/braintree-#{BRAINTREE_VERSION}.min.js`
|
|
|
|
`ruby #{BUILD_DIR}/jsmin.rb < #{TARGET_DIR}/braintree-#{BRAINTREE_VERSION}.js >> #{TARGET_DIR}/braintree-#{BRAINTREE_VERSION}.min.js`
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-21 19:55:54 +04:00
|
|
|
desc "build braintree.js"
|
2013-04-25 23:08:54 +04:00
|
|
|
task :build => ["build:clean", "build:bundle", "build:minify"]
|