<commit_before>require 'middleman-core/application'

# CLI Module
module Middleman::Cli
  # The CLI Build class
  class Build < Thor::Group
    include Thor::Actions

    check_unknown_options!

    class_option :environment,
                 aliases: '-e',
                 default: ENV['MM_ENV'] || ENV['RACK_ENV'] || :production
    class_option :clean,
                 type: :boolean,
                 default: true,
                 desc: 'Remove orphaned files from build (--no-clean to disable)'
    class_option :parallel,
                 type: :boolean,
                 default: true,
                 desc: 'Output files in parallel (--no-parallel to disable)'
    class_option :glob,
                 type: :string,
                 aliases: '-g',
                 default: nil,
                 desc: 'Build a subset of the project'
    class_option :verbose,
                 type: :boolean,
                 default: false,
                 desc: 'Print debug messages'
    class_option :bail,
                 type: :boolean,
                 default: false,
                 desc: 'Fail out on the first error and print error messages'
    class_option :instrument,
                 type: :boolean,
                 default: false,
                 desc: 'Print instrument messages'
    class_option :profile,
                 type: :boolean,
                 default: false,
                 desc: 'Generate profiling report for the build'
    class_option :dry_run,
                 type: :boolean,
                 default: false,
                 desc: 'Skip writing output files'
    class_option :track_dependencies,
                 type: :boolean,
                 default: false,
                 desc: 'Track file dependencies'
    class_option :dependency_file,
                 type: :string,
                 default: 'deps.yml',
                 desc: 'Track file dependencies'
    class_option :data_collection_depth,
                 type: :numeric,
                 default: 1,
                 desc: 'How deep to recurse into data structures when tracking changes.'
    class_option :visualize_graph,
                 type: :boolean,
                 default: false,
                 desc: 'Generate a visual of the dependency graph'
    class_option :only_changed,
                 type: :boolean,
                 default: false,
                 desc: 'Only build changed files'
    class_option :missing_and_changed,
                 type: :boolean,
                 default: false,
                 desc: 'Only build changed files or files missing from build folder'

    Middleman::Cli.import_config(self)

    # Core build Thor command
    # @return [void]
    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'],
                                         dependency_file: File.expand_path(options['dependency_file']))
        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

    protected

    # Handles incoming events from the builder.
    # @param [Symbol] event_type The type of event.
    # @param [String] target The event contents.
    # @param [String] extra The extra information.
    # @return [void]
    def on_event(event_type, target, extra = nil)
      case event_type
      when :error
        say_status :error, target, :red
        shell.say extra, :red if options['verbose'] || options['bail']
<commit_msg>Don't expand deps path immediately<commit_after>require 'middleman-core/application'

# CLI Module
module Middleman::Cli
  # The CLI Build class
  class Build < Thor::Group
    include Thor::Actions

    check_unknown_options!

    class_option :environment,
                 aliases: '-e',
                 default: ENV['MM_ENV'] || ENV['RACK_ENV'] || :production
    class_option :clean,
                 type: :boolean,
                 default: true,
                 desc: 'Remove orphaned files from build (--no-clean to disable)'
    class_option :parallel,
                 type: :boolean,
                 default: true,
                 desc: 'Output files in parallel (--no-parallel to disable)'
    class_option :glob,
                 type: :string,
                 aliases: '-g',
                 default: nil,
                 desc: 'Build a subset of the project'
    class_option :verbose,
                 type: :boolean,
                 default: false,
                 desc: 'Print debug messages'
    class_option :bail,
                 type: :boolean,
                 default: false,
                 desc: 'Fail out on the first error and print error messages'
    class_option :instrument,
                 type: :boolean,
                 default: false,
                 desc: 'Print instrument messages'
    class_option :profile,
                 type: :boolean,
                 default: false,
                 desc: 'Generate profiling report for the build'
    class_option :dry_run,
                 type: :boolean,
                 default: false,
                 desc: 'Skip writing output files'
    class_option :track_dependencies,
                 type: :boolean,
                 default: false,
                 desc: 'Track file dependencies'
    class_option :dependency_file,
                 type: :string,
                 default: 'deps.yml',
                 desc: 'Track file dependencies'
    class_option :data_collection_depth,
                 type: :numeric,
                 default: 1,
                 desc: 'How deep to recurse into data structures when tracking changes.'
    class_option :visualize_graph,
                 type: :boolean,
                 default: false,
                 desc: 'Generate a visual of the dependency graph'
    class_option :only_changed,
                 type: :boolean,
                 default: false,
                 desc: 'Only build changed files'
    class_option :missing_and_changed,
                 type: :boolean,
                 default: false,
                 desc: 'Only build changed files or files missing from build folder'

    Middleman::Cli.import_config(self)

    # Core build Thor command
    # @return [void]
    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'],
                                         dependency_file: options['dependency_file'])
        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

    protected

    # Handles incoming events from the builder.
    # @param [Symbol] event_type The type of event.
    # @param [String] target The event contents.
    # @param [String] extra The extra information.
    # @return [void]
    def on_event(event_type, target, extra = nil)
      case event_type
      when :error
        say_status :error, target, :red
        shell.say extra, :red if options['verbose'] || options['bail']

{'fraction_non_alphanumeric': 0.08754504702469895, 'fraction_numerical': 0.0007031730684714776, 'mean_word_length': 1.7090476190476191, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4250753', 'n_tokens_mistral': 2772, 'n_tokens_neox': 2684, 'n_words': 812}