-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathRakefile
More file actions
138 lines (111 loc) · 4.5 KB
/
Rakefile
File metadata and controls
138 lines (111 loc) · 4.5 KB
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
136
137
138
namespace :book do
# Variables referenced for build
version_string = `git describe --tags --abbrev=0`.chomp
if version_string.empty?
version_string = '0'
else
versions = version_string.split('.')
version_string = versions[0] + '.' + versions[1] + '.' + versions[2].to_i.next.to_s
end
date_string = Time.now.strftime('%Y-%m-%d')
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
header_hash = `git rev-parse --short HEAD`.strip
# Check contributors list
# This checks commit hash stored in the header of list against current HEAD
def check_contrib
if File.exist?('book/contributors.txt')
current_head_hash = `git rev-parse --short HEAD`.strip
header = `head -n 1 book/contributors.txt`.strip
# Match regex, then coerce resulting array to string by join
header_hash = header.scan(/[a-f0-9]{7,}/).join
if header_hash == current_head_hash
puts "Hash on header of contributors list (#{header_hash}) matches the current HEAD (#{current_head_hash})"
else
puts "Hash on header of contributors list (#{header_hash}) does not match the current HEAD (#{current_head_hash}), refreshing"
sh "rm book/contributors.txt"
# Reenable and invoke task again
Rake::Task['book/contributors.txt'].reenable
Rake::Task['book/contributors.txt'].invoke
end
end
end
desc 'alapvető könyvformátumok előállítása'
task :build => [:build_html, :build_epub, :build_fb2, :build_mobi, :build_pdf] do
begin
# Run check
Rake::Task['book:check'].invoke
# Rescue to ignore checking errors
rescue => e
puts e.message
puts 'Hiba a könyvek ellenőrzése közben (mellőzve)'
end
end
desc 'alapvető könyvformátumok előállítása (folyamatos integrációhoz)'
task :ci => [:build_html, :build_epub, :build_fb2, :build_mobi, :build_pdf] do
# Run check, but don't ignore any errors
Rake::Task['book:check'].invoke
end
desc 'közreműködési lista előállítása'
file 'book/contributors.txt' do
puts 'Közreműködési lista előállítása'
sh "echo 'Contributors as of #{header_hash}:\n' > book/contributors.txt"
sh "git shortlog -s HEAD | grep -v -E '(Straub|Chacon|dependabot)' | cut -f 2- | sort | column -c 120 >> book/contributors.txt"
end
desc 'HTML formátum készítése'
task :build_html => 'book/contributors.txt' do
check_contrib()
puts 'Átalakítás HTML formátumra...'
sh "bundle exec asciidoctor #{params} -a data-uri progit.asc"
puts ' -- HTML kimenet: progit.html'
end
desc 'Epub formátum készítése'
task :build_epub => 'book/contributors.txt' do
check_contrib()
puts 'Átalakítás EPub formátumra...'
sh "bundle exec asciidoctor-epub3 #{params} progit.asc"
puts ' -- Epub kimenet: progit.epub'
end
desc 'FB2 formátum készítése'
task :build_fb2 => 'book/contributors.txt' do
check_contrib()
puts 'Átalakítás FB2 formátumra...'
sh "bundle exec asciidoctor-fb2 #{params} progit.asc"
puts ' -- FB2 kimenet: progit.fb2.zip'
end
desc 'Mobi formátum készítése'
task :build_mobi => 'book/contributors.txt' do
check_contrib()
puts "Átalakítás Mobi (kf8) formátumra..."
sh "bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc"
puts " -- Mobi kimenet: progit.mobi"
end
desc 'PDF formátum készítése'
task :build_pdf => 'book/contributors.txt' do
check_contrib()
puts 'Átalakítás PDF formátumra... (eltarthat egy ideig)'
sh "bundle exec asciidoctor-pdf #{params} progit.asc 2>/dev/null"
puts ' -- PDF kimenet: progit.pdf'
end
desc 'Előállított könyvek ellenőrzése'
task :check => [:build_html, :build_epub] do
puts 'Előállított könyvek ellenőrzése'
sh "htmlproofer progit.html"
sh "epubcheck progit.epub"
end
desc 'Minden előállított fájl eltávolítása'
task :clean do
begin
puts 'Elkészített fájlok eltávolítása'
FileList['book/contributors.txt', 'progit.html', 'progit-kf8.epub', 'progit.epub', 'progit.fb2.zip', 'progit.mobi', 'progit.pdf'].each do |file|
rm file
# Rescue if file not found
rescue Errno::ENOENT => e
begin
puts e.message
puts 'Hiba a fájlok eltávolításakor (mellőzve)'
end
end
end
end
end
task :default => "book:build"