Sha256: 88c2af0257a336c885141c816650262f4de0041d50f27ee0f5bd9b552c10d534

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module NeetoCompliance
  class WebpackConfigurationVerifier < Base
    def files_to_sync
      @_files_to_sync ||= {
        "config/webpack/development.js" => NeetoCompliance::NeetoCommons.path.join("webpack/development.js"),
        "config/webpack/production.js" => NeetoCompliance::NeetoCommons.path.join("webpack/production.js"),
        "config/webpack/staging.js" => NeetoCompliance::NeetoCommons.path.join("webpack/staging.js"),
        "config/webpack/test.js" => NeetoCompliance::NeetoCommons.path.join("webpack/test.js")
      }
    end

    def auto_correct!
      unless valid?
        @autofix_commands.each do |command|
          puts command
          system(command)
        end
      end
    end

    def autofix_suggestion
      @autofix_commands.join("\n").yellow
    end

    def valid?
      @autofix_commands = []

      files_to_sync.each_pair do |local_file, common_file|
        unless same_file?(local_file, common_file)
          @autofix_commands << "cp #{common_file.to_s} #{local_file}"
        end
      end

      @autofix_commands.length == 0
    end

    def same_file?(local_file, common_file)
      File.exist?(local_file) &&
      `diff #{local_file} #{common_file.to_s}`.empty?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neetob-0.1.2 neeto_compliance/lib/neeto_compliance/verifiers/webpack_configuration_verifier.rb
neetob-0.1.1 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/webpack_configuration_verifier.rb
neetob-0.1.0 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/webpack_configuration_verifier.rb