Class: Vivlio::Starter::CLI::SamovarCommands::BuildCommand

Inherits:
Samovar::Command
  • Object
show all
Includes:
BuildCommands::OutputHelpers
Defined in:
lib/vivlio/starter/cli/samovar/build_command.rb

Overview

build コマンドの Samovar 実装

Constant Summary

Constants included from BuildCommands::OutputHelpers

BuildCommands::OutputHelpers::STEP5B_LABEL, BuildCommands::OutputHelpers::STEP5_AGG_LABEL, BuildCommands::OutputHelpers::STEP5_LABEL

Instance Method Summary collapse

Methods included from BuildCommands::OutputHelpers

#aggregate_step_timings, #calculate_extra_spaces, #print_build_timings, #print_outline_debug_info

Constructor Details

#initialize(input = nil) ⇒ BuildCommand

Returns a new instance of BuildCommand.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vivlio/starter/cli/samovar/build_command.rb', line 61

def initialize(input = nil, **)
  processed_input = if input
                      normalized = normalize_log_option_tokens(input)

                      if input.respond_to?(:replace) && !input.equal?(normalized)
                        input.replace(normalized)
                        input
                      else
                        normalized
                      end
                    else
                      input
                    end

  super(processed_input, **)
end

Instance Method Details

#callObject



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
# File 'lib/vivlio/starter/cli/samovar/build_command.rb', line 78

def call
  if options[:help]
    print_usage
    return 0
  end

  # 検証オプションをスレッドローカルに設定(LinkImageValidator が参照)
  setup_verify_options!
  PreProcessCommands::LinkImageValidator.reset!

  # 同一プロジェクトでの多重 build を防ぐため、.cache/vs/.build.lock を
  # File::LOCK_EX | LOCK_NB で取得する。取得失敗時は即座にエラー終了。
  BuildCommands::BuildLock.with_lock do
    if targets.any?
      target_entries = resolve_target_entries

      if target_entries.empty?
        common.log_error('指定した章が catalog.yml に存在しません。build を中断します。')
        return 1
      end

      run_single_mode_build(target_entries)
    else
      run_full_mode_build
    end
  end

  0
rescue BuildCommands::BuildLock::AlreadyLockedError => e
  common.log_error(e.message)
  1
rescue SystemExit => e
  raise e
rescue StandardError => e
  common.log_error("Error: #{e.message}")
  1
ensure
  Thread.current[:vs_verify_options] = nil
  PostProcessCommands::HeadingProcessor.chapter_tokens_override = nil
end