yarnlock 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e4f27bb2b5894c02b680ce6a0e635a64fef7e02
4
- data.tar.gz: 12d9253c4e405b2aafb986ab81a4ca4c644226bd
3
+ metadata.gz: 971a86fd881953dd44f8cb81309d879707e29471
4
+ data.tar.gz: 2d91494c6c74878999cf1b54e18fc85b3f4fdaa1
5
5
  SHA512:
6
- metadata.gz: 3a1b256d1a2b06cb267ace56ac4c85bb3172d2b53b3132272af74731b1dfc47e89c19f4b0ef772982cf5f52b5fe20c32a6fc2623b0a3a3bd49d80e876e2a73e8
7
- data.tar.gz: 4c1da8bd2f5160073c345c5e1c561edddd04254a35afe557ccd48f3e28209899eed4fdecbe02245db14776adf17da99fe494f4582d4b3c6b2020c162f878e858
6
+ metadata.gz: 8b10a8e7554b0fa385cee918333209e6c0f1c80fadfd08ef3a82e76aec10edb9d1f41e3f9302cbb72ec81989020bca12bb37317e1dd9d2626d98e012fea313cc
7
+ data.tar.gz: e0787a52a5b613d2cefe12299811eda7d17e0330d949f86e055f8cad9f9997ae0d978e844774a2da5c945fa9eb6316860fc1cf65583259f6296816b49c730362
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Ruby-Yarnlock
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/yarnlock.svg)](https://badge.fury.io/rb/yarnlock)
4
- [![Build Status](https://travis-ci.org/hiromi2424/ruby-yarnlock.svg?branch=master)](https://travis-ci.org/sinsoku/bundler_diffgems)
4
+ [![Build Status](https://travis-ci.org/hiromi2424/ruby-yarnlock.svg?branch=master)](https://travis-ci.org/hiromi2424/ruby-yarnlock)
5
5
 
6
6
  Thin wrapper of [@yarnpkg/lockfile](https://yarnpkg.com/ja/package/@yarnpkg/lockfile) for Ruby.
7
7
 
@@ -44,6 +44,15 @@ Yarnlock.load 'yarn.lock'
44
44
  Yarnlock.stringify parsed_hash
45
45
  ```
46
46
 
47
+ You can configure paths for Node.js(`'node'` by default) and JS scripts dir(`'{package root}/scripts'` by default).
48
+
49
+ ```ruby
50
+ Yarnlock.configure do |config|
51
+ config.script_dir = '/path/to/my/dir'
52
+ config.node_path = '/usr/local/bin/node'
53
+ end
54
+ ```
55
+
47
56
  ## Development
48
57
 
49
58
  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.
data/lib/yarnlock.rb CHANGED
@@ -1,11 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yarnlock/version'
4
+
5
+ require 'yarnlock/config'
6
+ require 'yarnlock/js_executor'
7
+
4
8
  require 'json'
5
9
 
6
10
  module Yarnlock
11
+ def self.config
12
+ @config ||= Config.new
13
+ end
14
+
15
+ def self.configure
16
+ yield config
17
+ end
18
+
7
19
  def self.parse(yarnlock)
8
- json_string = execute_script 'parse', yarnlock
20
+ json_string = JsExecutor.execute 'parse', yarnlock
9
21
  parsed = JSON.parse json_string
10
22
  raise "An error was occurred when parsing yarn.lock: #{parsed}" unless parsed.is_a? Hash
11
23
  raise "Could not parse yarn.lock: #{parsed['reason']}" unless parsed['type'] == 'success'
@@ -13,7 +25,7 @@ module Yarnlock
13
25
  end
14
26
 
15
27
  def self.stringify(object)
16
- json_string = execute_script 'stringify', JSON.generate(object)
28
+ json_string = JsExecutor.execute 'stringify', JSON.generate(object)
17
29
  parsed = JSON.parse json_string
18
30
  raise "An error was occurred when stringing object: #{parsed}" unless parsed.is_a? Hash
19
31
  raise "Could not stringing object: #{parsed['reason']}" unless parsed['type'] == 'success'
@@ -23,19 +35,4 @@ module Yarnlock
23
35
  def self.load(file)
24
36
  parse File.read(file)
25
37
  end
26
-
27
- def self.execute_script(script, stdin)
28
- IO.popen("node #{script_dir}/#{script}", 'r+') do |io|
29
- io.puts stdin
30
- io.close_write
31
- io.gets
32
- end
33
- end
34
-
35
- def self.script_dir
36
- return @script_dir unless @script_dir.nil?
37
- @script_dir = File.join File.dirname(__dir__), '/scripts'
38
- end
39
-
40
- private_class_method :execute_script, :script_dir
41
38
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yarnlock
4
+ class Config
5
+ attr_accessor :script_dir, :node_path
6
+
7
+ def initialize
8
+ @script_dir = File.expand_path '../../scripts', __dir__
9
+ @node_path = 'node'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yarnlock
4
+ module JsExecutor
5
+ def self.execute(script, stdin)
6
+ IO.popen(script_path(script), 'r+') do |io|
7
+ io.puts stdin
8
+ io.close_write
9
+ io.gets
10
+ end
11
+ end
12
+
13
+ def self.script_path(script)
14
+ "#{Yarnlock.config.node_path} #{Yarnlock.config.script_dir}/#{script}"
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yarnlock
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/yarnlock.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'yarnlock/version'
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yarnlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Shimizu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-04 00:00:00.000000000 Z
11
+ date: 2018-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,8 @@ files:
87
87
  - bin/console
88
88
  - bin/setup
89
89
  - lib/yarnlock.rb
90
+ - lib/yarnlock/config.rb
91
+ - lib/yarnlock/js_executor.rb
90
92
  - lib/yarnlock/version.rb
91
93
  - package.json
92
94
  - scripts/parse.js