npmdc 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7aaba2b72154a5a78139ad6d6dfa6bced85ddb0f
4
- data.tar.gz: c97559ba4610458e6baf1044b09d8d8adf1c2f9e
3
+ metadata.gz: d7eada3811dc31b5a240495eba981289843e70a7
4
+ data.tar.gz: e4c1bf4e93e6d0b56682a4403c1aee1b7c7fa412
5
5
  SHA512:
6
- metadata.gz: b7123a4a4e1c652c3a9a9bf97f304d8a83a3602bc153083bcd6a6af5f691b0f67fad9a4c85fae2bc77e76cc0ef74d214b185a8c761f2d86cbcc62228d0f9ff97
7
- data.tar.gz: c915ab3b3bacd40907cc7a298747d907e12619a225e6ee3f54dfb2f4b6355291c4e9900a499a9c9e53851aee3eb735e59914ccc2518722ca185b7a920a58876e
6
+ metadata.gz: 7ec1aad5bcae24fbd540061ac20caa085e3e69c04e045bac1352d53b1d3e2921135187ab747f47f395c15dd19c883c1c08d3a3c730d8888f8a1e1fc43b7965f3
7
+ data.tar.gz: 277912a03de5824c67f3a857408aaa9c55d7943e210ee0a8d210216115e3c549f76f12df517bfa4a3266747a2b6fbe4cc1896dbaf5f7641f83b97326cba06062
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  DisabledByDefault: true
3
+ TargetRubyVersion: 2.3
3
4
 
4
5
  #################### Lint ################################
5
6
 
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
- rvm:
4
- - 2.2.2
5
- - 2.3.3
6
- - ruby-head
3
+ cache: bundler
4
+ matrix:
5
+ include:
6
+ - rvm: 2.3.3
7
+ gemfile: gemfiles/rails42.gemfile
8
+ - rvm: 2.3.3
9
+ gemfile: gemfiles/rails5.gemfile
7
10
 
8
11
  before_install: gem install bundler -v 1.13.6
data/CHANGELOG.md CHANGED
@@ -43,4 +43,15 @@ Thanks to @aderyabin !
43
43
 
44
44
  ### 0.2.2
45
45
 
46
+ Thanks to @palkan !
47
+
46
48
  * Fixed runtime dependencies
49
+
50
+
51
+ ### 0.2.3
52
+
53
+ * Improved Rails integration
54
+
55
+ * Add Rails integration specs
56
+
57
+ * Minor improvemnts
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.2.0'
4
+
5
+ gemspec path: '..'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.0.0'
4
+
5
+ gemspec path: '..'
data/lib/npmdc/checker.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'colorize'
2
2
  require 'json'
3
- require 'npmdc/helpers'
4
3
  require 'npmdc/formatter'
5
4
  require 'npmdc/errors'
6
5
  require 'forwardable'
@@ -10,15 +9,15 @@ module Npmdc
10
9
  extend Forwardable
11
10
  include Npmdc::Errors
12
11
 
13
- attr_accessor :path, :formatter
12
+ attr_reader :path, :formatter
14
13
 
15
14
  DEPENDENCIES = %w(dependencies devDependencies).freeze
16
15
 
17
16
  def initialize(options)
18
- @path = options['path'] || Dir.pwd
17
+ @path = options[:path] || Dir.pwd
19
18
  @formatter = Npmdc::Formatter.(options)
20
19
  @dependencies_count = 0
21
- @missed_dependencies = []
20
+ @missing_dependencies = Set.new
22
21
  end
23
22
 
24
23
  delegate [:output, :dep_output, :check_start_output, :check_finish_output] => :formatter
@@ -26,13 +25,10 @@ module Npmdc
26
25
  def call
27
26
  begin
28
27
  success = false
29
- package_json_data = package_json(@path)
28
+ package_json_data = package_json(path)
29
+
30
30
  DEPENDENCIES.each do |dep|
31
- if package_json_data[dep]
32
- begin
33
- check_dependencies(package_json_data[dep], dep)
34
- end
35
- end
31
+ check_dependencies(package_json_data[dep], dep) if package_json_data[dep]
36
32
  end
