2013-07-17 13:26:20 +00:00
|
|
|
require 'bundler/gem_tasks'
|
|
|
|
|
|
|
|
namespace :cdnjs do
|
|
|
|
desc 'Updates packages.json file from cdnjs.com'
|
|
|
|
task :update do
|
|
|
|
require 'open-uri'
|
|
|
|
require 'multi_json'
|
|
|
|
|
|
|
|
packages_url = 'http://cdnjs.com/packages.json'
|
|
|
|
file_path = File.expand_path('../data/packages.json', __FILE__)
|
|
|
|
json = open(packages_url).read
|
|
|
|
|
|
|
|
# Remove all unnecessary data
|
|
|
|
# Keep repo small and code fast
|
|
|
|
data = MultiJson.load(json)['packages'].map do |pkg|
|
|
|
|
{
|
|
|
|
pkg['name'] => {
|
|
|
|
'filename' => pkg['filename'],
|
|
|
|
'latest_version' => pkg['version'],
|
|
|
|
'versions' => pkg['assets'].map{ |asset| asset['version'] }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end.inject(:merge)
|
|
|
|
|
2013-07-17 13:56:30 +00:00
|
|
|
# Pretty format JSON for better diffs and smaller patches
|
2013-07-17 13:26:20 +00:00
|
|
|
json = MultiJson.dump(data, :pretty => true)
|
|
|
|
|
2013-07-17 13:56:30 +00:00
|
|
|
File.open file_path, 'wb' do |file|
|
2013-07-17 13:26:20 +00:00
|
|
|
file.write json
|
|
|
|
file.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|