Class: VivlioStarter::CLI::SamovarCommands::BuildCommand

Inherits:
VsCommand
  • 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::PARALLEL_MARK, BuildCommands::OutputHelpers::STEP5B_LABEL, BuildCommands::OutputHelpers::STEP5_AGG_LABEL, BuildCommands::OutputHelpers::STEP5_LABEL, BuildCommands::OutputHelpers::SUM_LABEL, BuildCommands::OutputHelpers::WALL_LABEL

Constants included from OptionTokenNormalizer

OptionTokenNormalizer::BARE_VALUE_DEFAULTS

Instance Method Summary collapse

Methods included from BuildCommands::OutputHelpers

#aggregate_step_timings, #calculate_extra_spaces, #print_build_timings, #print_outline_debug_info

Methods included from OptionTokenNormalizer

#initialize, prepended

Instance Method Details

#callObject



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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/vivlio_starter/cli/samovar/build_command.rb', line 64

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

  # 設定ファイルを経由しない直接ビルド(vs build myawesome.md)。
  # プロジェクト前提の Guard は通さず、PDF 生成に必須の Node だけを確認する。
  if direct_mode?
    Guards::Guard.run!(Guards::NodeCheck.new)
    return run_direct_build
  end

  warn_theme_option_ignored

  # 前提条件の検証(precondition-guard-spec.md)
  # 違反があれば 🔴 メッセージを表示して本処理に入らず終了する
  Guards::Guard.run!(
    Guards::ProjectRootCheck.new,
    Guards::CatalogFileCheck.new,
    Guards::CatalogEntriesCheck.new,
    Guards::ContentsDirCheck.new,
    Guards::NodeCheck.new,
    Guards::ImageFilenameCheck.new,
    Guards::ChapterTargetCheck.new(targets)
  )

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

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

      # 解決できない章指定は ChapterTargetCheck が本処理の前に止めるので、
      # ここへ来るのは空白だけの引数(vs build "")のような、
      # 検査対象にすらならなかった指定に限られる。最後の網として残す。
      if target_entries.empty?
        common.log_error("章として読める指定がありません: #{targets.join(', ').inspect}")
        return 1
      end

      run_single_mode_build(target_entries)
    else
      run_full_mode_build
    end
  end

  0
rescue Guards::GuardError => e
  common.log_error(e.message)
  1
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

#projectless?Boolean

プロジェクト文脈(config/book.yml)なしで実行できるか。 RootCommand#ensure_project_context! がこの応答を見て ensure_configured! を省く。 直接ビルドは book.yml の値に依存しないことが機能の定義そのもの(spec §2.2)。

Returns:

  • (Boolean)


136
# File 'lib/vivlio_starter/cli/samovar/build_command.rb', line 136

def projectless? = direct_mode?