Class: Dev::EndOfLife::Node

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/eol/node.rb

Overview

Class which checks for eol packges referenced by the node package manager

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node = Dev::Node.new) ⇒ Node

Returns a new instance of Node.



7
8
9
10
# File 'lib/firespring_dev_commands/eol/node.rb', line 7

def initialize(node = Dev::Node.new)
  @node = node
  @lockfile = File.join(node.local_path, "#{node.package_file.reverse.split('.')[-1].reverse}-lock.json")
end

Instance Attribute Details

#lockfileObject (readonly)

Returns the value of attribute lockfile.



5
6
7
# File 'lib/firespring_dev_commands/eol/node.rb', line 5

def lockfile
  @lockfile
end

#nodeObject (readonly)

Returns the value of attribute node.



5
6
7
# File 'lib/firespring_dev_commands/eol/node.rb', line 5

def node
  @node
end

Instance Method Details

#default_productsObject

Default to NPM products



13
14
15
# File 'lib/firespring_dev_commands/eol/node.rb', line 13

def default_products
  npm_products
end

#npm_productsObject

1.) Parse the npm lock file 2.) Do some package name and version manipulation 3.) Return the product if it looks like something that the EOL library tracks



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/firespring_dev_commands/eol/node.rb', line 20

def npm_products
  eol = Dev::EndOfLife.new
  major_version_only_products = %w(ckeditor jquery)

  [].tap do |ary|
    packages = JSON.parse(File.read(lockfile))&.fetch('packages', [])
    packages.each do |key, info|
      name = key.split('node_modules/').last
      product = name

      # Make sure what we found is supported by the EOL library
      next unless eol.product?(product)

      version = info['version'].reverse.split('.')[-2..].join('.').reverse.tr('v', '')
      version = version.split('.').first if major_version_only_products.include?(product)
      version.chop! if version.end_with?('.00')
      ary << Dev::EndOfLife::ProductVersion.new(product, version, name)
    end
  end
end