# 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