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)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/epuber/command/build.rb', line 36

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

.subcommandsObject

To resolve problem with ‘compile` treating as subcommand



30
31
32
# File 'lib/epuber/command/build.rb', line 30

def self.subcommands
  []
end

Instance Method Details

#runObject



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

def run
  super

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

  if @release_version
    # Remove all previous versions of compiled files
    cleanup_build_folders

    # Build all targets to always clean directory
    targets.each do |target|
      Epuber::Config.instance.release_build = true

      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

      FileUtils.remove_file(archive_name) if ::File.exist?(archive_name)

      archive_path = compiler.archive(archive_name)

      Epubcheck.check(archive_path)

      convert_epub_to_mobi(archive_path, "#{::File.basename(archive_path, '.epub')}.mobi") if target.create_mobi

      Epuber::Config.instance.release_build = false
    end

    # Build all targets to always clean directory
  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')

      Epubcheck.check(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



48
49
50
51
52
53
54
# File 'lib/epuber/command/build.rb', line 48

def validate!
  super
  verify_one_bookspec_exists!
  verify_all_targets_exists!

  pre_build_checks
end