Class: VivlioStarter::CLI::SamovarCommands::PreflightCommand
- Inherits:
-
VsCommand
- Object
- Samovar::Command
- VsCommand
- VivlioStarter::CLI::SamovarCommands::PreflightCommand
- Defined in:
- lib/vivlio_starter/cli/samovar/preflight_command.rb
Overview
preflight コマンドの Samovar 実装
Constant Summary collapse
- CHAPTER_LABEL_WIDTH =
章別サマリー表のラベル幅(全角 1 文字=2 幅で数える)。 長い章タイトルは切り詰めて 🔴🟡✅ の縦位置を揃える(揃わないと表として読めない)
30- TITLE_SCAN_LINES =
章タイトル(H1)を探す行数の上限。原稿冒頭にあるため深追いしない
60- NO_ISSUES =
指摘ゼロの章に使う件数オブジェクト
PreProcessCommands::IssueRegistry::Counts.new(errors: 0, warns: 0)
Constants included from OptionTokenNormalizer
OptionTokenNormalizer::BARE_VALUE_DEFAULTS
Instance Method Summary collapse
Methods included from OptionTokenNormalizer
Instance Method Details
#call ⇒ Object
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 132 133 134 135 136 137 138 139 |
# File 'lib/vivlio_starter/cli/samovar/preflight_command.rb', line 64 def call if [:help] print_usage return 0 end # 章別サマリーの集計をリセットする。Guard の 🟡 警告も最終判定に含めるため、 # Guard.run! より前に置く(preflight-chapter-summary-spec.md §2.2) PreProcessCommands::IssueRegistry.reset! # 前提条件の網羅的診断(precondition-guard-spec.md Phase 4) # preflight は診断コマンドのため build より広く全 Check を実行する。 # Guard.run! は全違反をログしてから停止判定するため、複数の問題を一度に報告できる Guards::Guard.run!( Guards::ProjectRootCheck.new, Guards::CatalogFileCheck.new, Guards::CatalogEntriesCheck.new, Guards::ContentsDirCheck.new, Guards::NodeCheck.new, Guards::OrphanFileCheck.new, Guards::ImageFilenameCheck.new, Guards::CodeFenceCheck.new, Guards::ContainerFenceCheck.new, Guards::ContainerClassCheck.new, Guards::ChapterTargetCheck.new(targets) ) # ensure 節の execute_clean は本処理開始後のみ実行する # (Guard 違反=プロジェクト外の可能性があるディレクトリでクリーンを走らせない) @preflight_started = true PreProcessCommands::LinkImageValidator.reset! # 検証オプションをスレッドローカルに設定(LinkImageValidator が参照) entries = resolve_entries if entries.empty? && targets.any? Common.log_error('指定した章が catalog.yml に存在しません。preflight を中断します。') return 1 end pipeline = BuildCommands::UnifiedBuildPipeline.new(self, entries: entries, mode: :preflight) pipeline.run # 索引処理が積んだ案内(未走査章の vs index:auto 誘導・辞書不在)を吐き出す。 # build 側は従来から flush しており、preflight だけが握り潰していた # (=原稿の問題を先に知るための機能なのに知らせていなかった) IndexCommands. # --verify-links 有効時のみ外部 URL チェックを実行 PreProcessCommands::LinkImageValidator.check_external_urls! PreProcessCommands::LinkImageValidator.print_summary print_chapter_summary(entries) print_preflight_summary # 終了コードは 🔴 の有無だけで決める。画面に出た絵文字と CI の成否が一致し、 # 「❗ 警告 N 件(ビルドは可能です)」と言いながら 1 を返す食い違いが起きない。 # 従来は LinkImageValidator.any_issues?(severity を見ない)で判定していたため、 # 裸 URL の警告だけでも 1 を返していた。 PreProcessCommands::IssueRegistry.counts.errors.positive? ? 1 : 0 rescue Guards::GuardError => e Common.log_error(e.) 1 rescue SystemExit => e raise e rescue StandardError => e Common.log_error("Error: #{e.}") 1 ensure # 前処理で生成した中間 .md ファイルを後始末する(本処理開始後のみ。 # --help や Guard 違反時はプロジェクト外で実行された可能性があるため触らない) CleanCommands.execute_clean({}) if @preflight_started Thread.current[:vs_verify_options] = nil end |