Class: Npm3ppLister::Commands::List

Inherits:
Npm3ppLister::Command show all
Defined in:
lib/npm_3pp_lister/commands/list.rb

Instance Method Summary collapse

Methods inherited from Npm3ppLister::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(options) ⇒ List

Returns a new instance of List.



10
11
12
# File 'lib/npm_3pp_lister/commands/list.rb', line 10

def initialize(options)
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/npm_3pp_lister/commands/list.rb', line 14

def execute(input: $stdin, output: $stdout)
  if File.file?('./package.json')
    file = File.read('./package.json')
    json = JSON.parse(file)

    output.puts "dependencies:"
    output.puts "\n"
    json["dependencies"].each do |key, val|
      source_code_url = `npm view #{key}@#{val} dist.tarball`
      output.puts "#{key.colorize(:yellow)}: #{val}" + " " + source_code_url.colorize(:green)
    end

    output.puts "\n\n\n"
    output.puts "devDependencies:"
    output.puts "\n"
    json["devDependencies"].each do |key, val|
      source_code_url = `npm view #{key}@#{val} dist.tarball`
      output.puts "#{key.colorize(:yellow)}: #{val}" + " " + source_code_url.colorize(:green)
    end

  else
    output.puts "- No package.json found here -"
  end
end