37
33
 
38
34
  rescue NoNodeModulesError => e
@@ -48,33 +44,32 @@ module Npmdc
48
44
  rescue JsonParseError => e
49
45
  output("Can't parse JSON file #{e.message}")
50
46
  else
51
- success = true unless !@missed_dependencies.empty?
47
+ success = true unless !@missing_dependencies.empty?
52
48
  ensure
53
- if !@missed_dependencies.empty?
49
+ if !@missing_dependencies.empty?
54
50
  output("Following dependencies required by your package.json file are missing or not installed properly:")
55
- @missed_dependencies.uniq.each do |dep|
51
+ @missing_dependencies.each do |dep|
56
52
  output(" * #{dep}")
57
53
  end
58
- output("\nRun `npm install` to install #{@missed_dependencies.uniq.count} missed packages.", :warn)
54
+ output("\nRun `npm install` to install #{@missing_dependencies.size} missing packages.", :warn)
59
55
  elsif success
60
- output("#{pluralize(@dependencies_count, 'package')} checked. Everything is ok.", :success)
56
+ output("Checked #{@dependencies_count} packages. Everything is ok.", :success)
61
57
  end
62
-
63
- return success
64
58
  end
59
+
60
+ success
65
61
  end
66
62
 
67
63
  private
68
64
 
69
65
  def installed_modules
70
66
  @installed_modules ||= begin
71
- modules_directory = File.join(@path, 'node_modules')
72
- raise NoNodeModulesError, @path unless Dir.exist?(modules_directory)
67
+ modules_directory = File.join(path, 'node_modules')
68
+ raise NoNodeModulesError, path unless Dir.exist?(modules_directory)
73
69
 
74
- Dir.entries(modules_directory).each_with_object({}) do |entry, modules|
75
- if entry != '.' && entry != '..' and File.directory? File.join(modules_directory, entry)
76
- modules[entry] = package_json(File.join(modules_directory, entry))
77
- end
70
+ Dir.glob("#{modules_directory}/*").each_with_object({}) do |file_path, modules|
71
+ next unless File.directory?(file_path)
72
+ modules[File.basename(file_path)] = package_json(file_path)
78
73
  end
79
74
  end
80
75
  end
@@ -91,20 +86,22 @@ module Npmdc
91
86
  end
92
87
  end
93
88
 
94
- def check_dependencies(deps = {}, type)
95
- installed_modules
89
+ def check_dependencies(deps, type)
96
90
  check_start_output(type)
97
- deps.keys.each do |dep|
91
+ deps.each_key do |dep|
98
92
  @dependencies_count += 1
99
- status = valid_dependency?(dep) ? :success : :failure
100
- @missed_dependencies.push("#{dep}@#{deps[dep]}") unless valid_dependency?(dep)
101
- dep_output(dep, status)
93
+ check_dependency(dep, deps[dep])
102
94
  end
103
95
  check_finish_output
104
96
  end
105
97
 
106
- def valid_dependency?(dep)
107
- !!installed_modules[dep]
98
+ def check_dependency(dep, version)
99
+ if installed_modules[dep]
100
+ dep_output(dep, :success)
101
+ else
102
+ @missing_dependencies << "#{dep}@#{version}"
103
+ dep_output(dep, :failure)
104
+ end
108
105
  end
109
106
  end
110
107
  end
data/lib/npmdc/cli.rb CHANGED
@@ -7,11 +7,11 @@ module Npmdc
7
7
 
8
8
  desc 'check', 'Run check'
9
9
  method_option :path, desc: 'Path to package.json config'
10
- method_option :'no-color', desc: 'Disable color', type: :boolean
10
+ method_option :color, desc: 'Enable color', type: :boolean, default: true
11
11
  method_option :format, desc: "Output format, possible values: #{Npmdc::Formatter::FORMATTERS.keys.join(", ")}"
12
12
 
13
13
  def check
14
- Npmdc::Checker.new(options).call
14
+ Npmdc.call(options)
15
15
  end
