forked from podigee/device_detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
88 lines (74 loc) · 2.52 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true
require 'rake'
require 'rake/testtask'
$LOAD_PATH.unshift 'lib'
require 'device_detector'
Rake::TestTask.new do |t|
t.pattern = 'spec/**/*_spec.rb'
t.libs.push 'spec'
end
task default: :test
desc 'generate detectable names output for README'
task :detectable_names do
require 'date'
bot_names = DeviceDetector::Bot.new('').send(:regexes)
.map { |r| r[:name] }.uniq.sort_by(&:downcase)
bot_names.delete('$1')
client_names = DeviceDetector::Client.new('').send(:regexes)
.map { |r| r[:name] }.uniq.sort_by(&:downcase)
client_names.delete('$1')
device = DeviceDetector::Device.new('')
device_paths = device.send(:filepaths)
device_regexes = device.send(:load_regexes, device_paths)
device_names = device_regexes.flat_map { |dn| dn[1].keys }.uniq.sort_by(&:downcase)
today = Date.today.strftime
puts '## Detectable clients, bots and devices'
puts
puts "Updated on #{today}"
puts
puts '### Bots'
puts
puts bot_names.join(', ')
puts
puts '### Clients'
puts
puts client_names.join(', ')
puts
puts '### Devices'
puts
puts device_names.join(', ')
puts
end
PIWIK_REPO_URL = 'https://github.com/matomo-org/device-detector'
PIWIK_CHECKOUT_LOCATION = '/tmp/matomo_device_detector'
def get_latest_piwik_checkout
if File.exist?(PIWIK_CHECKOUT_LOCATION)
system "cd #{PIWIK_CHECKOUT_LOCATION}; git reset --hard HEAD; git pull origin master"
else
system "git clone --depth 1 #{PIWIK_REPO_URL} #{PIWIK_CHECKOUT_LOCATION}"
end
end
desc 'update regex database from piwik project'
task :update_regexes do
top = File.expand_path(__dir__)
get_latest_piwik_checkout
system "cp -R #{PIWIK_CHECKOUT_LOCATION}/regexes/* #{top}/regexes"
end
desc 'update fixtures from piwik project'
task :update_fixtures do
top = File.expand_path(__dir__)
get_latest_piwik_checkout
fixture_mappings = [
{ target_path: "#{top}/spec/fixtures/detector", source_path: 'Tests/fixtures/*.yml' },
{ target_path: "#{top}/spec/fixtures/client",
source_path: 'Tests/Parser/Client/fixtures/*.yml' },
{ target_path: "#{top}/spec/fixtures/parser", source_path: 'Tests/Parser/fixtures/*.yml' },
{ target_path: "#{top}/spec/fixtures/device",
source_path: 'Tests/Parser/Device/fixtures/*.yml' }
]
fixture_mappings.each do |mapping|
source_path = mapping.fetch(:source_path)
target_path = mapping.fetch(:target_path)
system "cp -R #{PIWIK_CHECKOUT_LOCATION}/#{source_path} #{target_path}"
end
end