Skip to content

Commit

Permalink
Fix jQuery version download task
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Apr 18, 2018
1 parent d42f68d commit c211b82
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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]
file_version = match[1]
constant_version = Jquery::Rails.const_get(constant)

unless constant_version == file_version
Expand All @@ -20,29 +20,19 @@ task :guard_version do
check_version('jquery.js', /jQuery JavaScript Library v([\S]+)/, 'JQUERY_VERSION')
end

desc "Update jQuery versions"
task :update_jquery do
puts "Downloading jquery.js"
puts `curl -o vendor/assets/javascripts/jquery.js http://code.jquery.com/jquery.js`
puts "Downloading jquery.min.js"
puts `curl -o vendor/assets/javascripts/jquery.min.js http://code.jquery.com/jquery.min.js`
puts "Downloading jquery.min.map"
puts `curl -o vendor/assets/javascripts/jquery.min.map http://code.jquery.com/jquery.min.map`

puts "Updating version.rb"
version = false
File.foreach('vendor/assets/javascripts/jquery.js') do |line|
version = line.match(/jQuery JavaScript Library v([\S]+)/)
version = version && version[1]
break if version
end

version_path = 'lib/jquery/rails/version.rb'
lines = IO.readlines(version_path).map do |line|
line.gsub(/JQUERY_VERSION = "([\d\.]+)"/, "JQUERY_VERSION = \"#{version}\"")
end
File.open(version_path, 'w') do |file|
file.puts lines
def download_jquery(filename, version)
suffix = "-#{version}"

puts "Downloading #{filename}.js"
puts `curl -o vendor/assets/javascripts/#{filename}.js https://code.jquery.com/jquery#{suffix}.js`
puts "Downloading #{filename}.min.js"
puts `curl -o vendor/assets/javascripts/#{filename}.min.js https://code.jquery.com/jquery#{suffix}.min.js`
puts "Downloading #{filename}.min.map"
puts `curl -o vendor/assets/javascripts/#{filename}.min.map https://code.jquery.com/jquery#{suffix}.min.map`
end

download_jquery('jquery', Jquery::Rails::JQUERY_VERSION)
puts "\e[32mDone!\e[0m"
end

0 comments on commit c211b82

Please sign in to comment.