-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
44 lines (36 loc) · 1.33 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
require 'bundler'
Bundler::GemHelper.install_tasks
# Check if versions are correct between VERSION constants and .js files
#
task :release => [:guard_version]
task :guard_version do
def check_version(file, pattern, constant)
body = File.read("vendor/assets/javascripts/#{file}")
match = body.match(pattern) or abort "Version check failed: no pattern matched in #{file}"
file_version = body.match(pattern)[1]
constant_version = Durl::Rails.const_get(constant)
unless constant_version == file_version
abort "Durl::Rails::#{constant} was #{constant_version} but it should be #{file_version}"
end
end
check_version('durl.js', /Version: ([\S]+)/, 'DURL_VERSION')
end
task :update_durl do
puts "Downloading durl.js"
puts `curl -o vendor/assets/javascripts/durl.js https://raw.githubusercontent.com/tkasten/durl/master/src/durl.js`
puts "Updating version.rb"
version = false
File.foreach('vendor/assets/javascripts/durl.js') do |line|
version = line.match(/Version: ([\S]+)/)
version = version && version[1]
break if version
end
version_path = 'lib/durl/rails/version.rb'
lines = IO.readlines(version_path).map do |line|
line.gsub(/DURL_VERSION = "([\d\.]+)"/, "DURL_VERSION = \"#{version}\"")
end
File.open(version_path, 'w') do |file|
file.puts lines
end
puts "\e[32mDone!\e[0m"
end