16
16
 
17
17
  map %w[--version -v] => :__print_version
@@ -0,0 +1,13 @@
1
+ require 'npmdc'
2
+
3
+ module Npmdc
4
+ class Engine < Rails::Engine # :nodoc:
5
+ config.npmdc = ActiveSupport::OrderedOptions.new
6
+
7
+ initializer "npmdc.load_hook" do |app|
8
+ options = app.config.npmdc
9
+ options.path ||= Rails.root
10
+ Npmdc.call(options)
11
+ end
12
+ end
13
+ end
data/lib/npmdc/errors.rb CHANGED
@@ -6,4 +6,4 @@ module Npmdc
6
6
  class MissedDepsError < StandardError; end
7
7
  class WrongPathError < StandardError; end
8
8
  end
9
- end
9
+ end
@@ -1,21 +1,23 @@
1
- Dir["#{File.dirname(__FILE__)}/formatters/*.rb"].each { |file| require file }
1
+ require 'npmdc/formatters/progress'
2
+ require 'npmdc/formatters/documentation'
3
+ require 'npmdc/formatters/short'
2
4
 
3
5
  module Npmdc
4
6
  module Formatter
5
7
 
6
8
  FORMATTERS = {
7
- progress: Npmdc::Formatters::ProgressFormatter,
8
- doc: Npmdc::Formatters::DocumentationFormatter,
9
- short: Npmdc::Formatters::ShortFormatter,
9
+ progress: Npmdc::Formatters::Progress,
10
+ doc: Npmdc::Formatters::Documentation,
11
+ short: Npmdc::Formatters::Short
10
12
  }.freeze
11
13
 
12
14
  DEFAULT_FORMAT = :short
13
15
 
14
16
  class << self
15
17
  def call(options)
16
- fmt = options['format'] || options[:format] || DEFAULT_FORMAT
18
+ fmt = options.fetch(:format, DEFAULT_FORMAT)
17
19
  FORMATTERS[fmt.to_sym].new(options)
18
20
  end
19
21
  end
20
22
  end
21
- end
23
+ end
@@ -2,7 +2,7 @@ require 'colorized_string'
2
2
 
3
3
  module Npmdc
4
4
  module Formatters
5
- class BaseFormatter
5
+ class Base
6
6
 
7
7
  COLORS = {
8
8
  success: :green,
@@ -11,16 +11,20 @@ module Npmdc
11
11
  info: :white
12
12
  }.freeze
13
13
 
14
- def initialize(options, output = $stdout)
14
+ def initialize(options, output = Npmdc.output)
15
15
  @options = options
16
16
  @output = output
17
- @disable_colorization = !!(@options['no-color'] || @options['no_color'])
17
+ @disable_colorization = !@options.fetch(:color, true)
18
18
  end
19
19
 
20
20
  def output(message, status = nil)
21
21
  @output.puts color_message(message, status)
22
22
  end
23
23
 
24
+ def dep_output(dep, status)
25
+ # no-op
26
+ end
27
+
24
28
  def check_finish_output
25
29
  @output.puts "\n"
26
30
  end
@@ -1,7 +1,9 @@
1
+ require_relative './base'
2
+
1
3
  module Npmdc
2
4
  module Formatters
3
- class DocumentationFormatter < BaseFormatter
4
- def dep_output(dep, status, options = {})
5
+ class Documentation < Base
6
+ def dep_output(dep, status)
5
7
  case status
6
8
  when :success
7
9
  @output.puts color_message(" ✓ #{dep}", status)
@@ -1,7 +1,9 @@
1
+ require_relative './base'
2
+
1
3
  module Npmdc
2
4
  module Formatters
3
- class ProgressFormatter < BaseFormatter
4
- def dep_output(dep, status, options = {})
5
+ class Progress < Base
6
+ def dep_output(_dep, status)
5
7
  case status
6
8
  when :success
7
9
  @output.print color_message(".", status)
@@ -1,9 +1,8 @@
1
+ require_relative './base'
2
+
1
3
  module Npmdc
