Class: Epuber::Command::Build

Inherits:
Epuber::Command show all
Defined in:
lib/epuber/command/build.rb

Direct Known Subclasses

Compile

Instance Attribute Summary

Attributes inherited from Epuber::Command

#debug_steps_times

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Epuber::Command

run

Constructor Details

#initialize(argv) ⇒ Build

Returns a new instance of Build.

Parameters:

  • argv (CLAide::ARGV)


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/epuber/command/build.rb', line 31

def initialize(argv)
  @targets_names = argv.arguments!
  @should_check = argv.flag?('check', false)
  @should_write = argv.flag?('write', false)
  @release_version = argv.flag?('release', false)
  @use_cache = argv.flag?('cache', true)

  self.debug_steps_times = argv.flag?('debug-steps-times', false)

  super(argv)
end

Class Method Details

.optionsObject



19
20
21
22
23
24
25
26
27
# File 'lib/epuber/command/build.rb', line 19

def self.options
  [
    ['--check',    'Performs additional validation on sources + checks result epub with epubcheck.'],
    ['--write',    'Performs additional transformations which writes to source files.'],
    ['--release',  'Create release version of the book, no caching, everything creates from scratch.'],
    ['--no-cache', 'Turns off incremental build, can resolve some bugs but build takes much longer.'],
    ['--debug-steps-times', 'Shows times of each step'],
  ].concat(super)
end

Instance Method Details

#runObject



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
# File 'lib/epuber/command/build.rb', line 51

def run
  super

  puts "compiling book `#{Config.instance.pretty_path_from_project(book.file_path)}`"

  if @release_version
    # Remove all previous versions of compiled files
    targets.each do |target|
      build_path = Epuber::Config.instance.release_build_path(target)

      if ::File.directory?(build_path)
        FileUtils.remove_dir(build_path, true)
      end
    end

    # Build all targets to always clean directory
    targets.each do |target|
      compiler = Epuber::Compiler.new(book, target)
      build_path = Epuber::Config.instance.release_build_path(target)
      compiler.compile(build_path, check: true, write: @should_write,
                                 release: true, verbose: verbose?,
                               use_cache: false)

      archive_name = compiler.epub_name

      if ::File.exists?(archive_name)
        FileUtils.remove_file(archive_name)
      end

      archive_path = compiler.archive(archive_name)

      system(%(epubcheck "#{archive_path}"))

      convert_epub_to_mobi(archive_path, ::File.basename(archive_path, '.epub') + '.mobi') if target.create_mobi
    end
  else
    targets.each do |target|
      compiler = Epuber::Compiler.new(book, target)
      build_path = Epuber::Config.instance.build_path(target)
      compiler.compile(build_path, check: @should_check, write: @should_write, verbose: verbose?, use_cache: @use_cache)
      archive_path = compiler.archive(configuration_suffix: 'debug')

      system(%(epubcheck "#{archive_path}")) if @should_check

      convert_epub_to_mobi(archive_path, ::File.basename(archive_path, '.epub') + '.mobi') if target.create_mobi
    end
  end

  write_lockfile
end

#validate!Object



43
44
45
46
47
48
49
# File 'lib/epuber/command/build.rb', line 43

def validate!
  super
  verify_one_bookspec_exists!
  verify_all_targets_exists!

  pre_build_checks
end