Sha256: 0a1dec0f38062e46351ad051c85a8181531d81098bd88d2aea60b6ef93e33d4f
Contents?: true
Size: 1.24 KB
Versions: 4
Compression:
Stored size: 1.24 KB
Contents
require 'json' require 'license_finder/package' module LicenseFinder class NPM def self.current_modules return @modules if @modules output = `npm list --json --long` json = JSON(output) @modules = json.fetch("dependencies",[]).map do |node_module| node_module = node_module[1] Package.new(OpenStruct.new( :name => node_module.fetch("name", nil), :version => node_module.fetch("version", nil), :full_gem_path => node_module.fetch("path", nil), :license => self.harvest_license(node_module), :summary => node_module.fetch("description", nil), :description => node_module.fetch("readme", nil) )) end end def self.has_package? File.exists?(package_path) end private def self.package_path Pathname.new('package.json').expand_path end def self.harvest_license(node_module) license = node_module.fetch("licenses", []).first if license license = license.fetch("type", nil) end if license.nil? license = node_module.fetch("license", nil) if license.is_a? Hash license = license.fetch("type", nil) end end license end end end
Version data entries
4 entries across 4 versions & 1 rubygems