knitter 0.1 → 0.1.1

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: 75dbb5ccb2ef2db2a68c18dd89b63592623bb057
4
- data.tar.gz: '0846c7cf3588e9bb3afb4025996973b338c7dd16'
3
+ metadata.gz: 19b44d43ac679acb8157cde332e7d2c12a82b81b
4
+ data.tar.gz: b29c2b9b6c35493cf3388df228b98af39efd7166
5
5
  SHA512:
6
- metadata.gz: f7e806fedd8b284594430ca89147cbe20a250860d39391da0c2be4cdfb2f7dddd74b86e290aa7fa722ecdd796c0ae2324fd1a900c21cbe121b711064288b8a7d
7
- data.tar.gz: '085c70e7d0d854dc9718127647de6bd4b39d04c7479be026b7169d429bb33ea29eb36e086205c9be4293a853826270612c505549649ed3270c7f6193e82be230'
6
+ metadata.gz: 40f2a15ec0ac4c87f5f0a593fe7674019cced2d5531eb881ecf1fe81030162d1ac0c7804abbc5b42240330297169e8a2c41e9b6429cc1b6b385f347186517efe
7
+ data.tar.gz: e27568fdb0aefa36cbb2bf23994cdd57216fe90a2a75dc27c4ce6955996087965335095fe33af267b8854af4f23116005c9156de40524b80b029184d523bab39
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ test/fixtures/node_modules/
11
+ test/fixtures/yarn-error.log
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ StringLiterals:
2
+ Enabled: false
3
+
4
+ Style/IndentationWidth:
5
+ # Number of spaces for each indentation level.
6
+ Width: 4
7
+
8
+ Style/EmptyLinesAroundClassBody:
9
+ Enabled: false
10
+
11
+ Style/EmptyLinesAroundModuleBody:
12
+ Enabled: false
13
+
14
+ Style/ClassAndModuleChildren:
15
+ Enabled: false
data/knitter.gemspec CHANGED
@@ -4,38 +4,35 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'knitter/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "knitter"
8
- spec.version = Knitter::VERSION
9
- spec.authors = ["Nathan Stitt"]
10
- spec.email = ["nathan@stitt.org"]
7
+ spec.name = "knitter"
8
+ spec.version = Knitter::VERSION
9
+ spec.authors = ["Nathan Stitt"]
10
+ spec.email = ["nathan@stitt.org"]
11
11
 
12
- spec.summary = %q{Wraps the Javascript "yarn" package manager command}
13
- spec.description = %q{Wraps the Javascript "yarn" command; query and install Javascript packages from Ruby. Reads the package.json file directly to detect packages that are installed, and shells out to `yarn` to initialize and install packages.}
14
- spec.homepage = "https://github.com/nathanstitt/knitter"
15
- spec.license = "MIT"
12
+ spec.summary = %q{Wraps the Javascript "yarn" package manager command}
13
+ spec.description = %q{Wraps the Javascript "yarn" command; query and install Javascript packages from Ruby. Reads the package.json file directly to detect packages that are installed, and shells out to `yarn` to initialize and install packages.}
14
+ spec.homepage = "https://github.com/nathanstitt/knitter"
15
+ spec.license = "MIT"
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
24
- end
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ end
25
22
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
- f.match(%r{^(test|spec|features)/})
28
- end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
32
29
 
33
- spec.add_dependency 'mixlib-shellout', '~> 2.2'
30
+ spec.add_dependency 'mixlib-shellout', '~> 2.2'
34
31
 
35
- spec.add_development_dependency "bundler", "~> 1.13"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_development_dependency "guard", "~> 2.13"
38
- spec.add_development_dependency "spy", "~> 0.4.5"
39
- spec.add_development_dependency "guard-minitest", "~> 2.3"
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "guard", "~> 2.13"
35
+ spec.add_development_dependency "spy", "~> 0.4.5"
36
+ spec.add_development_dependency "guard-minitest", "~> 2.3"
40
37
 
41
38
  end
data/lib/knitter.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require_relative "knitter/version"
2
+ require_relative "knitter/yarn"
2
3
  require_relative "knitter/package"
3
- require_relative "knitter/process"
4
4
 
5
5
  module Knitter
6
6
 
