Skip to content

Commit ccba093

Browse files
committed
Update compilation scripts
1 parent aab0e1c commit ccba093

File tree

3 files changed

+152
-110
lines changed

3 files changed

+152
-110
lines changed

Gemfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
source 'https://rubygems.org'
22

33
gem 'rake'
4-
gem 'asciidoctor', '1.5.0'
4+
gem 'asciidoctor', '1.5.6.1'
55

66
gem 'json'
77
gem 'awesome_print'
88

9-
gem 'asciidoctor-epub3', '1.0.0.alpha.2'
10-
gem 'asciidoctor-pdf', '1.5.0.alpha.8'
11-
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.1'
9+
gem 'asciidoctor-epub3', :git => 'https://github.com/asciidoctor/asciidoctor-epub3'
10+
gem 'asciidoctor-pdf', '1.5.0.alpha.16'
1211

1312
gem 'coderay'
1413
gem 'pygments.rb'
1514
gem 'thread_safe'
1615
gem 'epubcheck'
1716
gem 'kindlegen'
17+
18+
gem 'octokit'

Gemfile.lock

Lines changed: 0 additions & 92 deletions
This file was deleted.

Rakefile

Lines changed: 147 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,163 @@
1-
namespace :book do
2-
desc 'prepare build'
3-
task :prebuild do
4-
Dir.mkdir 'images' unless Dir.exists? 'images'
5-
Dir.glob("book/*/images/*").each do |image|
6-
FileUtils.copy(image, "images/" + File.basename(image))
7-
end
8-
end
1+
# coding: utf-8
2+
require 'octokit'
93

4+
namespace :book do
105
desc 'build basic book formats'
11-
task :build => :prebuild do
6+
task :build do
7+
8+
puts "Generating contributors list"
9+
`git shortlog -s --all| grep -v -E "(Straub|Chacon)" | cut -f 2- | column -c 120 > book/contributors.txt`
10+
1211
puts "Converting to HTML..."
13-
`bundle exec asciidoctor -r ./config.rb progit.asc`
12+
`bundle exec asciidoctor progit.asc`
1413
puts " -- HTML output at progit.html"
1514

1615
puts "Converting to EPub..."
17-
`bundle exec asciidoctor-epub3 -r ./config.rb progit.asc`
16+
`bundle exec asciidoctor-epub3 progit.asc`
1817
puts " -- Epub output at progit.epub"
1918

19+
sh "epubcheck progit.epub"
20+
2021
puts "Converting to Mobi (kf8)..."
21-
`bundle exec asciidoctor-epub3 -r ./config.rb -a ebook-format=kf8 progit.asc`
22+
`bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc`
2223
puts " -- Mobi output at progit.mobi"
2324

