browserify_ruby 0.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 +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +106 -0
- data/Rakefile +2 -0
- data/bin/bify +77 -0
- data/browserify_ruby.gemspec +34 -0
- data/lib/browserify_ruby.rb +110 -0
- data/lib/browserify_ruby/version.rb +3 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a8b25a9e650db37fa60d53564c91580dbbd7656a
|
4
|
+
data.tar.gz: 3e8170ece5ba59007340adbab4ba5995201cf393
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e8f3b50e60d5935e9f6d4a859278b78fb7fea1286ea9a6311271dbdef528ea159a8ddb0a5909ec6ee976de9bff92fd99029d7ef5f95f827345e82f12127c39e
|
7
|
+
data.tar.gz: 6682368459fddf0d9a5f5bb21304bcb1602700b14c0efbecc048451966d89e877dee36cd46be9e7a4983e97ac2dbadac737716b35135078ad8826dffb3b44c73
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Antiokus314
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# browserify_ruby
|
2
|
+
[Browserify](https://www.npmjs.com/package/browserify) + [Watchify](https://www.npmjs.com/package/watchify) wrapped in a ruby gem!
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
####node
|
6
|
+
$ npm install -g browserify
|
7
|
+
|
8
|
+
$ npm install -g watchify
|
9
|
+
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
####ruby
|
13
|
+
$ gem 'browserify_ruby', group: :development
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install browserify_ruby
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
You must have browserify and watchify installed globally for this to work.
|
25
|
+
|
26
|
+
For starters, after you've bundled the gem execute
|
27
|
+
|
28
|
+
$ bify init
|
29
|
+
|
30
|
+
This will create (from the root directory of your app)
|
31
|
+
|
32
|
+
* .browserify_ruby.json (config file)
|
33
|
+
* app/browserify (default source location)
|
34
|
+
* app/assets/javascripts/bundles (default bundle location -- Rails happiness)
|
35
|
+
|
36
|
+
Open up the config file (.browserify_ruby.json)
|
37
|
+
|
38
|
+
### .browserify_ruby.json
|
39
|
+
- "source_directory"
|
40
|
+
|
41
|
+
- The source directory of all your browserifying madness.
|
42
|
+
- `default: app/browserify`
|
43
|
+
|
44
|
+
- "bundle_directory"
|
45
|
+
|
46
|
+
- The bundle destination after all of the browserifying/watchifying.
|
47
|
+
- `default: app/assets/javascripts/bundles`
|
48
|
+
|
49
|
+
- "manifest"
|
50
|
+
|
51
|
+
- An array of objects containing 3 properties
|
52
|
+
|
53
|
+
- "name":
|
54
|
+
- source_alias_name,
|
55
|
+
- "source":
|
56
|
+
- entry point where you want to browserify. Searches from the `source_directory`
|
57
|
+
- "bundle":
|
58
|
+
- the bundle file name you want. Will output in `bundle_directory`
|
59
|
+
|
60
|
+
##CLI
|
61
|
+
|
62
|
+
#### bify (i.e. browserify)
|
63
|
+
|
64
|
+
$ bify init:
|
65
|
+
=> Creates a default scaffold. Run this first before executing
|
66
|
+
=> the other commands. See Usage above fore more details
|
67
|
+
|
68
|
+
$ bify start [NAMES]:
|
69
|
+
=> Runs browserify on all of the manifests indicated
|
70
|
+
=> in the manifest array of the .browserify_ruby.json file.
|
71
|
+
=> Takes optional list of names to browserify:
|
72
|
+
=> e.g. bify start name1 name2
|
73
|
+
|
74
|
+
$ bify watch [NAMES]:
|
75
|
+
=> Runs watchify on all of the manifests indicated
|
76
|
+
=> in the manifest array of the .browserify_ruby.json file.
|
77
|
+
=> Takes optional list of names to watchify:
|
78
|
+
=> e.g. bify watch name1 name2
|
79
|
+
|
80
|
+
$ bify clean:
|
81
|
+
=> Cleans out what ever bundles you have in the "bundle_directory"
|
82
|
+
|
83
|
+
$ bify list:
|
84
|
+
=> Lists all bundles in the "bundle_directory"
|
85
|
+
|
86
|
+
$ bify purge
|
87
|
+
=> Not a fan of browserify_ruby?
|
88
|
+
=> That's ok! This command will remove everything specified
|
89
|
+
=> in the .browserify_ruby.json file and removes the file too
|
90
|
+
|
91
|
+
## FAQ
|
92
|
+
|
93
|
+
1. Why wrap npm modules in a ruby gem?
|
94
|
+
> Because :) Well actually, I find it easier to write threads in ruby than in node.
|
95
|
+
> Once I figure that out, expect an npm module shortly after :)
|
96
|
+
|
97
|
+
2. Is it necessary?
|
98
|
+
> Nope but trust me, you're in for a sweet ride.
|
99
|
+
|
100
|
+
3. WHAT ABOUT TESTS?
|
101
|
+
> Uh...Not yet. To be honest, I'm not exactly sure how to implement tests with this kind of program
|
102
|
+
> Definitely open to suggestions though - and as always - pull requests.
|
103
|
+
|
104
|
+
## TODO
|
105
|
+
|
106
|
+
1. Write TESTS
|
data/Rakefile
ADDED
data/bin/bify
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'browserify_ruby'
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
class BrowserifyRubyRunner < Thor
|
6
|
+
desc 'init', 'Creates default installation directories and config file'
|
7
|
+
def init
|
8
|
+
begin
|
9
|
+
BrowserifyRuby.init
|
10
|
+
rescue Exception => e
|
11
|
+
puts 'Something bad happened! Could not initialize files'
|
12
|
+
puts e
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'clean', 'Alias -c or --clean. Cleans out bundles directory'
|
17
|
+
def clean
|
18
|
+
begin
|
19
|
+
BrowserifyRuby.clean_bundles
|
20
|
+
puts 'Bundle directory is clean'
|
21
|
+
rescue Exception => e
|
22
|
+
puts 'Please make sure you have run "bify init" and adjusted the ".browserify_ruby.json" file accordingly'
|
23
|
+
puts e
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'list', 'List all the bundles currently residing in the `bundle_directory`'
|
28
|
+
def list
|
29
|
+
begin
|
30
|
+
BrowserifyRuby.list_bundles
|
31
|
+
rescue Exception => e
|
32
|
+
puts 'Fatal error!'
|
33
|
+
puts e
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'start [NAMES]', 'Run browserify on the sources indicated in ".browserify_ruby.json". Optional - provide list of names: bify start name1 name2'
|
38
|
+
def start(*args)
|
39
|
+
begin
|
40
|
+
if args.empty?
|
41
|
+
BrowserifyRuby.browserify
|
42
|
+
else
|
43
|
+
BrowserifyRuby.match_and_load(:browserify, args)
|
44
|
+
end
|
45
|
+
puts '-- created bundles --'
|
46
|
+
BrowserifyRuby.list_bundles
|
47
|
+
rescue Exception => e
|
48
|
+
puts 'Please make sure you have run "bify init" and adjusted the ".browserify_ruby.json" file accordingly'
|
49
|
+
puts e
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'purge', 'Remove all files/directories created by "bify init"'
|
54
|
+
def purge
|
55
|
+
begin
|
56
|
+
BrowserifyRuby.purge
|
57
|
+
rescue Exception => e
|
58
|
+
puts 'Fatal error!'
|
59
|
+
puts "#{e}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc 'watch [NAMES]', 'Run watchify on the sources indicated in ".browserify_ruby.json". Optional - provide list of names: bify watch name1 name2'
|
64
|
+
def watch(*args)
|
65
|
+
begin
|
66
|
+
if args.empty?
|
67
|
+
BrowserifyRuby.watchify
|
68
|
+
else
|
69
|
+
BrowserifyRuby.match_and_load(:watchify, args)
|
70
|
+
end
|
71
|
+
rescue Exception => e
|
72
|
+
puts e
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
BrowserifyRubyRunner.start
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'browserify_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "browserify_ruby"
|
8
|
+
spec.version = BrowserifyRuby::VERSION
|
9
|
+
spec.authors = ["Antiokus314"]
|
10
|
+
spec.email = ["nrgarg@outlook.com"]
|
11
|
+
spec.summary = %q{A browserify + watchify task runner. Handles bundles from multiple sources. Easily configurable :).}
|
12
|
+
spec.description = %q{With browserify and watchify installed globally, here's simple command line to help you along the way}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.requirements << "node"
|
22
|
+
spec.requirements << "npm"
|
23
|
+
spec.requirements << "browserify"
|
24
|
+
spec.requirements << "watchify"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "pry", "~> 0"
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "json", "~> 1.8.1", '>= 1.8.1'
|
31
|
+
spec.add_runtime_dependency "thor", "~> 0.19.1", "~> 0.19.1"
|
32
|
+
|
33
|
+
spec.post_install_message = "browserify_ruby is ready to go!"
|
34
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "browserify_ruby/version"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module BrowserifyRuby
|
5
|
+
class << self
|
6
|
+
def init
|
7
|
+
config = basic_config
|
8
|
+
FileUtils.mkdir_p config[:source_directory] unless File.exists? config[:source_directory]
|
9
|
+
FileUtils.mkdir_p config[:bundle_directory] unless File.exists? config[:bundle_directory]
|
10
|
+
File.open("#{config[:source_directory]}/hello.js", 'w') do |f|
|
11
|
+
f.puts('var hello = function(string) { return string.toUpperCase(); }')
|
12
|
+
f.puts('module.exports = hello;')
|
13
|
+
end
|
14
|
+
File.open("#{config[:source_directory]}/app.js", 'w') do |f|
|
15
|
+
f.puts('var hello = require("./hello");')
|
16
|
+
f.puts('var app = function() { console.log(hello("now using browserify!")); }')
|
17
|
+
f.puts('module.exports = app();')
|
18
|
+
end
|
19
|
+
File.write('./.browserify_ruby.json', JSON.pretty_generate(config))
|
20
|
+
end
|
21
|
+
|
22
|
+
def purge
|
23
|
+
config = browserify_manifest
|
24
|
+
FileUtils.remove_dir(config["source_directory"]) if File.exists? config["source_directory"]
|
25
|
+
FileUtils.remove_dir(config["bundle_directory"]) if File.exists? config["bundle_directory"]
|
26
|
+
FileUtils.rm("./.browserify_ruby.json") if File.exists? "./.browserify_ruby.json"
|
27
|
+
end
|
28
|
+
|
29
|
+
def browserify(data = browserify_manifest)
|
30
|
+
data["manifest"].each do |manifest|
|
31
|
+
%x(browserify #{data["source_directory"]}/#{manifest["source"]} -o #{data["bundle_directory"]}/#{manifest["bundle"]})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def watchify(data = browserify_manifest)
|
36
|
+
threads = []
|
37
|
+
data["manifest"].each do |manifest|
|
38
|
+
thr = Thread.new do
|
39
|
+
%x(watchify #{data["source_directory"]}/#{manifest["source"]} -o #{data["bundle_directory"]}/#{manifest["bundle"]} -dv)
|
40
|
+
end
|
41
|
+
threads.push(thr)
|
42
|
+
end
|
43
|
+
run_threads(threads)
|
44
|
+
end
|
45
|
+
|
46
|
+
def clean_bundles
|
47
|
+
data = browserify_manifest
|
48
|
+
Dir.glob("#{data["bundle_directory"]}/*.js").each { |f| File.delete(f) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def match_and_load(browserify_or_watchify, names)
|
52
|
+
case browserify_or_watchify
|
53
|
+
when :browserify
|
54
|
+
browserify(match(names))
|
55
|
+
when :watchify
|
56
|
+
watchify(match(names))
|
57
|
+
else
|
58
|
+
puts "Invalid method call: #{browserify_or_watchify}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def browserify_manifest
|
63
|
+
JSON.parse(File.read('.browserify_ruby.json'))
|
64
|
+
end
|
65
|
+
|
66
|
+
def list_bundles
|
67
|
+
config = browserify_manifest
|
68
|
+
bundles = Dir.glob("#{config['bundle_directory']}/**")
|
69
|
+
if bundles.empty?
|
70
|
+
puts 'Bundle directory is empty'
|
71
|
+
else
|
72
|
+
puts bundles
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def run_threads(threads)
|
78
|
+
threads.each do |th|
|
79
|
+
begin
|
80
|
+
th.join
|
81
|
+
rescue Exception => e
|
82
|
+
Thread.kill(th)
|
83
|
+
Thread.exit
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def basic_config
|
89
|
+
{
|
90
|
+
source_directory: "app/browserify",
|
91
|
+
bundle_directory: "app/assets/javascripts/bundles",
|
92
|
+
manifest: [
|
93
|
+
{
|
94
|
+
name: "app",
|
95
|
+
source: "app.js",
|
96
|
+
bundle: "bundle.js"
|
97
|
+
}
|
98
|
+
]
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
def match(names)
|
103
|
+
data = browserify_manifest
|
104
|
+
manifests = names.map { |name| data["manifest"].find { |x| x["name"] == name } }
|
105
|
+
data["manifest"] = manifests
|
106
|
+
data
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: browserify_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Antiokus314
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.1
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.8.1
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.8.1
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.8.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: thor
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.19.1
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.19.1
|
89
|
+
description: With browserify and watchify installed globally, here's simple command
|
90
|
+
line to help you along the way
|
91
|
+
email:
|
92
|
+
- nrgarg@outlook.com
|
93
|
+
executables:
|
94
|
+
- bify
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- ".gitignore"
|
99
|
+
- Gemfile
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- bin/bify
|
104
|
+
- browserify_ruby.gemspec
|
105
|
+
- lib/browserify_ruby.rb
|
106
|
+
- lib/browserify_ruby/version.rb
|
107
|
+
homepage: ''
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message: browserify_ruby is ready to go!
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements:
|
126
|
+
- node
|
127
|
+
- npm
|
128
|
+
- browserify
|
129
|
+
- watchify
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.2.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: A browserify + watchify task runner. Handles bundles from multiple sources.
|
135
|
+
Easily configurable :).
|
136
|
+
test_files: []
|