Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
|
||||
# Format JSON for better diffs and smaller patches
|
||||
json = MultiJson.dump(data, :pretty => true)
|
||||
|
||||
File.open(file_path, 'wb') do |file|
|
||||
file.write json
|
||||
file.close
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user