forked from jughead/cloudinary_gem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
55 lines (48 loc) · 2.04 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
require 'bundler'
require 'fileutils'
require 'tmpdir'
require 'rest_client'
require 'json'
require 'rubygems/package'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
Bundler::GemHelper.install_tasks
namespace :cloudinary do
desc "Fetch the latest JavaScript library files and create the JavaScript index files"
task :fetch_assets do
index_files = %w[jquery.ui.widget.js jquery.iframe-transport.js jquery.fileupload.js jquery.cloudinary.js]
processing_files = %w[canvas-to-blob.min.js load-image.all.min.js jquery.fileupload-process.js jquery.fileupload-image.js jquery.fileupload-validate.js]
files = index_files + processing_files
release = JSON(RestClient.get("https://api.github.com/repos/cloudinary/cloudinary_js/releases/latest"))
FileUtils.rm_rf 'vendor/assets'
html_folder = 'vendor/assets/html'
FileUtils.mkdir_p html_folder
js_folder = 'vendor/assets/javascripts/cloudinary'
FileUtils.mkdir_p js_folder
puts "Fetching cloudinary_js version #{release["tag_name"]}\n\n"
sio = StringIO.new(RestClient.get(release["tarball_url"]).body)
file =Zlib::GzipReader.new(sio)
tar = Gem::Package::TarReader.new(file)
tar.each_entry do |entry|
name = File.basename(entry.full_name)
if files.include? name
js_full_name = File.join(js_folder, name)
puts "Adding #{js_full_name}"
File.write js_full_name, entry.read
elsif name == 'cloudinary_cors.html'
html_full_name = File.join(html_folder, name)
puts "Adding #{html_full_name}"
File.write html_full_name, entry.read
end
end
puts "Creating 'index.js' and 'processing.js' files"
File.open("vendor/assets/javascripts/cloudinary/index.js", "w") do |f|
index_files.each { |name| f.puts "//= require ./#{name}" }
end
File.open("vendor/assets/javascripts/cloudinary/processing.js", "w") do |f|
processing_files.each { |name| f.puts "//= require ./#{name}" }
end
end
end
task :build => "cloudinary:fetch_assets"