-
Notifications
You must be signed in to change notification settings - Fork 14
/
Rakefile
135 lines (110 loc) · 4.19 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
133
134
135
require 'open-uri'
namespace :book do
def exec_or_raise(command)
puts `#{command}`
if (! $?.success?)
raise "[ERROR] '#{command}' failed"
end
end
def generate_contributors_list(column_size)
# Generating preformatted contributors list...
`git shortlog -s | grep -v -E "(Straub|Chacon|dependabot)" | cut -f 2- | column -c #{column_size} > book/contributors.txt`
end
def download_locale(locale_file)
locale_file_url = "https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/data/locale/#{locale_file}"
if not File.exist?(locale_file)
puts "Downloading locale attributes file..."
l10n_text = URI.open(locale_file_url).read
File.open(locale_file, 'w') { |file| file.puts l10n_text }
puts " -- Saved at #{locale_file}"
else
puts "Use existing file with locale attributes #{locale_file}"
end
end
# Variables referenced for build
lang = 'be'
locale_file = "attributes-#{lang}.adoc"
date_string = Time.now.strftime('%d.%m.%Y')
version_string = `git describe --tags`.chomp
if version_string.empty?
version_string = '0'
end
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}' --attribute lang=#{lang} "
ignore_urls = "'https://developer.github.com','https://developer.github.com/webhooks/','https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent','https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit'"
# Tasks list
desc 'build basic book formats'
task :build => [:build_html, :build_epub, :build_mobi, :build_pdf] do
begin
puts 'Validating generated files...'
Rake::Task['book:check'].invoke
end
end
desc 'prepare necessary data to start build'
task :prebuild, [:column_size] do |t, args|
args.with_defaults(:column_size => 96)
download_locale(locale_file)
generate_contributors_list(args.column_size)
end
desc 'build HTML format'
task :build_html do
Rake::Task['book:prebuild'].invoke(96)
puts 'Converting to HTML...'
`bundle exec asciidoctor #{params} -a data-uri progit.asc`
puts ' -- HTML output at progit.html'
end
desc 'build EPUB format'
task :build_epub do
Rake::Task['book:prebuild'].invoke(48)
puts 'Converting to EPUB...'
`bundle exec asciidoctor-epub3 #{params} progit.asc`
puts ' -- EPUB output at progit.epub'
end
desc 'build Mobi format'
task :build_mobi do
Rake::Task['book:prebuild'].invoke(96)
# Commented out the .mobi file creation because the KindleGen dependency is not available.
#
# FIXME: If asciidoctor-epub3 supports Mobi again, uncomment these lines below
# puts 'Converting to Mobi (kf8)...'
# `bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc`
# puts ' -- Mobi output at progit.mobi'
puts "Converting to Mobi is not longer supported."
puts "For more information see issue #1496 at https://github.com/progit/progit2/issues/1496."
end
desc 'build PDF format'
task :build_pdf do
Rake::Task['book:prebuild'].invoke(88)
puts 'Converting to PDF... (this one takes a while)'
`bundle exec asciidoctor-pdf #{params} progit.asc 2>/dev/null`
puts ' -- PDF output at progit.pdf'
end
desc 'check HTML book'
task :check_html do
if not File.exist?('progit.html')
Rake::Task['book:build_html'].invoke
end
puts ' -- Validate HTML file progit.html'
exec_or_raise("bundle exec htmlproofer --url-ignore #{ignore_urls} --check-html progit.html")
end
desc 'check EPUB book'
task :check_epub do
if not File.exist?('progit.epub')
Rake::Task['book:build_epub'].invoke
end
puts ' -- Validate EPUB output file progit.epub'
exec_or_raise('bundle exec epubcheck progit.epub')
end
desc 'check generated books'
task :check => [:check_html, :check_epub]
desc 'clean all generated files'
task :clean do
begin
puts 'Removing downloaded and generated files'
FileList[locale_file, 'book/contributors.txt', 'progit.html', 'progit.epub', 'progit.pdf', 'progit.mobi'].each do |file|
rm file
rescue Errno::ENOENT
end
end
end
end
task :default => "book:build"