browserify_rb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/browserify_rb.gemspec +1 -1
- data/lib/browserify_rb.rb +10 -10
- data/lib/browserify_rb/nvm.rb +14 -6
- data/lib/browserify_rb/popen3.rb +34 -38
- data/lib/browserify_rb/version.rb +1 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 658dbed00139171d4a384b5b3ff5353dd4dd75a0
|
4
|
+
data.tar.gz: 222af08171c17b78d0820e9f69e8f1b983e21a38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80f4f97a884698b82ede735bb9429ad724f3a9087b868a99827068b840d63d798981be50c14ff770a874b400fa0a84466ee985106b9bcf97f2908f694482634f
|
7
|
+
data.tar.gz: 9686b3dad5db385021f2ca912a67250b262b9d1b5e23d3cb43b2912e1fcd9d52596ee6ee133e7903930256d5491eedc4c5b989e109ad75604c392decf15db865
|
data/browserify_rb.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
18
|
# delete this section to allow pushing this gem to any host.
|
19
19
|
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = "
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
21
|
else
|
22
22
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
23
|
end
|
data/lib/browserify_rb.rb
CHANGED
@@ -2,31 +2,34 @@ require "browserify_rb/version"
|
|
2
2
|
require "browserify_rb/nvm"
|
3
3
|
|
4
4
|
require "stringio"
|
5
|
+
require "logger"
|
5
6
|
|
6
7
|
class BrowserifyRb
|
7
8
|
DEFAULT_NVM_DIR = "#{ENV["HOME"]}/.nvm"
|
9
|
+
LOG = Logger.new(STDERR)
|
10
|
+
LOG.level = Logger::Severity.const_get(ENV["LOG"] || "INFO")
|
8
11
|
|
9
12
|
def initialize(
|
10
13
|
browserify_opts: "", node_ver: "stable", env: {},
|
11
|
-
nvm_dir: DEFAULT_NVM_DIR, suppress_stderr: false
|
14
|
+
nvm_dir: DEFAULT_NVM_DIR, suppress_stderr: false,
|
15
|
+
required_modules: nil)
|
12
16
|
@nvm = BrowserifyRb::Nvm.new nvm_dir
|
13
17
|
@node_ver = node_ver
|
14
18
|
@env = env
|
15
19
|
@browserify_opts = browserify_opts
|
16
20
|
@suppress_stderr = suppress_stderr
|
17
21
|
@prepared = false
|
22
|
+
@modules = required_modules
|
18
23
|
end
|
19
24
|
|
20
25
|
def prepare
|
21
|
-
|
22
|
-
|
23
|
-
npm install -g browserify >&2
|
24
|
-
fi
|
25
|
-
CMD
|
26
|
+
ms = ["browserify", *@modules].map{|m| %Q!"#{m}"! }.join(" ")
|
27
|
+
cmd = "npm install #{ms}"
|
26
28
|
stdout_handler = proc {|d| }
|
27
29
|
stderr_handler = @suppress_stderr ?
|
28
30
|
proc {|d| } :
|
29
31
|
proc {|d| STDERR.print d}
|
32
|
+
LOG.debug "run: #{cmd}"
|
30
33
|
status = @nvm.run(
|
31
34
|
cmd,
|
32
35
|
node_ver: @node_ver,
|
@@ -43,10 +46,7 @@ class BrowserifyRb
|
|
43
46
|
|
44
47
|
out_buf = StringIO.new
|
45
48
|
cmd = <<-CMD
|
46
|
-
|
47
|
-
npm install -g browserify >&2
|
48
|
-
fi
|
49
|
-
browserify #{@browserify_opts} -- -
|
49
|
+
node_modules/.bin/browserify #{@browserify_opts} -- -
|
50
50
|
CMD
|
51
51
|
stdout_handler = proc {|d| out_buf << d }
|
52
52
|
stderr_handler = @suppress_stderr ?
|
data/lib/browserify_rb/nvm.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require "browserify_rb/popen3"
|
2
|
+
|
2
3
|
require "stringio"
|
4
|
+
require "logger"
|
3
5
|
|
4
6
|
class BrowserifyRb
|
5
7
|
class Nvm
|
8
|
+
LOG = Logger.new(STDERR)
|
9
|
+
LOG.level = Logger::Severity.const_get(ENV["LOG"] || "INFO")
|
10
|
+
|
6
11
|
NVM_SH = File.join(__dir__, "nvm.sh")
|
7
12
|
|
8
13
|
def initialize nvm_dir = "#{ENV["HOME"]}/.nvm"
|
@@ -22,8 +27,8 @@ class BrowserifyRb
|
|
22
27
|
env: {})
|
23
28
|
new_env = (env).merge(self.env)
|
24
29
|
cmd = <<-CMD
|
25
|
-
|
26
|
-
printf "Abort
|
30
|
+
. "#{NVM_SH}" || {
|
31
|
+
printf "Abort\\n" >&2
|
27
32
|
exit 1
|
28
33
|
}
|
29
34
|
if ! nvm use "#{node_ver}" >&2; then
|
@@ -33,8 +38,10 @@ class BrowserifyRb
|
|
33
38
|
#{cmd}
|
34
39
|
CMD
|
35
40
|
|
41
|
+
LOG.debug "run: #{cmd}"
|
36
42
|
BrowserifyRb::Popen3.async_exec(
|
37
|
-
|
43
|
+
cmd,
|
44
|
+
input: stdin, env: new_env,
|
38
45
|
stdout_handler: stdout_handler,
|
39
46
|
stderr_handler: stderr_handler
|
40
47
|
)
|
@@ -44,15 +51,16 @@ class BrowserifyRb
|
|
44
51
|
out = StringIO.new
|
45
52
|
err = StringIO.new
|
46
53
|
cmd = <<-CMD
|
47
|
-
|
48
|
-
printf "Abort
|
54
|
+
. "#{NVM_SH}" || {
|
55
|
+
printf "Abort\\n" >&2
|
49
56
|
exit 1
|
50
57
|
}
|
51
58
|
nvm --version
|
52
59
|
CMD
|
53
60
|
|
61
|
+
LOG.debug "run: #{cmd}"
|
54
62
|
st = BrowserifyRb::Popen3.async_exec(
|
55
|
-
cmd
|
63
|
+
cmd,
|
56
64
|
stdout_handler: proc {|d| out << d },
|
57
65
|
stderr_handler: proc {|d| err << d }
|
58
66
|
).value
|
data/lib/browserify_rb/popen3.rb
CHANGED
@@ -5,30 +5,34 @@ require "logger"
|
|
5
5
|
class BrowserifyRb
|
6
6
|
module Popen3
|
7
7
|
LOG = Logger.new(STDERR)
|
8
|
+
LOG.level = Logger::Severity.const_get(ENV["LOG"] || "INFO")
|
8
9
|
|
9
10
|
CHUNK_SIZE = 2000
|
10
|
-
DEFAULT_STDOUT_HANDLER = proc {|data| STDOUT.
|
11
|
-
DEFAULT_STDERR_HANDLER = proc {|data| STDERR.
|
11
|
+
DEFAULT_STDOUT_HANDLER = proc {|data| STDOUT.write data }
|
12
|
+
DEFAULT_STDERR_HANDLER = proc {|data| STDERR.write data }
|
12
13
|
|
13
14
|
def self.async_exec(
|
15
|
+
cmd,
|
14
16
|
input: "",
|
15
17
|
env: {},
|
16
|
-
cmd: nil,
|
17
18
|
stdout_handler: DEFAULT_STDOUT_HANDLER,
|
18
19
|
stderr_handler: DEFAULT_STDERR_HANDLER,
|
19
20
|
spawn_opts: {},
|
20
21
|
chunk_size: CHUNK_SIZE)
|
21
|
-
|
22
|
-
raise ArgumentError, "'cmd' require" if cmd.nil?
|
23
|
-
|
24
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3 env, cmd, spawn_opts
|
25
|
-
|
26
|
-
in_buf = StringIO.new input
|
27
|
-
opened_ins = [stdin]
|
28
|
-
opened_outs = [stdout, stderr]
|
29
|
-
|
30
22
|
Thread.fork do
|
31
23
|
begin
|
24
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3 env, cmd, spawn_opts
|
25
|
+
|
26
|
+
input = input.is_a?(String) ?
|
27
|
+
StringIO.new(input) :
|
28
|
+
iput
|
29
|
+
input_buff = ""
|
30
|
+
opened_ins = [stdin]
|
31
|
+
opened_outs = [stdout, stderr]
|
32
|
+
handlers = {
|
33
|
+
stdout => stdout_handler,
|
34
|
+
stderr => stderr_handler
|
35
|
+
}
|
32
36
|
while not opened_outs.empty?
|
33
37
|
ios = IO.select opened_outs, opened_ins, nil, 1
|
34
38
|
if ios.nil? and Process.waitpid(wait_thr.pid, Process::WNOHANG)
|
@@ -37,47 +41,39 @@ class BrowserifyRb
|
|
37
41
|
|
38
42
|
outs, ins, = ios
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
if outs.include? stderr
|
51
|
-
begin
|
52
|
-
d = stderr.readpartial CHUNK_SIZE
|
53
|
-
stderr_handler.yield d
|
54
|
-
rescue EOFError
|
55
|
-
opened_outs.delete stderr
|
44
|
+
if not outs.nil?
|
45
|
+
outs.each do |out|
|
46
|
+
if out.eof?
|
47
|
+
out.close
|
48
|
+
opened_outs.delete out
|
49
|
+
else
|
50
|
+
d = out.readpartial chunk_size
|
51
|
+
handlers[out].call d
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
59
55
|
|
60
56
|
if not ins.nil? and ins.include? stdin
|
61
|
-
|
62
|
-
in_buf.readpartial CHUNK_SIZE
|
63
|
-
rescue EOFError
|
64
|
-
nil
|
65
|
-
end
|
66
|
-
if i.nil?
|
57
|
+
if input.eof?
|
67
58
|
stdin.close
|
68
59
|
opened_ins.delete stdin
|
60
|
+
elsif input_buff.empty?
|
61
|
+
d = input.readpartial(chunk_size)
|
62
|
+
bytes = stdin.write_nonblock(d)
|
63
|
+
input_buff = d[bytes .. -1]
|
69
64
|
else
|
70
|
-
bytes = stdin.write_nonblock(
|
71
|
-
|
65
|
+
bytes = stdin.write_nonblock(input_buff)
|
66
|
+
input_buff = input_buff[bytes .. -1]
|
72
67
|
end
|
73
68
|
end
|
74
69
|
end
|
70
|
+
|
71
|
+
wait_thr.value
|
75
72
|
rescue => e
|
76
73
|
LOG.error e
|
74
|
+
nil
|
77
75
|
end
|
78
76
|
end
|
79
|
-
|
80
|
-
wait_thr
|
81
77
|
end
|
82
78
|
end
|
83
79
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browserify_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keiichiro Ui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.11'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '5.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
55
|
description: browserify wrapper with nvm to install node automatically
|
@@ -59,8 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
@@ -77,24 +77,24 @@ homepage: https://github.com/kui/browserify_rb
|
|
77
77
|
licenses:
|
78
78
|
- MIT
|
79
79
|
metadata:
|
80
|
-
allowed_push_host:
|
80
|
+
allowed_push_host: https://rubygems.org
|
81
81
|
post_install_message:
|
82
82
|
rdoc_options: []
|
83
83
|
require_paths:
|
84
84
|
- lib
|
85
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.4.5.1
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: browserify wrapper
|