Sha256: b5cf20a9822cbbcf46f156329fb7fe1e844578274557b9e7f2eb29992c46e90a

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

module EmberCli
  class BuildMonitor
    def initialize(name, paths)
      @name = name
      @paths = paths
    end

    def check!
      if has_build_errors?
        raise_build_error!
      end

      true
    end

    def reset
      if error_file_exists?
        error_file.delete
      end
    end

    def wait!
      loop do
        check!
        break if complete?
        sleep 0.1
      end
    end

    private

    attr_reader :name, :paths

    def complete?
      !paths.lockfile.exist?
    end

    def error_file_exists?
      error_file.exist? && error_file.size?
    end

    def build_errors
      error_lines.
        reject { |line| is_blank_or_backtrace?(line) }.
        reject { |line| is_deprecation_warning?(line) }.
        reject { |line| is_building_notice?(line) }
    end

    def has_build_errors?
      build_errors.any?
    end

    def is_blank_or_backtrace?(line)
      line =~ /(^\s*$|^\s{4}at .+$)/
    end

    def is_deprecation_warning?(line)
      line =~ /^(\e[^\s]+)?DEPRECATION:/
    end

    def is_building_notice?(line)
      line =~ /^(\e[^\s]+)?.\s(\e[^\s]+)?Building/
    end

    def error_lines
      if error_file_exists?
        error_file.readlines
      else
        [""]
      end
    end

    def error_file
      paths.build_error_file
    end

    def raise_build_error!
      backtrace = build_errors.first
      message = "#{name.inspect} has failed to build: #{backtrace}"

      error = BuildError.new(message)
      error.set_backtrace(backtrace)

      fail error
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ember-cli-rails-0.12.2 lib/ember_cli/build_monitor.rb
ember-cli-rails-0.12.1 lib/ember_cli/build_monitor.rb
ember-cli-rails-0.12.0 lib/ember_cli/build_monitor.rb