|
1 | 1 | # coding: utf-8
|
2 | 2 | require 'octokit'
|
3 | 3 |
|
| 4 | +def exec_or_raise(command) |
| 5 | + puts `#{command}` |
| 6 | + if (! $?.success?) |
| 7 | + raise "'#{command}' failed" |
| 8 | + end |
| 9 | +end |
| 10 | + |
4 | 11 | namespace :book do
|
5 | 12 | desc 'build basic book formats'
|
6 | 13 | task :build do
|
7 | 14 |
|
8 | 15 | puts "Generating contributors list"
|
9 |
| - `git shortlog -s --all| grep -v -E "(Straub|Chacon)" | cut -f 2- | column -c 120 > book/contributors.txt` |
| 16 | + exec_or_raise("git shortlog -s --all| grep -v -E '(Straub|Chacon)' | cut -f 2- | column -c 120 > book/contributors.txt") |
10 | 17 |
|
11 | 18 | puts "Converting to HTML..."
|
12 |
| - `bundle exec asciidoctor progit.asc` |
| 19 | + exec_or_raise("bundle exec asciidoctor progit.asc") |
13 | 20 | puts " -- HTML output at progit.html"
|
14 | 21 |
|
15 | 22 | puts "Converting to EPub..."
|
16 |
| - `bundle exec asciidoctor-epub3 progit.asc` |
| 23 | + exec_or_raise("bundle exec asciidoctor-epub3 progit.asc") |
17 | 24 | puts " -- Epub output at progit.epub"
|
18 | 25 |
|
19 |
| - sh "epubcheck progit.epub" |
| 26 | + exec_or_raise("epubcheck progit.epub") |
20 | 27 |
|
21 | 28 | puts "Converting to Mobi (kf8)..."
|
22 |
| - `bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc` |
| 29 | + exec_or_raise("bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc") |
23 | 30 | puts " -- Mobi output at progit.mobi"
|
24 | 31 |
|
| 32 | + repo = ENV['TRAVIS_REPO_SLUG'] |
25 | 33 | puts "Converting to PDF... (this one takes a while)"
|
26 |
| - `bundle exec asciidoctor-pdf progit.asc 2>/dev/null` |
| 34 | + exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install") |
| 35 | + exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicJP progit.asc") |
27 | 36 | puts " -- PDF output at progit.pdf"
|
28 | 37 | end
|
29 | 38 |
|
@@ -148,7 +157,7 @@ namespace :book do
|
148 | 157 | content = File.read (filename)
|
149 | 158 | new_contents = content.gsub(/include::(.*?)asc/) {|match|
|
150 | 159 | "include::book/#{num}-#{title}/#{$1}asc"}
|
151 |
| - `git rm #{filename}` |
| 160 | + `git rm -f #{filename}` |
152 | 161 | File.open("#{chap}.asc", "w") {|file|
|
153 | 162 | file.puts "[##{chap}]\n"
|
154 | 163 | file.puts new_contents }
|
|
0 commit comments