Sha256: d7ce492835897db6c1b08e1ea2c38aba1e43a9ed63abe4e5299dcbc214489411

Contents?: true

Size: 845 Bytes

Versions: 20

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

module LearnTest
  module JsStrategy
    def js_package
      @js_package ||= File.exist?('package.json') ? Oj.load(File.read('package.json'), symbol_keys: true) : nil
    end

    def has_js_dependency?(dep)
      [:dependencies, :devDependencies].any? { |key| js_package[key] && js_package[key][dep] }
    end

    def modules_missing?(module_names)
      module_names.any? { |name| !File.exist?("node_modules/#{name}") }
    end

    def missing_dependencies?
      return true unless File.exist?('node_modules')
      [:dependencies, :devDependencies, :peerDependencies].any? do |dep_group|
        modules = js_package[dep_group] || {}
        modules_missing?(modules.keys)
      end
    end

    def npm_install
      run_install('npm install', npm_install: true) if missing_dependencies?
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
learn-test-3.3.1 lib/learn_test/js_strategy.rb
learn-test-3.3.0 lib/learn_test/js_strategy.rb
learn-test-3.3.0.pre.6 lib/learn_test/js_strategy.rb
learn-test-3.3.0.pre.5 lib/learn_test/js_strategy.rb
learn-test-3.3.0.pre.4 lib/learn_test/js_strategy.rb
learn-test-3.3.0.pre.3 lib/learn_test/js_strategy.rb
learn-test-3.3.0.pre.2 lib/learn_test/js_strategy.rb
learn-test-3.3.0.pre.1 lib/learn_test/js_strategy.rb
learn-test-3.2.4 lib/learn_test/js_strategy.rb
learn-test-3.2.3 lib/learn_test/js_strategy.rb
learn-test-3.2.2 lib/learn_test/js_strategy.rb
learn-test-3.2.1 lib/learn_test/js_strategy.rb
learn-test-3.2.1.pre.7 lib/learn_test/js_strategy.rb
learn-test-3.2.1.pre.6 lib/learn_test/js_strategy.rb
learn-test-3.2.1.pre.5 lib/learn_test/js_strategy.rb
learn-test-3.2.1.pre.4 lib/learn_test/js_strategy.rb
learn-test-3.2.1.pre.3 lib/learn_test/js_strategy.rb
learn-test-3.2.1.pre.2 lib/learn_test/js_strategy.rb
learn-test-3.2.1.pre.1 lib/learn_test/js_strategy.rb
learn-test-3.2.0 lib/learn_test/js_strategy.rb