-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
130 lines (108 loc) · 3.42 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
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rdoc/task"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.warning = false
end
begin
require "rubocop/rake_task"
desc "Run rubocop"
RuboCop::RakeTask.new(:rubocop)
rescue LoadError
end
namespace :coverage do
desc "Aggregates coverage reports"
task :report do
return unless ENV.key?("CI")
require "simplecov"
SimpleCov.collate Dir["coverage/**/.resultset.json"]
end
end
CI_TASKS = RUBY_VERSION >= "3.1.0" ? %i[test rubocop] : %i[test]
task "test:ci": CI_TASKS
task default: :test
# Doc
rdoc_opts = ["--line-numbers", "--title", "Rodauth OAuth: OAuth 2.0 and OpenID for rodauth"]
begin
gem "hanna-nouveau"
rdoc_opts.concat(["-f", "hanna"])
rescue Gem::LoadError
end
rdoc_opts.concat(["--main", "README.md"])
RDOC_FILES = %w[README.md CHANGELOG.md lib/**/*.rb] + Dir["doc/*.rdoc"] + Dir["doc/release_notes/*.md"]
RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = "rdoc"
rdoc.options += rdoc_opts
rdoc.rdoc_files.add RDOC_FILES
end
RDoc::Task.new(:website_rdoc) do |rdoc|
rdoc.rdoc_dir = "rdoc"
rdoc.options += rdoc_opts
rdoc.rdoc_files.add RDOC_FILES
end
desc "Check configuration method documentation"
task :check_method_doc do
docs = {}
Dir["doc/*.rdoc"].sort.each do |f|
meths = File.binread(f).split("\n").grep(/\A(\w+[!?]?(\([^\)]+\))?) :: /).map { |line| line.split(/( :: |\()/, 2)[0] }.sort
docs[File.basename(f).sub(/\.rdoc\z/, "")] = meths unless meths.empty?
end
require "rodauth/oauth"
begin
require "jwt"
rescue LoadError
end
docs.each do |f, doc_meths|
require "./lib/rodauth/features/#{f}"
feature = Rodauth::FEATURES[f.to_sym]
meths = (feature.auth_methods + feature.auth_value_methods + feature.auth_private_methods).map(&:to_s).sort
unless (undocumented_meths = meths - doc_meths).empty?
puts "#{f} undocumented methods: #{undocumented_meths.join(', ')}"
end
unless (bad_doc_meths = doc_meths - meths).empty?
puts "#{f} documented methods that don't exist: #{bad_doc_meths.join(', ')}"
end
end
puts "#{docs.values.flatten.length} total documented configuration methods"
end
desc "Builds jekyll data"
task :prepare_jekyll_data do
require "yaml"
FileUtils.mkdir_p("data")
version_tmpl = <<-VERSION
-
name: "%<name>s"
path: "%<path>s"
VERSION
`git tag -l`.lines(chomp: true)
.map { |v| v[1..-1] }
.sort_by(&Gem::Version.method(:new))
.reverse
.map { |v| { name: v, path: "#{v.tr('.', '_')}_md.html" } }
.map { |v| format(version_tmpl, v) }
.join
.then { |v| "-\n#{v}" }
.then { |output| File.write("data/versions.yml", output) }
end
desc "Builds Homepage"
task prepare_website: %i[website_rdoc prepare_jekyll_data] do
require "fileutils"
FileUtils.rm_rf("wiki")
system("git clone https://gitlab.com/os85/rodauth-oauth.wiki.git wiki")
Dir.glob("wiki/*.md") do |path|
data = File.read(path)
name = File.basename(path, ".md")
title = name == "home" ? "Wiki" : name.split("-").map(&:capitalize).join(" ")
layout = name == "home" ? "page" : "wiki"
header = "---\n" \
"layout: #{layout}\n" \
"title: #{title}\n" \
"project: rodauth-oauth\n" \
"---\n\n"
File.write(path, header + data)
end
end