2
4
  module Formatters
3
- class ShortFormatter < BaseFormatter
4
- def dep_output(dep, status, options = {})
5
- end
6
-
5
+ class Short < Base
7
6
  def check_start_output(type)
8
7
  end
9
8
 
data/lib/npmdc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Npmdc
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
data/lib/npmdc.rb CHANGED
@@ -1,9 +1,17 @@
1
1
  require "npmdc/checker"
2
- require "npmdc/railtie" if defined?(Rails)
2
+ require "npmdc/engine" if defined?(Rails)
3
3
  require "npmdc/version"
4
4
 
5
5
  module Npmdc
6
- def self.call(options = {})
7
- Npmdc::Checker.new(options).call
6
+ class << self
7
+ attr_writer :output
8
+
9
+ def call(options = {})
10
+ Npmdc::Checker.new(options).call
11
+ end
12
+
13
+ def output
14
+ @output ||= STDOUT
15
+ end
8
16
  end
9
17
  end
data/log/test.log ADDED
File without changes
data/npmdc.gemspec CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = ['npmdc']
20
20
  spec.require_paths = ['lib']
21
21
  spec.required_ruby_version = '>= 2.2.2'
22
- spec.add_dependency 'thor', '~> 0.19.4'
22
+ spec.add_dependency 'thor', '> 0.18'
23
23
  spec.add_dependency 'colorize', '~> 0.8.1'
24
24
  spec.add_development_dependency 'bundler', '~> 1.13'
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'rails', '>= 4.2'
28
+ spec.add_development_dependency 'pry-byebug'
27
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: npmdc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kashkevich
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.19.4
19
+ version: '0.18'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.19.4
26
+ version: '0.18'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: colorize
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: Check for missed dependencies of NPM packages based on dependency list
84
112
  specified in package.json file.
85
113
  email:
@@ -103,18 +131,20 @@ files:
103
131
  - bin/console
104
132
  - bin/npmdc
105
133
  - bin/setup
134
+ - gemfiles/rails42.gemfile
135
+ - gemfiles/rails5.gemfile
106
136
  - lib/npmdc.rb
107
137
  - lib/npmdc/checker.rb
108
138
  - lib/npmdc/cli.rb
139
+ - lib/npmdc/engine.rb
109
140
  - lib/npmdc/errors.rb
110
141
  - lib/npmdc/formatter.rb
111
- - lib/npmdc/formatters/base_formatter.rb
112
- - lib/npmdc/formatters/documentation_formatter.rb
113
- - lib/npmdc/formatters/progress_formatter.rb
114
- - lib/npmdc/formatters/short_formatter.rb
115
- - lib/npmdc/helpers.rb
116
- - lib/npmdc/railtie.rb
142
+ - lib/npmdc/formatters/base.rb
143
+ - lib/npmdc/formatters/documentation.rb
144
+ - lib/npmdc/formatters/progress.rb
145
+ - lib/npmdc/formatters/short.rb
117
146
  - lib/npmdc/version.rb
147
+ - log/test.log
118
148
  - npmdc.gemspec
119
149
  homepage: https://github.com/lysyi3m/npmdc
120
150
  licenses:
data/lib/npmdc/helpers.rb DELETED
@@ -1,9 +0,0 @@
1
- def pluralize(n, singular, plural = nil)
2
- if n == 1
3
- "1 #{singular}"
4
- elsif plural
5
- "#{n} #{plural}"
6
- else
7
- "#{n} #{singular}s"
8
- end
9
- end
data/lib/npmdc/railtie.rb DELETED
@@ -1,16 +0,0 @@
1
- require 'rails'
2
-
3
- module Npmdc
4
- class Railtie < Rails::Railtie
5
- config.npmdc = ActiveSupport::OrderedOptions.new
6
-
7
- initializer 'npmdc' do |app|
8
- options = {
9
- path: app.config.npmdc[:path] || Rails.root,
10
- verbose: app.config.npmdc[:verbose]
11
- }
12
-
13
- Npmdc.call(options)
14
- end
15
- end
16
- end