2425
puts "Converting to PDF... (this one takes a while)"
25-
`bundle exec asciidoctor-pdf -r ./config.rb -a pdf-style=KaiGenGothicCN progit.asc 2>/dev/null`
26-
puts " -- PDF output at progit.pdf"
26+
`bundle exec asciidoctor-pdf progit.asc 2>/dev/null`
27+
puts " -- PDF output at progit.pdf"
28+
end
29+
30+
desc 'tag the repo with the latest version'
31+
task :tag do
32+
api_token = ENV['GITHUB_API_TOKEN']
33+
if (api_token && (ENV['TRAVIS_PULL_REQUEST'] == 'false') && (ENV['TRAVIS_BRANCH']=='master') && !ENV['TRAVIS_TAG'])
34+
repo = ENV['TRAVIS_REPO_SLUG']
35+
@octokit = Octokit::Client.new(:access_token => api_token)
36+
begin
37+
last_version=@octokit.latest_release(repo).tag_name
38+
rescue
39+
last_version="2.1.-1"
40+
end
41+
new_patchlevel= last_version.split('.')[-1].to_i + 1
42+
new_version="2.1.#{new_patchlevel}"
43+
obj = @octokit.create_tag(repo, new_version, "Version " + new_version, ENV['TRAVIS_COMMIT'],
44+
'commit',
45+
'Automatic build', '[email protected]',
46+
Time.now.utc.iso8601)
47+
@octokit.create_ref(repo, "tags/#{new_version}", obj.sha)
48+
p "Created tag #{new_version}"
49+
else
50+
p 'This only runs on a commit to master'
51+
end
52+
end
53+
54+
desc 'convert book to asciidoctor compatibility'
55+
task:convert do
56+
`cp -aR ../progit2/images .`
57+
`sed -i -e 's!/images/!!' .gitignore`
58+
`git add images`
59+
`git rm -r book/*/images`
60+
61+
chapters = [
62+
["01", "introduction" ],
63+
["02", "git-basics" ],
64+
["03", "git-branching" ],
65+
["04", "git-server" ],
66+
["05", "distributed-git" ],
67+
["06", "github" ],
68+
["07", "git-tools" ],
69+
["08", "customizing-git" ],
70+
["09", "git-and-other-scms" ],
71+
["10", "git-internals" ],
72+
["A", "git-in-other-environments" ],
73+
["B", "embedding-git" ],
74+
["C", "git-commands" ]
75+
]
76+
77+
crossrefs = {}
78+
chapters.each { | num, title |
79+
if num =~ /[ABC]/
80+
chap = "#{num}-#{title}"
81+
else
82+
chap = "ch#{num}-#{title}"
83+
end
84+
Dir[File.join ["book","#{num}-#{title}" , "sections","*.asc"]].map { |filename|
85+
File.read(filename).scan(/\[\[(.*?)\]\]/)
86+
}.flatten.each { |ref|
87+
crossrefs[ref] = "#{chap}"
88+
}
89+
}
90+
91+
headrefs = {}
92+
chapters.each { | num, title |
93+
if num =~ /[ABC]/
94+
chap = "#{num}-#{title}"
95+
else
96+
chap = "ch#{num}-#{title}"
97+
end
98+
Dir[File.join ["book","#{num}-#{title}", "*.asc"]].map { |filename|
99+
File.read(filename).scan(/\[\[(.*?)\]\]/)
100+
}.flatten.each { |ref|
101+
headrefs[ref] = "#{chap}"
102+
}
103+
}
104+
105+
# transform all internal cross refs
106+
chapters.each { | num, title |
107+
if num =~ /[ABC]/
108+
chap = "#{num}-#{title}"
109+
else
110+
chap = "ch#{num}-#{title}"
111+
end
112+
files = Dir[File.join ["book","#{num}-#{title}" , "sections","*.asc"]] +
113+
Dir[File.join ["book","#{num}-#{title}" ,"1-*.asc"]]
114+
p files
115+
files.each { |filename|
116+
content = File.read(filename)
117+
new_contents = content.gsub(/\[\[(.*?)\]\]/, '[[r\1]]').gsub(
118+
"&rarr;", "→").gsub(/<<(.*?)>>/) { |match|
119+
ch = crossrefs[$1]
120+
h = headrefs[$1]
121+
# p " #{match} -> #{ch}, #{h}"
122+
if ch
123+
# if local do not add the file
124+
if ch==chap
125+
"<<r#{$1}>>"
126+
else
127+
"<<#{ch}#r#{$1}>>"
128+
end
129+
elsif h
130+
if h==chap
131+
"<<#{chap}>>"
132+
else
133+
"<<#{h}##{h}>>"
134+
end
135+
end
136+
}
137+
File.open(filename, "w") {|file| file.puts new_contents }
138+
}
139+
}
140+
141+
chapters.each { | num, title |
142+
if num =~ /[ABC]/
143+
chap = "#{num}-#{title}"
144+
else
145+
chap = "ch#{num}-#{title}"
146+
end
147+
Dir[File.join ["book","#{num}-#{title}" ,"1*.asc"]].map { |filename|
148+
content = File.read (filename)
149+
new_contents = content.gsub(/include::(.*?)asc/) {|match|
150+
"include::book/#{num}-#{title}/#{$1}asc"}
151+
`git rm #{filename}`
152+
File.open("#{chap}.asc", "w") {|file|
153+
file.puts "[##{chap}]\n"
154+
file.puts new_contents }
155+
`git add "#{chap}.asc"`
156+
}
157+
}
27158
end
28159
end
29160

161+
162+
30163
task :default => "book:build"

0 commit comments

Comments
 (0)