Sha256: bcf0f503c7d3d8e5d92fa0d23810323b75ad7394bf025d038992eb3ab81b8ffa

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module NeetoCompliance
  class CypressConfigVerifier < Base
    def cypress_config_files
      @_cypress_config_files ||= {
        "cypress-tests/package.json" => NeetoCompliance::NeetoCommons.path.join("cypress/package.json"),
        "cypress-tests/cypress/jsconfig.json" => NeetoCompliance::NeetoCommons.path.join("cypress/jsconfig.json"),
        "cypress-tests/cypress/webpack.config.js" => NeetoCompliance::NeetoCommons.path.join("cypress/webpack.config.js"),
        "cypress-tests/cypress/config/cypress.review.json" => NeetoCompliance::NeetoCommons.path.join("cypress/cypress.review.json"),
        "cypress-tests/cypress/resolve.js" => NeetoCompliance::NeetoCommons.path.join("cypress/resolve.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 = []

      cypress_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}"
          @autofix_commands << "cd cypress-tests && yarn" if local_file == "cypress-tests/package.json"
        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

4 entries across 4 versions & 2 rubygems

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