knitter 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/knitter.gemspec +41 -0
- data/lib/knitter.rb +8 -0
- data/lib/knitter/package.rb +81 -0
- data/lib/knitter/package_version.rb +17 -0
- data/lib/knitter/process.rb +54 -0
- data/lib/knitter/version.rb +3 -0
- data/lib/yarn/wrapper.rb +7 -0
- data/lib/yarn/wrapper/version.rb +5 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75dbb5ccb2ef2db2a68c18dd89b63592623bb057
|
4
|
+
data.tar.gz: '0846c7cf3588e9bb3afb4025996973b338c7dd16'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7e806fedd8b284594430ca89147cbe20a250860d39391da0c2be4cdfb2f7dddd74b86e290aa7fa722ecdd796c0ae2324fd1a900c21cbe121b711064288b8a7d
|
7
|
+
data.tar.gz: '085c70e7d0d854dc9718127647de6bd4b39d04c7479be026b7169d429bb33ea29eb36e086205c9be4293a853826270612c505549649ed3270c7f6193e82be230'
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Nathan Stitt
|
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,49 @@
|
|
1
|
+
# Knitter
|
2
|
+
|
3
|
+
A lightweight Ruby Gem wrapper around the node package manager. Allows checking installation status of and installing packages.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'knitter'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install knitter
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'knitter'
|
25
|
+
|
26
|
+
process = NPMWrapper::Process.new('my-npm-project-directory')
|
27
|
+
|
28
|
+
# create a bare-bones 'package.json' file
|
29
|
+
process.init
|
30
|
+
|
31
|
+
# test with the infamous left-pad. Process is optional, it will default to Dir.pwd
|
32
|
+
package = NPMWrapper::Package.new('left-pad', process: process)
|
33
|
+
|
34
|
+
package.installed? # false
|
35
|
+
|
36
|
+
package.install
|
37
|
+
|
38
|
+
package.installed? # true
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nathanstitt/npm-wrapper.
|
45
|
+
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "npm/wrapper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/knitter.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'knitter/version'
|
5
|
+
|
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"]
|
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"
|
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
|
25
|
+
|
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"]
|
32
|
+
|
33
|
+
spec.add_dependency 'mixlib-shellout', '~> 2.2'
|
34
|
+
|
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"
|
40
|
+
|
41
|
+
end
|
data/lib/knitter.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative 'package_version'
|
3
|
+
|
4
|
+
module Knitter
|
5
|
+
class Package
|
6
|
+
PackageConfig = Struct.new(:area, :version)
|
7
|
+
|
8
|
+
attr_reader :name, :dependency_type
|
9
|
+
|
10
|
+
attr_writer :process
|
11
|
+
|
12
|
+
def initialize(name, process: nil)
|
13
|
+
@name = name
|
14
|
+
@process = process
|
15
|
+
end
|
16
|
+
|
17
|
+
def version
|
18
|
+
@version ||= PackageVersion.new(config.version)
|
19
|
+
end
|
20
|
+
|
21
|
+
def version=(ver)
|
22
|
+
@version = PackageVersion.new(ver)
|
23
|
+
end
|
24
|
+
|
25
|
+
def dependency_type=(type)
|
26
|
+
@dependency_type = type
|
27
|
+
end
|
28
|
+
|
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
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def installed?
|
42
|
+
!config.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def add
|
46
|
+
process.add(self)
|
47
|
+
@config = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def config
|
51
|
+
@config ||= read_config
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid?
|
55
|
+
process.package_file.exist? && config
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def parse_package_file
|
61
|
+
JSON.parse(process.package_file.read)
|
62
|
+
end
|
63
|
+
|
64
|
+
def process
|
65
|
+
@process ||= Process.new(Dir.pwd)
|
66
|
+
end
|
67
|
+
|
68
|
+
def read_config
|
69
|
+
config = PackageConfig.new
|
70
|
+
package = parse_package_file
|
71
|
+
%w{dependencies devDependencies optionalDependencies}.each do | part_name |
|
72
|
+
part = package[part_name]
|
73
|
+
next unless part && (version = part[@name])
|
74
|
+
config.area = part_name
|
75
|
+
config.version = version
|
76
|
+
end
|
77
|
+
config
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'mixlib/shellout'
|
2
|
+
|
3
|
+
module Knitter
|
4
|
+
class Process
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :@sh, :stderr, :stdout
|
7
|
+
|
8
|
+
attr_reader :directory
|
9
|
+
|
10
|
+
def initialize(directory)
|
11
|
+
@directory = Pathname.new(directory)
|
12
|
+
end
|
13
|
+
|
14
|
+
def init
|
15
|
+
execute('init', '--yes')
|
16
|
+
end
|
17
|
+
|
18
|
+
def ok?
|
19
|
+
@sh && @sh.status.exitstatus == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(package)
|
23
|
+
name = package.name
|
24
|
+
unless package.version.latest?
|
25
|
+
name << '@' << package.version.to_s
|
26
|
+
end
|
27
|
+
execute(
|
28
|
+
*['add', name, package_save_as_flag(package)].compact
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def package_file
|
33
|
+
@directory.join "package.json"
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def package_save_as_flag(package)
|
39
|
+
case package.dependency_type
|
40
|
+
when :peer then '--peer'
|
41
|
+
when :optional then '--optional'
|
42
|
+
when :development then '--dev'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def execute(cmd, *args)
|
47
|
+
@sh = Mixlib::ShellOut.new(
|
48
|
+
"yarn", cmd, *args,
|
49
|
+
cwd: @directory.to_s
|
50
|
+
)
|
51
|
+
@sh.run_command
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/yarn/wrapper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knitter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Stitt
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mixlib-shellout
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
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: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: spy
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.4.5
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.4.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.3'
|
97
|
+
description: Wraps the Javascript "yarn" command; query and install Javascript packages
|
98
|
+
from Ruby. Reads the package.json file directly to detect packages that are installed,
|
99
|
+
and shells out to `yarn` to initialize and install packages.
|
100
|
+
email:
|
101
|
+
- nathan@stitt.org
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- Gemfile
|
108
|
+
- Guardfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- knitter.gemspec
|
115
|
+
- lib/knitter.rb
|
116
|
+
- lib/knitter/package.rb
|
117
|
+
- lib/knitter/package_version.rb
|
118
|
+
- lib/knitter/process.rb
|
119
|
+
- lib/knitter/version.rb
|
120
|
+
- lib/yarn/wrapper.rb
|
121
|
+
- lib/yarn/wrapper/version.rb
|
122
|
+
homepage: https://github.com/nathanstitt/knitter
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata:
|
126
|
+
allowed_push_host: https://rubygems.org
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.5.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Wraps the Javascript "yarn" package manager command
|
147
|
+
test_files: []
|