bower_vendor 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 061b206ea3ca93d61e5d78b5f8def7df7a269c6c
4
- data.tar.gz: 5552fa9185b5fc7f24e833da840686f7f26922c0
3
+ metadata.gz: 762474c4e7c499fcf2909f643ee0ec6e799e69fc
4
+ data.tar.gz: 201cf15a263a2dfe38206305ca8f2665fadb0386
5
5
  SHA512:
6
- metadata.gz: 7f6864277758c9ad6e1a418b2e188d78f509f2da5a5a4d074f67d4a35da4944a377a2715345d889240bae5c3ee63cdf668f5ad185826a937f0a0faa261c1213c
7
- data.tar.gz: f8a1411f71ad7d39ab1c0d67ac63c64774ff30a1f15e8a5558fffdfbecd6178ffe34d462a75b31fbed382d3a6ee9d9b32a435b2887b0c9b40aa3e3d5183720c5
6
+ metadata.gz: d894aceae7ae02bdb74d920b773dd6b53b9c524c6b748403a60bf188534e0867b198e702b4ee369d8c7a5b9cbb0b865d57111edf5705ab277e769115d7e9b436
7
+ data.tar.gz: c942e7408a84f3d9d206d59abbcb271670e130bc2d07f34d27d7f0123c9cb9999989264a41b5012699d6d87275cc7db092c0ca7594da07b572e2590346362fff
data/README.md CHANGED
@@ -1,8 +1,24 @@
1
1
  # BowerVendor
2
2
 
3
- Rake tasks to manage vendor assets for rails application
3
+ Simple rake tasks to manage vendor assets for rails application
4
4
  using bower. This gem is inspired by bower-rails.
5
5
 
6
+ Reason for the existence of this gem is to have improved assets control, which is lacking
7
+ in bower-rails. This gem not only fetches assets using bower, but also contains logic to
8
+ maintain actually used assets in "vendor/asests" so that they can be committed safely into
9
+ repository.
10
+
11
+ This has various benefits
12
+ - Removes bower dependency from deploy
13
+ * Safe-guarding deplpy from unavailability of bower central repository
14
+ * Faster deploy
15
+ * no need to have node/bower/etc. installed in deployed machine
16
+ - Versioned assets, allowing safer upgrading of them (and safe rollback to old versions)
17
+ * This allows that not all parts of the application (or engines) are requierd to be upgraded
18
+ to latest vendor asset versions at once
19
+ - Assets are available always
20
+ * Just clone repository and it's ready to use
21
+
6
22
  # Install
7
23
 
8
24
  Gemfile
@@ -16,16 +32,53 @@ gem 'bower_vendor'
16
32
 
17
33
  vendor.yml
18
34
  ```ruby
35
+ jquery:
36
+ version: 2.1.3
37
+ assets:
38
+ - dist/jquery.js
39
+ jquery-ujs:
40
+ version: 1.0.3
41
+ assets:
42
+ - src/rails.js
43
+ lodash:
44
+ version: 3.0.0
45
+ assets:
46
+ - lodash.js
19
47
  angular:
20
48
  version: 1.3.15
21
- files:
49
+ assets:
22
50
  - angular.js
51
+ bootstrap-sass:
52
+ version: 3.3.4
53
+ assets:
54
+ - assets/javascripts/bootstrap-sprockets.js
55
+ # copy into "bootstrap" subdir in destination
56
+ - bootstrap:
57
+ - assets/javascripts/*.js
58
+ - assets/stylesheets/_bootstrap.scss
59
+ - assets/stylesheets/_bootstrap-sprockets.scss
60
+ - bootstrap:
61
+ - assets/stylesheets/bootstrap/*.scss
62
+ # copy into "bootstrap/mixins" subdir in destination
63
+ - mixins:
64
+ - assets/stylesheets/bootstrap/mixins/*.scss
65
+ # "*" matches all files
66
+ - assets/fonts/bootstrap/*
23
67
  ```
24
68
 
25
69
  2) Install assets
26
70
 
27
71
  ```bash
72
+ bundle exec rake vendor:clean
28
73
  bundle exec rake vendor:all
29
74
  ```
