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 +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +7 -4
- data/CHANGELOG.md +11 -0
- data/gemfiles/rails42.gemfile +5 -0
- data/gemfiles/rails5.gemfile +5 -0
- data/lib/npmdc/checker.rb +28 -31
- data/lib/npmdc/cli.rb +2 -2
- data/lib/npmdc/engine.rb +13 -0
- data/lib/npmdc/errors.rb +1 -1
- data/lib/npmdc/formatter.rb +8 -6
- data/lib/npmdc/formatters/{base_formatter.rb → base.rb} +7 -3
- data/lib/npmdc/formatters/{documentation_formatter.rb → documentation.rb} +4 -2
- data/lib/npmdc/formatters/{progress_formatter.rb → progress.rb} +4 -2
- data/lib/npmdc/formatters/{short_formatter.rb → short.rb} +3 -4
- data/lib/npmdc/version.rb +1 -1
- data/lib/npmdc.rb +11 -3
- data/log/test.log +0 -0
- data/npmdc.gemspec +3 -1
- metadata +41 -11
- data/lib/npmdc/helpers.rb +0 -9
- data/lib/npmdc/railtie.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7eada3811dc31b5a240495eba981289843e70a7
|
4
|
+
data.tar.gz: e4c1bf4e93e6d0b56682a4403c1aee1b7c7fa412
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ec1aad5bcae24fbd540061ac20caa085e3e69c04e045bac1352d53b1d3e2921135187ab747f47f395c15dd19c883c1c08d3a3c730d8888f8a1e1fc43b7965f3
|
7
|
+
data.tar.gz: 277912a03de5824c67f3a857408aaa9c55d7943e210ee0a8d210216115e3c549f76f12df517bfa4a3266747a2b6fbe4cc1896dbaf5f7641f83b97326cba06062
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
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
|
-
|
12
|
+
attr_reader :path, :formatter
|
14
13
|
|
15
14
|
DEPENDENCIES = %w(dependencies devDependencies).freeze
|
16
15
|
|
17
16
|
def initialize(options)
|
18
|
-
@path = options[
|
17
|
+
@path = options[:path] || Dir.pwd
|
19
18
|
@formatter = Npmdc::Formatter.(options)
|
20
19
|
@dependencies_count = 0
|
21
|
-
@
|
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(
|
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 !@
|
47
|
+
success = true unless !@missing_dependencies.empty?
|
52
48
|
ensure
|
53
|
-
if !@
|
49
|
+
if !@missing_dependencies.empty?
|
54
50
|
output("Following dependencies required by your package.json file are missing or not installed properly:")
|
55
|
-
@
|
51
|
+
@missing_dependencies.each do |dep|
|
56
52
|
output(" * #{dep}")
|
57
53
|
end
|
58
|
-
output("\nRun `npm install` to install #{@
|
54
|
+
output("\nRun `npm install` to install #{@missing_dependencies.size} missing packages.", :warn)
|
59
55
|
elsif success
|
60
|
-
output("#{
|
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(
|
72
|
-
raise NoNodeModulesError,
|
67
|
+
modules_directory = File.join(path, 'node_modules')
|
68
|
+
raise NoNodeModulesError, path unless Dir.exist?(modules_directory)
|
73
69
|
|
74
|
-
Dir.
|
75
|
-
|
76
|
-
|
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
|
95
|
-
installed_modules
|
89
|
+
def check_dependencies(deps, type)
|
96
90
|
check_start_output(type)
|
97
|
-
deps.
|
91
|
+
deps.each_key do |dep|
|
98
92
|
@dependencies_count += 1
|
99
|
-
|
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
|
107
|
-
|
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 :
|
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
|
14
|
+
Npmdc.call(options)
|
15
15
|
end
|
16
16
|
|
17
17
|
map %w[--version -v] => :__print_version
|
data/lib/npmdc/engine.rb
ADDED
@@ -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
data/lib/npmdc/formatter.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
|
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::
|
8
|
-
doc: Npmdc::Formatters::
|
9
|
-
short: Npmdc::Formatters::
|
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
|
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
|
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 =
|
14
|
+
def initialize(options, output = Npmdc.output)
|
15
15
|
@options = options
|
16
16
|
@output = output
|
17
|
-
@disable_colorization =
|
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
|
4
|
-
def dep_output(dep, status
|
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
|
4
|
-
def dep_output(
|
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)
|
data/lib/npmdc/version.rb
CHANGED
data/lib/npmdc.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
require "npmdc/checker"
|
2
|
-
require "npmdc/
|
2
|
+
require "npmdc/engine" if defined?(Rails)
|
3
3
|
require "npmdc/version"
|
4
4
|
|
5
5
|
module Npmdc
|
6
|
-
|
7
|
-
|
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', '
|
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.
|
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
|
+
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.
|
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/
|
112
|
-
- lib/npmdc/formatters/
|
113
|
-
- lib/npmdc/formatters/
|
114
|
-
- lib/npmdc/formatters/
|
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
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
|