def build
      root = ENV['MM_ROOT'] || Dir.pwd

      raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?' unless File.exist?(File.join(root, 'config.rb'))

      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
        missing_and_changed = !options['only_changed'] && options['missing_and_changed']
        should_track_dependencies = options['only_changed'] || missing_and_changed || options['track_dependencies']
        data_collection_depth = options['data_collection_depth']

        @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
          config[:track_data_access] = should_track_dependencies
          config[:data_collection_depth] = data_collection_depth
        end

        builder = Middleman::Builder.new(@app,
                                         glob: options['glob'],
                                         dry_run: options['dry_run'],
                                         clean: options['clean'],
                                         parallel: options['parallel'],
                                         only_changed: options['only_changed'],
                                         missing_and_changed: missing_and_changed,
                                         track_dependencies: should_track_dependencies,
                                         visualize_graph: options['visualize_graph'])
        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']
          puts 'Project built successfully.'
        else
          msg = 'There were errors during this build'
          msg << ', re-run with `middleman build --verbose` to see the full exception.' unless options['verbose']
          shell.say msg, :red

          exit(1)
        end
      end
    end
def build
      root = ENV['MM_ROOT'] || Dir.pwd

      raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?' unless File.exist?(File.join(root, 'config.rb'))

      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
        missing_and_changed = !options['only_changed'] && options['missing_and_changed']
        should_track_dependencies = options['only_changed'] || missing_and_changed || options['track_dependencies']
        data_collection_depth = options['data_collection_depth']

        @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
          config[:track_data_access] = should_track_dependencies
          config[:data_collection_depth] = data_collection_depth
        end

        builder = Middleman::Builder.new(@app,
                                         glob: options['glob'],
                                         dry_run: options['dry_run'],
                                         clean: options['clean'],
                                         parallel: options['parallel'],
                                         only_changed: options['only_changed'],
                                         missing_and_changed: missing_and_changed,
                                         track_dependencies: should_track_dependencies,
                                         visualize_graph: options['visualize_graph'])
        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']
          puts 'Project built successfully.'
        else
          msg = 'There were errors during this build'
          msg << ', re-run with `middleman build --verbose` to see the full exception.' unless options['verbose']
          shell.say msg, :red

          exit(1)
        end
      end
    end
Core build Thor command
 @return [void]