browserify_rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dd70243ad4d62334ac69f8efcdc690931ddccf9
4
+ data.tar.gz: 15b681ba96ed567e57c30e77d3751b5e950aff27
5
+ SHA512:
6
+ metadata.gz: edfd3ceeb8418deb65fe42e0cfce5204f5f50d9f841473c098dc59016842a29be28ad54142c3e39e7e3d382fcfdcff911605b10a0ef70216433b8ba7e16a03c4
7
+ data.tar.gz: 12ac708441a7be2315f0cea06a06399d41ccd916e7a6365ad2c78801deb52fb2e1351e156f339502e989eb8f59d3667cba1ddda428019ddd6b29747347c5ab0f
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/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in browserify_rb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Keiichiro Ui
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,48 @@
1
+ # BrowserifyRb
2
+
3
+ browserify wrapper with nvm to install node automatically.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'browserify_rb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install browserify_rb
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "browserify_rb"
25
+
26
+ br = BrowserifyRb.new
27
+ puts br.compile("console.log('foo');")
28
+
29
+ puts BrowserifyRb.compile("console.log('bar');")
30
+ ```
31
+
32
+ `node` nor `nvm` are not required.
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kui/browserify_rb.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "browserify_rb"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'browserify_rb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "browserify_rb"
8
+ spec.version = BrowserifyRb::VERSION
9
+ spec.authors = ["Keiichiro Ui"]
10
+ spec.email = ["keiichiro.ui@gmail.com"]
11
+
12
+ spec.summary = %q{browserify wrapper}
13
+ spec.description = %q{browserify wrapper with nvm to install node automatically}
14
+ spec.homepage = "https://github.com/kui/browserify_rb"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ end
@@ -0,0 +1,64 @@
1
+ require "browserify_rb/popen3"
2
+ require "stringio"
3
+
4
+ class BrowserifyRb
5
+ class Nvm
6
+ NVM_SH = File.join(__dir__, "nvm.sh")
7
+
8
+ def initialize nvm_dir = "#{ENV["HOME"]}/.nvm"
9
+ @nvm_dir = nvm_dir
10
+ end
11
+
12
+ def env
13
+ { "NVM_DIR" => @nvm_dir }
14
+ end
15
+
16
+ def run(
17
+ cmd,
18
+ stdin: "",
19
+ stdout_handler: proc{|d| STDOUT.print d },
20
+ stderr_handler: proc{|d| STDERR.print d },
21
+ node_ver: "stable",
22
+ env: {})
23
+ new_env = (env).merge(self.env)
24
+ cmd = <<-CMD
25
+ source "#{NVM_SH}" || {
26
+ printf "Abort\n" >&2
27
+ exit 1
28
+ }
29
+ if ! nvm use "#{node_ver}" >&2; then
30
+ nvm install "#{node_ver}" >&2
31
+ nvm use "#{node_ver}" >&2
32
+ fi
33
+ #{cmd}
34
+ CMD
35
+
36
+ BrowserifyRb::Popen3.async_exec(
37
+ input: stdin, env: new_env, cmd: cmd,
38
+ stdout_handler: stdout_handler,
39
+ stderr_handler: stderr_handler
40
+ )
41
+ end
42
+
43
+ def self.version
44
+ out = StringIO.new
45
+ err = StringIO.new
46
+ cmd = <<-CMD
47
+ source "#{NVM_SH}" || {
48
+ printf "Abort\n" >&2
49
+ exit 1
50
+ }
51
+ nvm --version
52
+ CMD
53
+
54
+ st = BrowserifyRb::Popen3.async_exec(
55
+ cmd: cmd,
56
+ stdout_handler: proc {|d| out << d },
57
+ stderr_handler: proc {|d| err << d }
58
+ ).value
59
+ raise "non-zero exit status: #{status.to_i}\n#{err}" unless st.success?
60
+
61
+ out.string.strip
62
+ end
63
+ end
64
+ end