npmdc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93c4b8f8f516f0beafab7cfe44d89bd754e400b9
4
+ data.tar.gz: c82d5836c95c17a11dfc8a0436abbb95e6ad06c2
5
+ SHA512:
6
+ metadata.gz: 7fdd0443a28f7d128a61743df0c0cfa402548d05e5d2c2c529c5beff8a59403011e03d5ad7d0363f7ee61673c91c5644c55cae4fad596e4a6696f76bdcaf1322
7
+ data.tar.gz: 7bca6de70b1cf50b275702f5c3b4a7e52b32dca0942fff371f5ddebbe96ba46daae4737f7f077f7712e386b06736905a02c698c60a6ab5e4157c94106d3de8f4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ### 0.1.0 First release
2
+
3
+ Initial implementation of Npmdc gem with following features:
4
+
5
+ * Checking for missed (or incorrectly installed) NPM dependencies inside specific folder
6
+
7
+ * Works with Ruby On Rails
8
+
9
+ * Standalone CLI tool
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Emil Kashkevich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # npmdc
2
+
3
+ *NPM Dependency Checker* is a simple tool which can check for missed dependencies based on your `package.json` file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'npmdc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install npmdc
20
+
21
+ ## Usage
22
+
23
+ ### Rails
24
+
25
+ ```ruby
26
+ YourApp::Application.configure do
27
+ config.npmdc = {
28
+ :path => "/path/to/your/frontend/code/dir" # `Rails.root` by default,
29
+ :verbose => true # `false` by default
30
+ }
31
+ end
32
+ ```
33
+
34
+ ### CLI tool:
35
+
36
+ ```bash
37
+ $ bundle exec npmdc --path="/path/to/your/frontend/code/dir" --verbose
38
+
39
+ ```
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lysyi3m/npmdc.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "npmdc"
5
+
6
+ require "irb"
7
+ IRB.start
data/bin/npmdc ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "npmdc/cli"
5
+
6
+ Npmdc::Cli.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/lib/npmdc.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "npmdc/checker"
2
+ require "npmdc/railtie" if defined?(Rails)
3
+ require "npmdc/version"
4
+
5
+ module Npmdc
6
+ def self.call(options = {})
7
+ Npmdc::Checker.new(options).call
8
+ end
9
+ end
@@ -0,0 +1,105 @@
1
+ require "json"
2
+ require "npmdc/helpers"
3
+
4
+ module Npmdc
5
+ class Checker
6
+ def initialize(options)
7
+ @options = {
8
+ :path => options[:path] || Dir.pwd,
9
+ :verbose => options[:verbose]
10
+ }
11
+ end
12
+
13
+ def call
14
+ package_json = get_package_json(@options[:path])
15
+
16
+ if package_json
17
+ package_json_data = parse_package_json(package_json)
18
+ @installed_modules = get_installed_modules
19
+ end
20
+
21
+ if package_json_data&.key?("dependencies")
22
+ dependencies = package_json_data["dependencies"]
23
+ check_dependencies(dependencies)
24
+ end
25
+
26
+ if package_json_data&.key?("devDependencies")
27
+ dev_dependencies = package_json_data["devDependencies"]
28
+ check_dependencies(dev_dependencies, "devDependencies")
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def get_installed_modules
35
+ modules_directory = File.join(@options[:path], "node_modules")
36
+
37
+ if Dir.exists?(modules_directory)
38
+ modules = {}
39
+
40
+ Dir.entries(modules_directory).each do |entry|
41
+ if entry != '.' && entry != '..' and File.directory? File.join(modules_directory, entry)
42
+ modules[entry] = File.join(modules_directory, entry)
43
+ end
44
+ end
45
+
46
+ modules
47
+ else
48
+ message = [
49
+ "Failed! Can't find `node_modules` folder inside '#{@options[:path]}' directory!",
50
+ "Try running `npm install` first."
51
+ ].join("\n")
52
+
53
+ puts message
54
+ exit
55
+ end
56
+ end
57
+
58
+ def get_package_json(directory)
59
+ file_path = File.join(directory, "package.json")
60
+
61
+ if File.file?(file_path)
62
+ File.read(file_path)
63
+ else
64
+ puts "There is no `package.json` file inside '#{directory}' directory." if @options[:verbose]
65
+ end
66
+ end
67
+
68
+ def parse_package_json(json)
69
+ begin
70
+ JSON.parse(json)
71
+ rescue JSON::ParserError => e
72
+ raise "Failed to parse package.json file."
73
+ end
74
+ end
75
+
76
+ def check_dependencies(deps = {}, type = "dependencies")
77
+ puts "Check #{type}..." if @options[:verbose]
78
+
79
+ missed_dependencies = []
80
+
81
+ deps.keys.each do |dep|
82
+ if @installed_modules.key?(dep)
83
+ package_json = get_package_json(@installed_modules[dep])
84
+ package_json_data = parse_package_json(package_json)
85
+ missed_dependencies.push(dep) unless package_json_data["name"] == dep
86
+ else
87
+ missed_dependencies.push(dep)
88
+ end
89
+ end
90
+
91
+ if missed_dependencies.any?
92
+ message = [
93
+ "Failed! Following #{type} required by your package.json file are missing or not installed properly:\n",
94
+ missed_dependencies.map { |dep| "* #{dep}@#{deps[dep]}" },
95
+ "\nRun `npm install` to install missing packages.",
96
+ ].join("\n")
97
+
98
+ puts message
99
+ exit
100
+ else
101
+ puts "OK! #{pluralize(deps.length, 'dependency', 'dependencies')} checked." if @options[:verbose]
102
+ end
103
+ end
104
+ end
105
+ end
data/lib/npmdc/cli.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "thor"
2
+ require "npmdc"
3
+
4
+ module Npmdc
5
+ class Cli < Thor
6
+ class_option "verbose", :type => :boolean, :desc => "Enable verbose output mode", :aliases => "-V"
7
+ default_task :check
8
+
9
+ desc "check", "Run check"
10
+ option :path
11
+ def check
12
+ Npmdc::Checker.new(options).call
13
+ end
14
+
15
+ map %w[--version -v] => :__print_version
16
+ desc "--version, -v", "Print gem version"
17
+ def __print_version
18
+ puts Npmdc::VERSION
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,3 @@
1
+ module Npmdc
2
+ VERSION = "0.1.0"
3
+ end
data/npmdc.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'npmdc/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "npmdc"
9
+ spec.version = Npmdc::VERSION
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.authors = ["Emil Kashkevich"]
12
+ spec.email = ["emil.kashkevich@gmail.com"]
13
+ spec.summary = "Check for missed dependencies of NPM packages."
14
+ spec.description = "Check for missed dependencies of NPM packages based on dependency list specified in package.json file."
15
+ spec.homepage = "https://github.com/lysyi3m/npmdc"
16
+ spec.license = "MIT"
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = ["npmdc"]
22
+ spec.require_paths = ["lib"]
23
+ spec.add_dependency "thor"
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: npmdc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Emil Kashkevich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Check for missed dependencies of NPM packages based on dependency list
70
+ specified in package.json file.
71
+ email:
72
+ - emil.kashkevich@gmail.com
73
+ executables:
74
+ - npmdc
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/npmdc
88
+ - bin/setup
89
+ - lib/npmdc.rb
90
+ - lib/npmdc/checker.rb
91
+ - lib/npmdc/cli.rb
92
+ - lib/npmdc/helpers.rb
93
+ - lib/npmdc/railtie.rb
94
+ - lib/npmdc/version.rb
95
+ - npmdc.gemspec
96
+ homepage: https://github.com/lysyi3m/npmdc
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Check for missed dependencies of NPM packages.
120
+ test_files: []