Class: Middleman::Cli::Build

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/middleman-core/cli/build.rb

Overview

The CLI Build class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debuggingObject (readonly)

Returns the value of attribute debugging.



11
12
13
# File 'lib/middleman-core/cli/build.rb', line 11

def debugging
  @debugging
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/middleman-core/cli/build.rb', line 81

def exit_on_failure?
  true
end

.shared_instance(verbose = false, instrument = false) ⇒ Middleman::Application

Middleman::Application singleton



88
89
90
91
92
93
# File 'lib/middleman-core/cli/build.rb', line 88

def shared_instance(verbose=false, instrument=false)
  @_shared_instance ||= ::Middleman::Application.server.inst do
    config[:environment] = :build
    logger(verbose ? 0 : 1, instrument)
  end
end

.shared_rackRack::Test::Session

Rack::Test::Session singleton

Returns:

  • (Rack::Test::Session)


105
106
107
# File 'lib/middleman-core/cli/build.rb', line 105

def shared_rack
  @_shared_rack ||= ::Rack::Test::Session.new(shared_server.to_rack_app)
end

.shared_serverMiddleman::Application

Middleman::Application class singleton



98
99
100
# File 'lib/middleman-core/cli/build.rb', line 98

def shared_server
  @_shared_server ||= shared_instance.class
end

.source_rootObject

Set the root path to the Middleman::Application’s root



110
111
112
# File 'lib/middleman-core/cli/build.rb', line 110

def source_root
  shared_instance.root
end

Instance Method Details

#buildvoid

This method returns an undefined value.

Core build Thor command



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
# File 'lib/middleman-core/cli/build.rb', line 42

def build
  if !ENV["MM_ROOT"]
    raise Thor::Error, "Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
  end

  # Use Rack::Test for inspecting a running server for output
  require "rack"
  require "rack/test"

  require 'find'

  @debugging = Middleman::Cli::Base.respond_to?(:debugging) && Middleman::Cli::Base.debugging
  @had_errors = false

  self.class.shared_instance(options["verbose"], options["instrument"])

  self.class.shared_rack

  opts = {}
  opts[:glob]  = options["glob"]  if options.has_key?("glob")
  opts[:clean] = options["clean"]  if options.has_key?("clean")

  action GlobAction.new(self, opts)

  self.class.shared_instance.run_hook :after_build, self

  if @had_errors && !@debugging
    msg = "There were errors during this build"
    unless options["verbose"]
      msg << ", re-run with `middleman build --verbose` to see the full exception."
    end
    self.shell.say msg, :red
  end

  exit(1) if @had_errors
end