bower_vendor 0.0.4

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: 061b206ea3ca93d61e5d78b5f8def7df7a269c6c
4
+ data.tar.gz: 5552fa9185b5fc7f24e833da840686f7f26922c0
5
+ SHA512:
6
+ metadata.gz: 7f6864277758c9ad6e1a418b2e188d78f509f2da5a5a4d074f67d4a35da4944a377a2715345d889240bae5c3ee63cdf668f5ad185826a937f0a0faa261c1213c
7
+ data.tar.gz: f8a1411f71ad7d39ab1c0d67ac63c64774ff30a1f15e8a5558fffdfbecd6178ffe34d462a75b31fbed382d3a6ee9d9b32a435b2887b0c9b40aa3e3d5183720c5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.gem
15
+ mkmf.log
16
+ /vendor
17
+ /vendor.yml
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ bower_vendor
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.5
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 kari
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,31 @@
1
+ # BowerVendor
2
+
3
+ Rake tasks to manage vendor assets for rails application
4
+ using bower. This gem is inspired by bower-rails.
5
+
6
+ # Install
7
+
8
+ Gemfile
9
+ ```ruby
10
+ gem 'bower_vendor'
11
+ ```
12
+
13
+ # Usage
14
+
15
+ 1) Configuration file
16
+
17
+ vendor.yml
18
+ ```ruby
19
+ angular:
20
+ version: 1.3.15
21
+ files:
22
+ - angular.js
23
+ ```
24
+
25
+ 2) Install assets
26
+
27
+ ```bash
28
+ bundle exec rake vendor:all
29
+ ```
30
+
31
+ Assets will be copied into vendor/assets
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'bower_vendor'
3
+
4
+ BowerVendor.load_tasks
5
+
6
+ load 'lib/tasks/console.rake'
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bower_vendor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bower_vendor"
8
+ spec.version = BowerVendor::VERSION
9
+ spec.authors = ["kari"]
10
+ spec.email = ["mr.kari.ikonen@gmail.com"]
11
+ spec.summary = 'Use bower to manage resources for rails application'
12
+ spec.description = 'Manage vendor assets using simple configuration file'
13
+ spec.homepage = "https://github.com/kikonen/bower_vendor"
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.add_dependency "awesome_print"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry"
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'awesome_print'
2
+ require 'yaml'
3
+ require 'json'
4
+
5
+ require "bower_vendor/version"
6
+ require "bower_vendor/base"
7
+ require "bower_vendor/copy"
8
+ require "bower_vendor/fetch"
9
+ require "bower_vendor/setup"
10
+
11
+ if defined?(Rails)
12
+ require "bower_vendor/railtie"
13
+ end
14
+
15
+ module BowerVendor
16
+ def self.root_dir
17
+ File.expand_path('../..', __FILE__)
18
+ end
19
+
20
+ def self.load_tasks
21
+ dir = File.join(root_dir, 'lib/tasks')
22
+ load "#{dir}/vendor.rake"
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module BowerVendor
2
+ class Base
3
+ def initialize
4
+ end
5
+
6
+ def vendors
7
+ @vendors ||= YAML.load_file('vendor.yml')
8
+ end
9
+
10
+ def config
11
+ # @config ||= YAML.load_file('vendor_config.yml')
12
+ @config ||= {
13
+ base_dir: 'vendor/assets',
14
+ dst_dirs: {
15
+ 'css' => 'stylesheets',
16
+ 'js' => 'javascripts',
17
+ }
18
+ }
19
+ end
20
+
21
+ def base_src_dir
22
+ @base_src_dir ||= 'bower_components'
23
+ end
24
+
25
+ def work_dir
26
+ if defined?(Rails)
27
+ "#{Rails.root}/tmp"
28
+ else
29
+ 'tmp'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,73 @@
1
+ module BowerVendor
2
+ class Copy < Base
3
+ def execute
4
+ ap vendors
5
+
6
+ vendors.each do |asset_key, asset_data|
7
+ src_dir = "#{base_src_dir}/#{asset_key}"
8
+ puts "processing: #{src_dir}"
9
+
10
+ run_scripts(asset_key, asset_data)
11
+ copy_files(asset_key, asset_data)
12
+ end
13
+ end
14
+
15
+ def run_scripts(asset_key, asset_data)
16
+ scripts = (asset_data['build'] || [])
17
+ if !scripts.empty?
18
+ puts " building..."
19
+ scripts.each do |cmd|
20
+ full_cmd ="cd #{src_dir} && #{cmd}"
21
+ puts " #{full_cmd}"
22
+ pid = fork do
23
+ exec full_cmd
24
+ end
25
+ Process.wait pid
26
+ end
27
+ end
28
+ end
29
+
30
+ def copy_files(asset_key, asset_data)
31
+ puts " copying..."
32
+ version = asset_data['version']
33
+ asset_data['files'].each do |orig_path|
34
+ src_path = orig_path.gsub("{{VERSION}}", version)
35
+ has_version = orig_path != src_path
36
+ src_file = src_path.split('/').last
37
+ ext = src_file.split('.').last
38
+ dst_file = src_file
39
+ unless has_version
40
+ # dst_file = src_file.gsub("\.#{ext}", "-#{version}.#{ext}")
41
+ end
42
+
43
+ src_dir = "#{work_dir}/bower_components/#{asset_key}"
44
+
45
+ base_dst_dir = dst_dirs[ext]
46
+ dst_dir = "#{base_dst_dir}/#{asset_key}-#{version}"
47
+
48
+ full_src_file = "#{src_dir}/#{src_path}"
49
+ full_dst_file = "#{dst_dir}/#{dst_file}"
50
+
51
+ puts " #{full_src_file} => #{full_dst_file}"
52
+ if !File.exist? full_src_file
53
+ raise "NOT_FOUND: #{full_src_file}"
54
+ end
55
+ if !Dir.exist? dst_dir
56
+ FileUtils.mkdir_p dst_dir
57
+ end
58
+ FileUtils.cp full_src_file, full_dst_file
59
+ end
60
+ end
61
+
62
+ def dst_dirs
63
+ @dst_dirs ||= setup_dst_dirs
64
+ end
65
+
66
+ def setup_dst_dirs
67
+ base_dir = config[:base_dir]
68
+ config[:dst_dirs].map do |k, v|
69
+ [k, "#{base_dir}/#{v}"]
70
+ end.to_h
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,12 @@
1
+ module BowerVendor
2
+ class Fetch < Base
3
+ def execute
4
+ Dir.chdir(work_dir) do
5
+ fork do
6
+ exec "bower install"
7
+ end
8
+ Process.wait
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module BowerVendor
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ BowerVendor.load_tasks
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ module BowerVendor
2
+ class Setup < Base
3
+ def execute
4
+ create_bowerrc
5
+ create_bower_json
6
+ end
7
+
8
+ def create_bower_json
9
+ data = {
10
+ name: 'autogenerated',
11
+ dependencies: {
12
+ },
13
+ resolutions: {
14
+ },
15
+ }
16
+ vendors.each do |vendor_key, vendor|
17
+ data[:dependencies][vendor_key] = vendor['version']
18
+ data[:resolutions][vendor_key] = vendor['version']
19
+ end
20
+ File.write("#{work_dir}/bower.json", JSON.pretty_generate(data))
21
+ end
22
+
23
+ def create_bowerrc
24
+ data = {
25
+ directory: "bower_components"
26
+ }
27
+ File.write("#{work_dir}/.bowerrc", JSON.pretty_generate(data))
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module BowerVendor
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'pry'
2
+ desc 'console'
3
+ task :console do
4
+ pry
5
+ end
@@ -0,0 +1,25 @@
1
+ namespace :vendor do
2
+ desc 'Do all'
3
+ task :all => [:setup, :fetch, :copy] do
4
+ end
5
+
6
+ desc 'Clear bower setup and fetched bower_components'
7
+ task :clean do
8
+ BowerVendor::Clean.new.execute
9
+ end
10
+
11
+ desc 'Create setup for bower'
12
+ task :setup do
13
+ BowerVendor::Setup.new.execute
14
+ end
15
+
16
+ desc 'Fetch bower_components'
17
+ task :fetch do
18
+ BowerVendor::Fetch.new.execute
19
+ end
20
+
21
+ desc 'Copy bower_components to vendor/assets'
22
+ task :copy do
23
+ BowerVendor::Copy.new.execute
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bower_vendor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - kari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Manage vendor assets using simple configuration file
70
+ email:
71
+ - mr.kari.ikonen@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-gemset"
78
+ - ".ruby-version"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bower_vendor.gemspec
84
+ - lib/bower_vendor.rb
85
+ - lib/bower_vendor/base.rb
86
+ - lib/bower_vendor/copy.rb
87
+ - lib/bower_vendor/fetch.rb
88
+ - lib/bower_vendor/railtie.rb
89
+ - lib/bower_vendor/setup.rb
90
+ - lib/bower_vendor/version.rb
91
+ - lib/tasks/console.rake
92
+ - lib/tasks/vendor.rake
93
+ homepage: https://github.com/kikonen/bower_vendor
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Use bower to manage resources for rails application
117
+ test_files: []