class Middleman::Cli::Build

The CLI Build class

Attributes

debugging[R]
had_errors[RW]

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/middleman-core/cli/build.rb, line 87
def exit_on_failure?
  true
end
shared_instance(verbose=false, instrument=false) click to toggle source

Middleman::Application singleton

@return [Middleman::Application]

# File lib/middleman-core/cli/build.rb, line 94
def shared_instance(verbose=false, instrument=false)
  @_shared_instance ||= ::Middleman::Application.server.inst do
    config[:environment] = :build
    ::Middleman::Logger.singleton(verbose ? 0 : 1, instrument)
  end
end

Public Instance Methods

build() click to toggle source

Core build Thor command @return [void]

# File lib/middleman-core/cli/build.rb, line 45
def build
  unless ENV['MM_ROOT']
    raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?'
  end

  require 'middleman-core'
  require 'middleman-core/logger'

  # 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
  self.had_errors = false

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

  opts = {}
  opts[:glob]  = options['glob'] if options.key?('glob')
  opts[:clean] = options['clean']

  self.class.shared_instance.run_hook :before_build, self

  action BuildAction.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
    shell.say msg, :red
  end

  exit(1) if had_errors
end