-
Notifications
You must be signed in to change notification settings - Fork 22
/
Rakefile
60 lines (48 loc) · 1.61 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
require 'bundler'
Bundler::GemHelper.install_tasks
require 'open-uri'
require 'json'
# Helper Functions
def name
@name ||= Dir['*.gemspec'].first.split('.').first
end
def version
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
end
def latest_tag
tags = JSON.parse(open('https://api.github.com/repos/marionettejs/backbone.marionette/tags').read)
tags.sort!{|a,b| b["name"] <=> a["name"]}
tags.first
end
namespace :marionette do
desc "Fetches and displays the latest backbone.marionette tag"
task :latest do
tag = latest_tag
puts "The latest backbone.marionette tag is #{tag["name"]} with commit #{tag["commit"]["sha"]}"
end
desc "Updates the vendored backbone.marionette version to the latest tag"
task :update do
tag = latest_tag
# Pull attributes we need
name = tag["name"]
sha = tag["commit"]["sha"]
# Cleanup the name
name.gsub!(/^v/, '')
name.gsub!(/-/, '.')
if name == version
puts "Gem version #{version} matches the latest backbone.marionette version #{name}"
exit
end
# Update marionette
puts "Updating marionette..."
base_url = "https://raw.githubusercontent.com/marionettejs/backbone.marionette/#{sha}/lib"
files = %w{backbone.marionette.js backbone.marionette.map backbone.marionette.min.js}
Dir.chdir './vendor/assets/javascripts' do
files.each {|file| `curl -O #{base_url}/#{file}`}
end
# Update version file
puts "Updating version.rb..."
`sed -i "" "s/ VERSION = '.*'/ VERSION = '#{name}'/g" lib/marionette-rails/version.rb`
end
end