bowerinstaller 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/bowerinstaller.gemspec +23 -0
- data/lib/bowerinstaller.rb +92 -0
- data/lib/bowerinstaller/dsl.rb +53 -0
- data/lib/bowerinstaller/railtie.rb +17 -0
- data/lib/bowerinstaller/version.rb +3 -0
- data/lib/tasks/bowerinstaller.rake +19 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fd56802130b32ca9054317368df9ad420b81d20b
|
4
|
+
data.tar.gz: ee9bae0d7c83d5256d7d1dab1c2e62ec5e9bfc1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a61ae26f89608852881662e62d1bae6a89c2ce33ea1601fbf03b98dcaee247cec5f9f893994d3f8e097bc184b287a3be0b98155ff19b7df2b28883d9832d33b1
|
7
|
+
data.tar.gz: 8950e0ce0479ae9a42f38834db62e682db9e4a1a70d92252f41844eb4bea503dca16ec412bbb5673d3880f6a63f75010172b1b8c17b959e1cbbbfecebbedf0e7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Gary Lin
|
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,50 @@
|
|
1
|
+
# Bowerinstaller
|
2
|
+
|
3
|
+
rake task to install bower packages to rails. This project is inspired by
|
4
|
+
bower, bower-installer, and bower-rails. The rake task uses bower to
|
5
|
+
manage the package dependencies and download the required bower packages.
|
6
|
+
Then it follows the mechanism similar to bower-installer to install js/css
|
7
|
+
to the proper location. Once that is done, it will then generate a
|
8
|
+
component.js and component.css file to require all the installed js/css file.
|
9
|
+
component.js/css can then be included by application.js/css.
|
10
|
+
|
11
|
+
## Requirement
|
12
|
+
|
13
|
+
* [node](http://nodejs.org) ([on github](https://github.com/joyent/node))
|
14
|
+
* [bower](https://github.com/twitter/bow) installed with npm
|
15
|
+
|
16
|
+
## Install
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'bowerinstaller'
|
20
|
+
|
21
|
+
## bower.rb
|
22
|
+
Instead of using bower.json, bowerinstaller uses a DSL approach, similar to
|
23
|
+
Gemfile. bower.rb must be created in your Rails application's root directory.
|
24
|
+
Here is an example:
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
group :vendor do # install package under vendor folder
|
28
|
+
package :jquery, "1.8" do # require jquery, version 1.8
|
29
|
+
do_not_install # tell bowerinstall only download jquery for dependency check, we use do_not_install to tell bower that we will include jquery ourselves
|
30
|
+
end
|
31
|
+
package :handlebars, "1.0.0-rc.3" do
|
32
|
+
source 'handlebars.js' # we want to install handlebars.js only.
|
33
|
+
end
|
34
|
+
package :datatables, "1.9.4" # we do not explicitly say what source to install. This will install the files as specified in package's package.json's main attribute
|
35
|
+
end
|
36
|
+
```
|
37
|
+
The other support group is :lib.
|
38
|
+
|
39
|
+
## Available command
|
40
|
+
|
41
|
+
rake bower:install # install bower packages
|
42
|
+
rake bower:unindstall # uninstall bower packages
|
43
|
+
|
44
|
+
## Note
|
45
|
+
After you run bower:install, the required js/css will be installed under
|
46
|
+
/vendor/assets/components folder. It will also generate
|
47
|
+
/app/assets/javascripts/components.js and /app/assets/stylesheets/components.js.
|
48
|
+
You can explicitly require these two files in your application.js and application.css.
|
49
|
+
This will ensure any vendor packages you add in the future will be automatically
|
50
|
+
included into your app.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bowerinstaller/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bowerinstaller"
|
8
|
+
spec.version = Bowerinstaller::VERSION
|
9
|
+
spec.authors = ["Gary Lin"]
|
10
|
+
spec.email = ["gary@employees.org"]
|
11
|
+
spec.description = "Bower installer for rails"
|
12
|
+
spec.summary = "Bower installer for rails"
|
13
|
+
spec.homepage = "https://github.com/garylin/bowerinstaller-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "bowerinstaller/version"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Bowerinstaller
|
5
|
+
extend FileUtils
|
6
|
+
|
7
|
+
require 'bowerinstaller/railtie' if defined?(Rails)
|
8
|
+
require "bowerinstaller/dsl"
|
9
|
+
|
10
|
+
def self.packages_order_by_dependencies
|
11
|
+
bower_map = JSON.parse(`bower list --map`)
|
12
|
+
dep_info = {}
|
13
|
+
bower_map.each do |pkg_name, pkg_info|
|
14
|
+
deps = pkg_info['dependencies']
|
15
|
+
dep_info[pkg_name] = deps ? deps.map { |k, v| k } : []
|
16
|
+
end
|
17
|
+
dep_order = []
|
18
|
+
|
19
|
+
while !dep_info.empty?
|
20
|
+
dep_order += dep_info.map do |pkg_name, deps|
|
21
|
+
dep_info[pkg_name] = deps -= dep_order;
|
22
|
+
deps.empty? ? pkg_name : nil
|
23
|
+
end.compact
|
24
|
+
dep_order.each { |pkg_name| dep_info.delete(pkg_name) }
|
25
|
+
end
|
26
|
+
dep_order
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.sourc_type(filename)
|
30
|
+
File.extname(filename).gsub(/^\./, '');
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.write_file(name, content)
|
34
|
+
File.open(Rails.root.join(name), 'w') { |file| file.write(content) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.install(bower_config)
|
38
|
+
write_file('bower.json', bower_config.to_bower_json)
|
39
|
+
|
40
|
+
# get dependency
|
41
|
+
sh 'bower install'
|
42
|
+
|
43
|
+
# perform installation
|
44
|
+
default_source_list = JSON.parse(`bower list --paths`)
|
45
|
+
install_log = {}
|
46
|
+
bower_config.groups.each do|grp|
|
47
|
+
grp[:packages].each do |pkg|
|
48
|
+
srcs = pkg[:sources] || [default_source_list[pkg[:name].to_s]].flatten || []
|
49
|
+
srcs.each do |src|
|
50
|
+
src_path = Rails.root.join('components', pkg[:name].to_s)
|
51
|
+
s = pkg[:sources] ? src_path.join(src) : Rails.root.join(src)
|
52
|
+
s_relative_path = s.sub(/^#{src_path}\//, '')
|
53
|
+
t = Rails.root.join(grp[:name].to_s, 'assets', 'components', pkg[:name].to_s, s_relative_path)
|
54
|
+
puts "Copy #{pkg[:name].to_s}/#{s_relative_path}"
|
55
|
+
FileUtils.mkdir_p t.dirname.to_s
|
56
|
+
FileUtils.cp s, t
|
57
|
+
(install_log[pkg[:name]] ||= []) << "#{pkg[:name].to_s}/#{s_relative_path}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
reference_files = {};
|
63
|
+
packages_order_by_dependencies.each do |pkg_name|
|
64
|
+
(install_log[pkg_name] || []).each do |source|
|
65
|
+
(reference_files[sourc_type(source)] ||= []) << source
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
reference_files.each do |source_type, sources|
|
70
|
+
if (source_type.to_s == 'js')
|
71
|
+
path = 'javascripts'
|
72
|
+
content = sources.map {|s| "//= require #{s}"}.join("\n");
|
73
|
+
elsif (source_type.to_s == 'css')
|
74
|
+
path = 'stylesheets'
|
75
|
+
content = "/*\n" + sources.map {|s| " *= require #{s}"}.join("\n") + "\n */";
|
76
|
+
end
|
77
|
+
|
78
|
+
write_file(Rails.root.join('app','assets', path, "components.#{source_type}"), content) if path
|
79
|
+
end
|
80
|
+
rm_rf 'bower.json'
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.uninstall(bower_config)
|
85
|
+
['vendor', 'lib'].each do |grp|
|
86
|
+
rm_rf Rails.root.join('grp[:name].to_s', 'assets', 'components').to_s
|
87
|
+
end
|
88
|
+
rm_rf Rails.root.join("components")
|
89
|
+
rm_rf Rails.root.join('app','assets', "javascripts", "components.js")
|
90
|
+
rm_rf Rails.root.join('app','assets', "stylesheets", "components.css")
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'json'
|
2
|
+
module Bowerinstaller
|
3
|
+
class Dsl
|
4
|
+
def initialize
|
5
|
+
@default_options = {}
|
6
|
+
eval_file(Rails.root.join('bower.rb'))
|
7
|
+
end
|
8
|
+
|
9
|
+
def group name, options={}
|
10
|
+
@context = {:packages => []}
|
11
|
+
yield
|
12
|
+
(@groups ||= []) << @default_options.merge({ :name => name, :packages => @context[:packages]})
|
13
|
+
end
|
14
|
+
|
15
|
+
def eval_file(file)
|
16
|
+
contents = File.open(file,"r").read
|
17
|
+
instance_eval(contents, file.to_s, 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
def package name, version=nil, &dsl
|
21
|
+
@context[:sources] = [];
|
22
|
+
if dsl
|
23
|
+
dsl.call()
|
24
|
+
else
|
25
|
+
@context[:sources] = nil # use default install method
|
26
|
+
end
|
27
|
+
(@context[:packages] || []) << {:name => name.to_s, :version => version, :sources => @context[:sources]}
|
28
|
+
end
|
29
|
+
|
30
|
+
def do_not_install
|
31
|
+
@context[:sources] = []
|
32
|
+
end
|
33
|
+
|
34
|
+
def source src
|
35
|
+
(@context[:sources] ||= []) << src
|
36
|
+
end
|
37
|
+
|
38
|
+
def groups
|
39
|
+
@groups
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_bower_json
|
43
|
+
dependencies = {};
|
44
|
+
|
45
|
+
groups.each do|grp|
|
46
|
+
grp[:packages].each do |pkg|
|
47
|
+
dependencies[pkg[:name]] = pkg[:version] || 'latest'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return JSON.pretty_generate( {:dependencies => dependencies} )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bowerinstaller'
|
2
|
+
require 'rails'
|
3
|
+
module BowerInstaller
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
railtie_name :bowerinstaller
|
6
|
+
|
7
|
+
config.after_initialize do |app|
|
8
|
+
["lib", "vendor"].each do |dir|
|
9
|
+
app.config.assets.paths << Rails.root.join(dir, 'assets', 'components')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
rake_tasks do
|
14
|
+
load "tasks/bowerinstaller.rake"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
namespace :bower do
|
2
|
+
desc "Run bower"
|
3
|
+
|
4
|
+
bower_config = Bowerinstaller::Dsl.new
|
5
|
+
|
6
|
+
task :install do
|
7
|
+
Bowerinstaller.install(bower_config)
|
8
|
+
end
|
9
|
+
|
10
|
+
# task :update do
|
11
|
+
# gittler.install "#{Rails.root}"
|
12
|
+
# end
|
13
|
+
|
14
|
+
task :uninstall do
|
15
|
+
Bowerinstaller.uninstall(bower_config)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bowerinstaller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gary Lin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-06 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Bower installer for rails
|
42
|
+
email:
|
43
|
+
- gary@employees.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bowerinstaller.gemspec
|
54
|
+
- lib/bowerinstaller.rb
|
55
|
+
- lib/bowerinstaller/dsl.rb
|
56
|
+
- lib/bowerinstaller/railtie.rb
|
57
|
+
- lib/bowerinstaller/version.rb
|
58
|
+
- lib/tasks/bowerinstaller.rake
|
59
|
+
homepage: https://github.com/garylin/bowerinstaller-rails
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Bower installer for rails
|
83
|
+
test_files: []
|