-
Notifications
You must be signed in to change notification settings - Fork 110
/
Rakefile
64 lines (54 loc) · 1.85 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'net/http'
require 'capybara'
require 'capybara-webkit'
require 'yaml'
RSpec::Core::RakeTask.new(:spec)
desc 'Run specs'
task default: [:spec]
desc 'Update assets'
task update_assets: [:update_braintree, :update_dropin]
desc 'Update braintree client'
task :update_braintree do
puts 'Downloading braintree.js'
origin = 'https://js.braintreegateway.com/v2/braintree.js'
target = 'spec/dummy/public/braintree.js'
sh "curl #{origin} -o #{target}"
end
desc 'Update braintree drop-in assets'
task :update_dropin do
puts 'Determining drop-in version from client code'
uri = URI('https://js.braintreegateway.com/v2/braintree.js')
js_client = Net::HTTP.get(uri)
session = Capybara::Session.new(:webkit, ->{})
session.execute_script(js_client)
client_version = session.evaluate_script('braintree.VERSION')
dropin_version = session.evaluate_script('braintree.dropin.VERSION')
data = YAML::load_file('asset_versions.yml')
if dropin_version == data['dropin_version']
puts 'Drop-in assets up to date'
next
end
rm_rf('lib/fake_braintree/braintree_assets/dropin')
origin_root = "https://assets.braintreegateway.com/dropin/#{dropin_version}/"
target_root = "lib/fake_braintree/braintree_assets/dropin/#{dropin_version}/"
[
'braintree-dropin-internal.min.js',
'braintree-dropin.css',
'inline-frame.html',
'modal-frame.html',
'vendor/jquery-2.1.0.js',
'vendor/modernizr.js',
'vendor/normalize.css',
'images/2x-sf9a66b4f5a.png'
].each do |path|
puts "Downloading #{path}"
sh "curl #{origin_root + path} -o #{target_root + path} --create-dirs"
end
puts 'Updating asset_versions.yml'
data['client_version'] = client_version
data['dropin_version'] = dropin_version
File.write('asset_versions.yml', data.to_yaml)
end