Sha256: f0240dcdcc01aa8345b1dc0a531cc16d8574f7725949a482fb5037fe681a966b

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module NeetoCompliance
  class NodeVersionVerifier < Base
    def node_version
      JSON.parse(open(common_packages_latest_file).read)["engines"]["node"]
    end

    def package_json_engines
      JSON.parse(open("package.json").read)["engines"]
    end

    def auto_correct!
    end

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

    def valid?
      @errors = []
      unless updated_nvmrc_file?
        @errors << "Update node version in .nvmrc to #{node_version}"
      end

      unless updated_node_version_file?
        @errors << "Update node version in .node-version to #{node_version}"
      end

      unless check_node_step_added_to_semahore_config?
        @errors << "Add node version to your semaphore.yml as shown below:
            global_job_config:
              prologue:
                commands:
                  - checkout
                  - sem-version ruby 3.0.1
                  - sem-version node #{node_version}
                  - sem-service start postgres 12.4
           \n "
      end

      @errors.length == 0
    end

    def updated_node_version_file?
      node_version == File.open(".node-version").read.chomp
    end

    def updated_nvmrc_file?
      node_version == File.open(".nvmrc").read.chomp
    end

    def check_node_step_added_to_semahore_config?
      semaphore_config = YAML.load(File.open(".semaphore/semaphore.yml").read, aliases: true)
      semaphore_command = "sem-version node #{node_version}"
      semaphore_config["global_job_config"]["prologue"]["commands"].include?(semaphore_command)
    end

    def common_packages_latest_file
      NeetoCompliance::NeetoCommons.path.join "common_files/package-common.json"
    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/node_version_verifier.rb
neetob-0.1.1 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/node_version_verifier.rb
neetob-0.1.0 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/node_version_verifier.rb