30
75
 
31
76
  Assets will be copied into vendor/assets
77
+
78
+
79
+ # TODO
80
+
81
+ - Support other more asset types
82
+ * curently only js and css are supported
83
+ * should support also fonts, etc.
84
+ - Support more complex paths for assets
@@ -0,0 +1,20 @@
1
+ ---
2
+ base_dir: vendor/assets
3
+ dst_dirs:
4
+ # javascripts
5
+ js: javascripts
6
+ es6: javascripts
7
+ next: javascripts
8
+ # stylesheets
9
+ css: stylesheets
10
+ scss: stylesheets
11
+ # fonts
12
+ eot: fonts
13
+ ttf: fonts
14
+ woff: fonts
15
+ woff2: fonts
16
+ # images
17
+ jpg: images
18
+ jpeg: images
19
+ png: images
20
+ svg: images
data/lib/bower_vendor.rb CHANGED
@@ -4,6 +4,7 @@ require 'json'
4
4
 
5
5
  require "bower_vendor/version"
6
6
  require "bower_vendor/base"
7
+ require "bower_vendor/clean"
7
8
  require "bower_vendor/copy"
8
9
  require "bower_vendor/fetch"
9
10
  require "bower_vendor/setup"
@@ -19,6 +20,6 @@ module BowerVendor
19
20
 
20
21
  def self.load_tasks
21
22
  dir = File.join(root_dir, 'lib/tasks')
22
- load "#{dir}/vendor.rake"
23
+ load "#{dir}/bower_vendor.rake"
23
24
  end
24
25
  end
@@ -8,14 +8,16 @@ module BowerVendor
8
8
  end
9
9
 
10
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
- }
11
+ @config ||= load_config('config/bower_vendor.yml')
12
+ @config ||= load_config(File.join(BowerVendor.root_dir, 'config/bower_vendor.yml'))
13
+ end
14
+
15
+ def load_config(file)
16
+ if File.exist?(file)
17
+ YAML.load_file(file)
18
+ else
19
+ nil
20
+ end
19
21
  end
20
22
 
21
23
  def base_src_dir
@@ -0,0 +1,11 @@
1
+ module BowerVendor
2
+ class Clean < Base
3
+ def initialize
4
+ end
5
+
6
+ def execute
7
+ FileUtils.rm_rf "#{work_dir}/bower_components"
8
+ FileUtils.rm_f "#{work_dir}/bower.json"
9
+ end
10
+ end
11
+ end
@@ -5,20 +5,20 @@ module BowerVendor
5
5
 
6
6
  vendors.each do |asset_key, asset_data|
7
7
  src_dir = "#{base_src_dir}/#{asset_key}"
8
- puts "processing: #{src_dir}"
8
+ msg 0, "processing: #{src_dir}"
9
9
 
10
- run_scripts(asset_key, asset_data)
11
- copy_files(asset_key, asset_data)
10
+ run_scripts(asset_key, asset_data, 1)
11
+ copy_assets(asset_key, asset_data, 1)
12
12
  end
13
13
  end
14
14
 
15
- def run_scripts(asset_key, asset_data)
15
+ def run_scripts(asset_key, asset_data, level)
16
16
  scripts = (asset_data['build'] || [])
17
17
  if !scripts.empty?
18
- puts " building..."
18
+ msg level, "building..."
19
19
  scripts.each do |cmd|
20
20
  full_cmd ="cd #{src_dir} && #{cmd}"
21
- puts " #{full_cmd}"
21
+ msg level + 1, full_cmd
22
22
  pid = fork do
23
23
  exec full_cmd
24
24
  end
@@ -27,47 +27,70 @@ module BowerVendor
27
27
  end
28
28
  end
29
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
30
+ def copy_assets(asset_key, asset_data, level)
31
+ msg level, "copying: #{asset_key}..."
32
+ copy_asset(asset_key, asset_data, asset_data['assets'], '', level + 1)
33
+ end
42
34
 
