Sha256: 5a06ace331c4076939675745bdf8ab6c865e70a6576fdcfafaa0fa4c533fccef

Contents?: true

Size: 897 Bytes

Versions: 5

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

require "refinements/io"
require "refinements/pathname"
require "rubocop"

module Hanamismith
  module Extensions
    # Ensures NPM packages are installed if NPM is available.
    class NPM
      include Import[:kernel, :logger]

      using Refinements::IO
      using Refinements::Pathname

      def self.call(...) = new(...).call

      def initialize(configuration, **)
        super(**)
        @configuration = configuration
      end

      def call
        logger.error { "Unable to detect NPM. Install NPM and run: `npm install`." } unless run
        configuration
      end

      private

      attr_reader :configuration

      def run
        success = false

        configuration.project_root.change_dir do
          STDOUT.squelch { success = kernel.system "command -v npm && npm install" }
        end

        success
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hanamismith-0.28.1 lib/hanamismith/extensions/npm.rb
hanamismith-0.28.0 lib/hanamismith/extensions/npm.rb
hanamismith-0.27.0 lib/hanamismith/extensions/npm.rb
hanamismith-0.26.0 lib/hanamismith/extensions/npm.rb
hanamismith-0.25.0 lib/hanamismith/extensions/npm.rb