Class: Highway::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/highway/main.rb

Overview

This class is a main entry point to Highway.

Instance Method Summary collapse

Constructor Details

#initialize(entrypoint:, path:, preset:, fastlane_runner:, fastlane_lane_context:) ⇒ Main

Initialize an instance.



29
30
31
32
33
34
35
# File 'lib/highway/main.rb', line 29

def initialize(entrypoint:, path:, preset:, fastlane_runner:, fastlane_lane_context:)
  @entrypoint = entrypoint
  @path = path
  @preset = preset
  @fastlane_runner = fastlane_runner
  @fastlane_lane_context = fastlane_lane_context
end

Instance Method Details

#runVoid

Run Highway.



40
41
42
43
44
45
46
47
48
49
50
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/highway/main.rb', line 40

def run()

  # Always run Highway in the root directory of the project. This should
  # standardize the legacy directory behavior described here:
  # https://docs.fastlane.tools/advanced/fastlane/#directory-behavior.

  Dir.chdir(running_dir) do

    # Print the header, similar to Fastlane's "driving the lane".

    interface.success("Driving the Highway preset '#{@preset}' 🏎")

    # Construct a steps registry and load steps from the default library
    # by requiring files in `highway/steps/library` and registering all
    # classes that inherit from `Highway::Steps::Step`.

    registry = Steps::Registry.new_and_load_default_library()

    # Set up the compiler and compile Highway configuration file into the
    # build manifest. See `highway/compiler/parse`, `highway/compiler/analyze`
    # and `highway/compiler/build` for more information.

    compiler = Compiler::Suite.new(
      registry: registry,
      interface: interface,
    )

    manifest = compiler.compile(
      path: File.expand_path(@path, running_dir),
      preset: @preset,
    )

    # At this point the compilation is done. Now, construct the runtime
    # context, set up the runner and run the compiled build manifest.

    context = Runtime::Context.new(
      fastlane_runner: @fastlane_runner,
      fastlane_lane_context: @fastlane_lane_context,
      env: env,
      interface: interface,
    )

    runner = Runtime::Runner.new(
      manifest: manifest,
      context: context,
      interface: interface,
    )

    runner.run()

    # We can safely print the success summary message because fatal errors
    # will be catched by the rescue block below.

    @interface.whitespace()
    @interface.success("Wubba lubba dub dub, Highway preset '#{@preset}' has succeeded!")

  end

rescue StandardError => error

  # Unless the error contains any message we should print it right now but
  # as an error so that we can still control the output.

  interface.error(error) unless error.message.empty?

  # We should take care of the unnecessary printing of Fastlane lane
  # context but only if we're running from lane entry point (otherwise we
  # could affect other actions and fallback lanes user has set up).
  #
  # So, if we're running from lane entry point, we should clear the lane
  # context before raising a fatal error. If we're in verbose mode, we
  # should additionally print it before cleaning.

  if @entrypoint == :lane
    report_fastlane_lane_context() if env.verbose?
    clear_fastlane_lane_context()
  end

  # Now we throw a fatal error that tells Fastlane to abort.

  interface.whitespace()
  interface.fatal!("Highway preset '#{@preset}' has failed with one or more errors. Please examine the above log.")

end