@@ -7,11 +7,11 @@ module Knitter
7
7
 
8
8
  attr_reader :name, :dependency_type
9
9
 
10
- attr_writer :process
10
+ attr_writer :yarn
11
11
 
12
- def initialize(name, process: nil)
12
+ def initialize(name, yarn: nil)
13
13
  @name = name
14
- @process = process
14
+ @yarn = yarn
15
15
  end
16
16
 
17
17
  def version
@@ -27,23 +27,15 @@ module Knitter
27
27
  end
28
28
 
29
29
  def dependency_type
30
- @dependency_type || (
31
- case config.area
32
- when 'optionalDependencies' then :optional
33
- when 'devDependencies' then :development
34
- when 'peerDependencies' then :peer
35
- else
36
- :dependencies
37
- end
38
- )
30
+ @dependency_type ||= Yarn::PACKAGE_AREAS.invert[config.area]
39
31
  end
40
32
 
41
33
  def installed?
42
- !config.nil?
34
+ !config.area.nil?
43
35
  end
44
36
 
45
37
  def add
46
- process.add(self)
38
+ yarn.add(self)
47
39
  @config = nil
48
40
  end
49
41
 
@@ -51,25 +43,17 @@ module Knitter
51
43
  @config ||= read_config
52
44
  end
53
45
 
54
- def valid?
55
- process.package_file.exist? && config
56
- end
57
-
58
46
  protected
59
47
 
60
- def parse_package_file
61
- JSON.parse(process.package_file.read)
62
- end
63
-
64
- def process
65
- @process ||= Process.new(Dir.pwd)
48
+ def yarn
49
+ @yarn ||= Yarn.new(Dir.pwd)
66
50
  end
67
51
 
68
52
  def read_config
69
53
  config = PackageConfig.new
70
- package = parse_package_file
54
+ json = yarn.package_file_contents
71
55
  %w{dependencies devDependencies optionalDependencies}.each do | part_name |
72
- part = package[part_name]
56
+ part = json[part_name]
73
57
  next unless part && (version = part[@name])
74
58
  config.area = part_name
75
59
  config.version = version
@@ -1,3 +1,3 @@
1
1
  module Knitter
2
- VERSION = '0.1'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,8 +1,17 @@
1
1
  require 'mixlib/shellout'
2
+ require 'forwardable'
2
3
 
3
4
  module Knitter
4
- class Process
5
- extend Forwardable
5
+ class Yarn
6
+
7
+ PACKAGE_AREAS = {
8
+ dev: 'devDependencies',
9
+ peer: 'peerDependencies',
10
+ optional: 'optionalDependencies',
11
+ dependencies: 'dependencies'
12
+ }
13
+
14
+ extend ::Forwardable
6
15
  def_delegators :@sh, :stderr, :stdout
7
16
 
8
17
  attr_reader :directory
@@ -33,6 +42,28 @@ module Knitter
33
42
  @directory.join "package.json"
34
43
  end
35
44
 
45
+ def packages
46
+ json = package_file_contents
47
+ Enumerator.new do | enum |
48
+ PACKAGE_AREAS.each do | type, area |
49
+ (json[area] || []).each do | package, version |
50
+ package = Package.new(package, yarn: self)
51
+ package.version = version
52
+ package.dependency_type = type
53
+ enum << package
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def package_file_contents
60
+ JSON.parse(package_file.read)
61
+ end
62
+
63
+ def valid?
64
+ package_file_contents
65
+ end
66
+
36
67
  protected
37
68
 
38
69
  def package_save_as_flag(package)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knitter
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Stitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -104,6 +104,7 @@ extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
106
  - ".gitignore"
107
+ - ".rubocop.yml"
107
108
  - Gemfile
108
109
  - Guardfile
109
110
  - LICENSE.txt
@@ -115,8 +116,8 @@ files:
115
116
  - lib/knitter.rb
116
117
  - lib/knitter/package.rb
117
118
  - lib/knitter/package_version.rb
118
- - lib/knitter/process.rb
119
119
  - lib/knitter/version.rb
120
+ - lib/knitter/yarn.rb
120
121
  - lib/yarn/wrapper.rb
121
122
  - lib/yarn/wrapper/version.rb
122
123
  homepage: https://github.com/nathanstitt/knitter