-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
132 lines (112 loc) · 3.6 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
# frozen_string_literal: true
# codeless_code filters and prints fables from http://thecodelesscode.com
# Copyright (C) 2018 Jon Sangster
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https://www.gnu.org/licenses/>.
$LOAD_PATH.unshift(File.join(__dir__, 'lib'))
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
warn e.message
warn 'Run `bundle install` to install missing gems'
exit e.status_code
end
require 'jeweler'
require 'pathname'
require 'pry-byebug'
require 'rake'
require 'rake/testtask'
require 'reek/rake/task'
require 'yard'
require 'codeless_code'
Jeweler::Tasks.new do |gem|
gem.name = 'codeless_code'
gem.homepage = 'https://github.com/sangster/codeless_code'
gem.license = 'GPL-3.0'
gem.summary = 'Search and print The Codeless Code fables'
gem.description = <<-DESC.gsub(/\s+/m, ' ').strip
http://thecodelesscode.com contains many humorous and interesting fables
and koans. The authors have open-sourced these fables, and many
tanslations, available at https://github.com/aldesantis/the-codeless-code.
This tool provides a CLI to filter through these fables and view them.
DESC
gem.email = 'jon@ertt.ca'
gem.authors = ['Jon Sangster']
gem.files.include('data/**/*.txt')
# dependencies defined in Gemfile
end
Jeweler::RubygemsDotOrgTasks.new
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
Rake::Task[:build].prerequisites << :test
desc 'Code coverage detail'
task :simplecov do
ENV['COVERAGE'] = 'true'
Rake::Task['test'].execute
end
Reek::Rake::Task.new do |t|
t.fail_on_error = true
t.verbose = false
t.source_files = 'lib/**/*.rb'
end
YARD::Rake::YardocTask.new
Rake::Task['console'].clear
desc 'Start Pry with all runtime dependencies loaded'
task :console do
include CodelessCode
pry
end
namespace :readme do
readme = Pathname.new(__dir__).join('README.md')
desc 'Update README with the app\'s options'
task :options do
help = CodelessCode::Options.new('codeless_code', []).help.gsub(/ +$/, '')
readme.write(
readme.read.gsub(/(^\s*#+ Current Options).+?(^\s*#)/m,
format("\\1\n\n```\n%s```\n\\2", help))
)
end
end
namespace :lint do
require 'reek/rake/task'
require 'rubocop/rake_task'
Reek::Rake::Task.new do |t|
t.fail_on_error = false
end
RuboCop::RakeTask.new
end
desc 'Render every fable in the given catalog'
task :render_all, [:path] do |_task, args|
fables = CodelessCode::Catalog.new(Pathname.new(args[:path])).fables
fables.each do |fable|
puts fable.file
CodelessCode::Renderers::Fable
.new(fable)
.tap(&:for_list)
.tap { |r| r.for_pager(CodelessCode::Formats::Plain) }
.tap { |r| r.for_pager(CodelessCode::Formats::Term) }
rescue StandardError => err
warn format('Failed on %p', fable)
raise err
end
puts format('Rendered %d fables without error', fables.size)
end
desc 'Run all linters'
task lint: ['lint:rubocop', 'lint:reek']
task default: %i[test lint]