File: Rakefile

package info (click to toggle)
ruby-device-detector 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 3,104 kB
  • sloc: ruby: 1,224; makefile: 5
file content (79 lines) | stat: -rw-r--r-- 2,414 bytes parent folder | download
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
require 'rake'
require 'rake/testtask'

$:.unshift 'lib'
require 'device_detector'

Rake::TestTask.new do |t|
  t.pattern = 'spec/**/*_spec.rb'
  t.libs.push 'spec'
end

task default: :test

task :detectable_names do
  bot_names = DeviceDetector::Bot.new.send(:regexes).map { |r| r[:name] }.uniq.sort_by { |n| n.downcase }
  bot_names.delete('$1')
  client_names = DeviceDetector::Client.new.send(:regexes).map { |r| r[:name] }.uniq.sort_by { |n| n.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 { |n| n.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/piwik/device-detector.git'.freeze
PIWIK_CHECKOUT_LOCATION = '/tmp/piwik_device_detector'.freeze

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('..', __FILE__)
  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('..', __FILE__)
  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/Devices/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