-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
132 lines (115 loc) · 3.59 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import 'tasks/compatibility.rake'
import 'tasks/evaluation.rake'
import 'spec/test_suites.rake'
require 'rake'
require 'rubygems'
require 'bundler'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rainbow/ext/string' unless String.respond_to?(:color)
require 'rubocop/rake_task'
RuboCop::RakeTask.new
# first check code style, then execute the tests
task default: %i[rubocop spec]
# map spec task to all test suites
task :spec do
# first, run all tests
Rake::Task['spec:suite:all'].invoke
end
task :doc_toc do
File.open('README.md', 'r') do |f|
f.each_line do |line|
forbidden_words = ['Table of contents', 'define', 'pragma']
next if !line.start_with?('#') || forbidden_words.any? { |w| line =~ /#{w}/ }
title = line.delete('#').strip
href = title.tr(' ', '-').downcase
puts ' ' * (line.count('#') - 1) + "* [#{title}](\##{href})"
end
end
end
desc 'Record all adapter tests'
task :record do
# http://www.relishapp.com/vcr/vcr/v/2-9-3/docs/record-modes
ENV['VCR_RECORD_MODE'] = 'once'
# recording only valid for adapter tests
Rake::Task['spec:suite:adapters'].invoke
end
namespace :record do
FileList['spec/adapter/v1/**'].each do |file|
next unless File.directory?(file)
adapter = File.basename(file)
desc "Record #{adapter} adapter tests"
RSpec::Core::RakeTask.new(adapter) do |t|
# new_episodes
ENV['VCR_RECORD_MODE'] = 'once'
t.pattern = "spec/adapter/v1/#{adapter}/*_spec.rb"
t.verbose = true
end
end
end
task :environment do
ENV['RACK_ENV'] ||= 'development'
require 'configatron'
require 'nucleus/scripts/setup_config'
nucleus_config.logging.level = Logger::Severity::ERROR
require 'nucleus_api/scripts/load_api'
require 'nucleus_api/scripts/initialize_api'
end
task routes: :environment do
Nucleus::API::RootAPI.routes.each do |route|
next if route.nil? || route.route_method.nil?
method = route.route_method.ljust(10)
path = route.route_path
version = route.instance_variable_get(:@options)[:version]
path = path.gsub(/:version/, version) unless version.nil?
puts " #{method} #{path} - [#{version}]"
end
end
task schema_v1: :environment do
require 'json'
response = Nucleus::API::RootAPI.call(
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/schema',
'rack.input' => StringIO.new
)[2].body[0]
json = JSON.parse(response)
puts JSON.pretty_generate(json)
end
begin
require 'yard'
DOC_FILES = %w[lib/**/*.rb].freeze
YARD::Rake::YardocTask.new(:doc) do |t|
t.files = DOC_FILES
end
namespace :doc do
YARD::Rake::YardocTask.new(:pages) do |t|
t.files = DOC_FILES
t.options = ['-o', '../nucleus.doc/docs', '--title', "Nucleus #{Nucleus::VERSION} Documentation"]
end
desc 'Check out gh-pages.'
task :checkout do
dir = File.join(__dir__, '..', 'nucleus.doc')
unless Dir.exist?(dir)
Dir.mkdir(dir)
Dir.chdir(dir) do
system('git init')
system('git remote add origin [email protected]:stefan-kolb/nucleus.git')
system('git pull')
system('git checkout gh-pages')
end
end
end
desc 'Generate and publish YARD docs to GitHub pages.'
task publish: %w[doc:pages:checkout doc:pages] do
Dir.chdir(File.join(__dir__, '..', 'nucleus.doc')) do
system('git checkout gh-pages')
system('git add .')
system('git add -u')
system("git commit -m 'Generating docs for version #{Nucleus::VERSION}.'")
system('git push origin gh-pages')
end
end
end
rescue LoadError
puts 'You need to install YARD.'
end