File: Rakefile

package info (click to toggle)
ruby-maxitest 7.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 444 kB
  • sloc: ruby: 1,339; makefile: 7
file content (68 lines) | stat: -rw-r--r-- 1,667 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
# frozen_string_literal: true
require "bundler/setup"
require "bundler/gem_tasks"
require "net/http"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

begin
  require "bump/tasks"
  Bump.replace_in_default = Dir["gemfiles/**.lock"]
rescue LoadError
  # not available in gemfiles/
end

module VendorUpdate
  class << self
    def all
      Dir["lib/maxitest/vendor/*"].each { |f| update_file f }
    end

    private

    def update_file(file)
      # a file has multiple parts, and each part starts with the url where it was copied from
      do_not_modify = "generated by rake update, do not modify"
      start = "# BEGIN #{do_not_modify}\n"
      finish = "# END #{do_not_modify}\n"
      urls = File.read(file).scan(/#{Regexp.escape start}# (\S+)\n.*?#{Regexp.escape(finish)}/m).flatten(1)

      urls.map! do |url|
        code = Net::HTTP.get(URI(url))
        code = modify_code code, url
        "#{start}# #{url}\n#{code}\n#{finish}"
      end

      File.write(file, urls.reject(&:empty?).join("\n"))
    end

    def modify_code(code, url)
      code = code.dup
      code.gsub!(/require .*?\n/, "") # we inline everything
      code.strip!
      code = "=begin\n#{code}\n=end" if url.include?("LICENSE")
      code
    end
  end
end

desc "Run all tests"
task default: :spec

desc "Update all dependencies"
task :update do
  VendorUpdate.all
end

desc "bundle all gemfiles/ EXTRA="
task :bundle do
  extra = ENV["EXTRA"]
  Bundler.with_original_env do
    Dir["gemfiles/*.gemfile"].reverse.each { |gemfile| sh "BUNDLE_GEMFILE=#{gemfile} bundle #{extra}" }
  end
end

desc "Run rubocop"
task :rubocop do
  sh "rubocop --autocorrect-all"
end