43
- src_dir = "#{work_dir}/bower_components/#{asset_key}"
35
+ def copy_asset(asset_key, asset_data, assets, target_path = '', level)
36
+ assets.each do |asset|
37
+ if asset.is_a? Hash
38
+ sub_asset = asset.keys.first
39
+ sub_target_path = target_path.empty? ? sub_asset : target_path + '/' + sub_asset
40
+ copy_asset(asset_key, asset_data, asset[sub_asset], sub_target_path, level + 1)
41
+ else
42
+ msg level, asset
44
43
 
45
- base_dst_dir = dst_dirs[ext]
46
- dst_dir = "#{base_dst_dir}/#{asset_key}-#{version}"
44
+ version = asset_data['version']
45
+ src_path = asset.gsub("{{VERSION}}", version)
47
46
 
48
- full_src_file = "#{src_dir}/#{src_path}"
49
- full_dst_file = "#{dst_dir}/#{dst_file}"
47
+ base_src_dir = "#{work_dir}/bower_components"
48
+ src = "#{base_src_dir}/#{asset_key}/#{src_path}"
50
49
 
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
50
+ Dir[src].sort!.each do |src_path|
51
+ copy_src_file asset_key, asset_data, asset, src_path, target_path, level + 1
52
+ end
57
53
  end
58
- FileUtils.cp full_src_file, full_dst_file
59
54
  end
60
55
  end
61
56
 
57
+ def copy_src_file(asset_key, asset_data, orig_path, full_src_file, target_path, level)
58
+ if !File.exist? full_src_file
59
+ raise "NOT_FOUND: #{full_src_file}"
60
+ end
61
+
62
+ version = asset_data['version']
63
+ src_file = full_src_file.split('/').last
64
+ ext = src_file.split('.').last
65
+ dst_file = src_file
66
+
67
+ base_dst_dir = dst_dirs[ext]
68
+ raise "NOT_FOUND_EXT: #{ext}" unless base_dst_dir
69
+
70
+ dst_dir = "#{base_dst_dir}/#{asset_key}-#{version}"
71
+ dst_dir = "#{dst_dir}/#{target_path}" unless target_path.empty?
72
+ full_dst_file = "#{dst_dir}/#{dst_file}"
73
+
74
+ msg level, "#{full_src_file} => #{full_dst_file}"
75
+ if !Dir.exist? dst_dir
76
+ FileUtils.mkdir_p dst_dir
77
+ end
78
+ FileUtils.cp full_src_file, full_dst_file
79
+ end
80
+
62
81
  def dst_dirs
63
82
  @dst_dirs ||= setup_dst_dirs
64
83
  end
65
84
 
66
85
  def setup_dst_dirs
67
- base_dir = config[:base_dir]
68
- config[:dst_dirs].map do |k, v|
86
+ base_dir = config['base_dir']
87
+ config['dst_dirs'].map do |k, v|
69
88
  [k, "#{base_dir}/#{v}"]
70
89
  end.to_h
71
90
  end
91
+
92
+ def msg(level, msg)
93
+ puts "#{' ' * level}#{msg}"
94
+ end
72
95
  end
73
96
  end
@@ -1,3 +1,3 @@
1
1
  module BowerVendor
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  namespace :vendor do
2
- desc 'Do all'
2
+ desc 'Do everything except clean'
3
3
  task :all => [:setup, :fetch, :copy] do
4
4
  end
5
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bower_vendor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -81,15 +81,17 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - bower_vendor.gemspec
84
+ - config/bower_vendor.yml
84
85
  - lib/bower_vendor.rb
85
86
  - lib/bower_vendor/base.rb
87
+ - lib/bower_vendor/clean.rb
86
88
  - lib/bower_vendor/copy.rb
87
89
  - lib/bower_vendor/fetch.rb
88
90
  - lib/bower_vendor/railtie.rb
89
91
  - lib/bower_vendor/setup.rb
90
92
  - lib/bower_vendor/version.rb
93
+ - lib/tasks/bower_vendor.rake
91
94
  - lib/tasks/console.rake
92
- - lib/tasks/vendor.rake
93
95
  homepage: https://github.com/kikonen/bower_vendor
94
96
  licenses:
95
97
  - MIT