Sha256: 85fd40c49f574273104e33cc74882cef7b4ca141d106ee63d3125fbe1e662f23

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

require_relative "common"

module Grundler
  module Commands
    class Install
      include Common

      def initialize(cli, _arguments, _json_writer)
        super(cli)
        unless File.exist?(Grundler::LOCKFILE_PATH)
          puts "No #{Grundler::LOCKFILE_PATH} file found!"
          return
        end

        loaded_versions = JSON.parse(File.read(Grundler::LOCKFILE_PATH))["dependencies"]
        loaded_versions.each { |k, v| install(specific_version(k, v)) }
      end

      private

      def specific_version(package_name, version_number)
        package_metadata = JSON.parse(HTTP.get("https://registry.npmjs.org/#{package_name}").to_s)
        package_metadata.dig("versions", version_number.delete_prefix("^")) || "Not found"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grundler-0.1.0 lib/grundler/commands/install.rb