# frozen_string_literal: true module NeetoCompliance class NeetoCommonsSyncVerifier < Base def webpack_config_files @_webpack_config_files ||= { "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! @autofix_commands.each do |command| puts command system(command) end end def autofix_suggestion @autofix_commands.join("\n").yellow end def valid? @autofix_commands = [] webpack_config_files.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