Class: Middleman::Cli::Build

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

Overview

The CLI Build class

Instance Method Summary collapse

Instance Method Details

#build

This method returns an undefined value.

Core build Thor command



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

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'
  require 'middleman-core/builder'
  require 'fileutils'

  verbose = options['verbose'] ? 0 : 1
  instrument = options['instrument']

  builder = nil
  cli_options = options

  ::Middleman::Logger.singleton(verbose, instrument)

  ::Middleman::Util.instrument 'builder.setup' do
    @app = ::Middleman::Application.new do
      config[:mode] = :build
      config[:show_exceptions] = false
      config[:cli_options] = cli_options.each_with_object({}) do |(k, v), sum|
        sum[k] = v
      end
    end

    builder = Middleman::Builder.new(@app,
                                     glob: options['glob'],
                                     clean: options['clean'],
                                     parallel: options['parallel'])
    builder.thor = self
    builder.on_build_event(&method(:on_event))
  end

  ::Middleman::Util.instrument 'builder.run' do
    if builder.run!
      clean_directories! if options['clean']
      shell.say 'Project built successfully.'
    else
      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

      exit(1)
    end
  end
end