bower_vendor 0.0.18 → 0.1.0

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
- SHA1:
3
- metadata.gz: e2143404e8b00fb878d79591d322abd096bcc0de
4
- data.tar.gz: a0cfb58598f9280a3aa43842ecd271268a8342d2
2
+ SHA256:
3
+ metadata.gz: 2b417d3edd915d7fde1d0881d3beda3307c347e6782e42a5d440dd0479578304
4
+ data.tar.gz: 4dd3926b2c96f3ba301f34b0b3cf3d223f30b2a4c181ad10a62f29a5b7bbcc1d
5
5
  SHA512:
6
- metadata.gz: 72803a3b96b4c42768c9be4a46e75b11bb970d817171b58f76ff547c61897313cab131c25bc225643fb3f43382e51123f704da6ee1f7d9a428ecd6647b8188a0
7
- data.tar.gz: 0b898156a61e220de861d56d162d820e9d1eb743e9c31aa56f76e7e0d16c578f207119270d978b753b2b957bf7b17a7de20d2cf8435fa305ed217f3e1bbddf95
6
+ metadata.gz: 57d05d4bd63b24fc08baac65304a22902b10cb0d810c842c7eabc942e53d9877efe8e1ec26b632449cf72510702cca4cc1440586f49de00cc660791ac2282fe5
7
+ data.tar.gz: 669245594777c50b5c18cc1721a488ea6e4b1848af9a05691b5718b55ce5e1f9c0bd9d57682b342325f11d273b036cea61a8fea6097523b7fd41b46f9b47f399
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # BowerVendor
2
2
 
3
3
  Simple rake tasks to manage vendor assets for rails application
4
- using bower. This gem is inspired by bower-rails.
4
+ using bower or yarn. This gem is inspired by bower-rails.
5
5
 
6
6
  Reason for the existence of this gem is to have improved assets control, which is lacking
7
7
  in bower-rails. This gem not only fetches assets using bower, but also contains logic to
@@ -96,6 +96,34 @@ bootstrap-multiselect:
96
96
  - dist/js/bootstrap-multiselect-collapsible-groups.js
97
97
  ```
98
98
 
99
+ vendor_yarn.yml
100
+ ```yaml
101
+ bootstrap:
102
+ assets:
103
+ - scss/*.scss
104
+ - mixins:
105
+ - scss/mixins/*.scss
106
+ - utilities:
107
+ - scss/utilities/*.scss
108
+ - js/dist/*.js
109
+
110
+ jquery:
111
+ assets:
112
+ - dist/jquery.js
113
+
114
+ lodash:
115
+ assets:
116
+ - lodash.js
117
+
118
+ url.js:
119
+ assets:
120
+ - url.js
121
+
122
+ vue:
123
+ assets:
124
+ - dist/vue.js
125
+ ```
126
+
99
127
  2) Install assets
100
128
 
101
129
  ```bash
@@ -7,6 +7,7 @@ require "bower_vendor/base"
7
7
  require "bower_vendor/clean"
8
8
  require "bower_vendor/check"
9
9
  require "bower_vendor/copy"
10
+ require "bower_vendor/yarn"
10
11
  require "bower_vendor/fetch"
11
12
  require "bower_vendor/setup"
12
13
 
@@ -1,60 +1,58 @@
1
- module BowerVendor
2
- class Base
3
- def initialize
4
- end
1
+ class BowerVendor::Base
2
+ def initialize
3
+ end
5
4
 
6
- def vendors
7
- @vendors ||= load_vendors
8
- validate_vendors
9
- @vendors
10
- end
5
+ def vendors
6
+ @vendors ||= load_vendors
7
+ validate_vendors
8
+ @vendors
9
+ end
11
10
 
12
- def validate_vendors
13
- # validate resources
14
- @vendors.each do |vendor_key, vendor|
15
- raise "VERSION MISSING: #{vendor_key}: #{vendor.inspect}" unless vendor['version']
16
- puts "WARN: ASSETS MISSING: #{vendor_key}: #{vendor.inspect}" unless vendor['assets']
17
- end
11
+ def validate_vendors
12
+ # validate resources
13
+ @vendors.each do |vendor_key, vendor|
14
+ raise "VERSION MISSING: #{vendor_key}: #{vendor.inspect}" unless vendor['version']
15
+ puts "WARN: ASSETS MISSING: #{vendor_key}: #{vendor.inspect}" unless vendor['assets']
18
16
  end
17
+ end
19
18
 
20
- def config
21
- @config ||= load_config('config/bower_vendor.yml')
22
- @config ||= load_config(File.join(BowerVendor.root_dir, 'config/bower_vendor.yml'))
23
- end
19
+ def config
20
+ @config ||= load_config('config/bower_vendor.yml')
21
+ @config ||= load_config(File.join(BowerVendor.root_dir, 'config/bower_vendor.yml'))
22
+ end
24
23
 
25
- def load_config(file)
26
- if File.exist?(file)
27
- YAML.load_file(file)
28
- else
29
- nil
30
- end
24
+ def load_config(file)
25
+ if File.exist?(file)
26
+ YAML.load_file(file)
27
+ else
28
+ nil
31
29
  end
30
+ end
32
31
 
33
- def full_asset_key_src_dir(asset_key)
34
- "#{self.work_dir}/bower_components/#{asset_key}"
35
- end
32
+ def full_asset_key_src_dir(asset_key)
33
+ "#{self.work_dir}/bower_components/#{asset_key}"
34
+ end
36
35
 
37
- def work_dir
38
- "#{self.root_dir}/tmp"
39
- end
36
+ def work_dir
37
+ "#{self.root_dir}/tmp"
38
+ end
40
39
 
41
- def local_node_bin
42
- "#{self.root_dir}/node_modules/.bin"
43
- end
40
+ def local_node_bin
41
+ "#{self.root_dir}/node_modules/.bin"
42
+ end
44
43
 
45
- def root_dir
46
- @root_dir ||= if defined?(Rails)
47
- Rails.root
48
- else
49
- Dir.pwd
50
- end
51
- end
44
+ def root_dir
45
+ @root_dir ||= if defined?(Rails)
46
+ Rails.root
47
+ else
48
+ Dir.pwd
49
+ end
50
+ end
52
51
 
53
- def load_vendors
54
- vendors = YAML.load_file('vendor.yml')
55
- vendors.sort do |a, b|
56
- a[0] <=> b[0]
57
- end.to_h
58
- end
52
+ def load_vendors
53
+ vendors = YAML.load_file('vendor.yml')
54
+ vendors.sort do |a, b|
55
+ a[0] <=> b[0]
56
+ end.to_h
59
57
  end
60
58
  end
@@ -1,20 +1,18 @@
1
- module BowerVendor
2
- class Check < Base
3
- def execute
4
- Dir.chdir(work_dir) do
5
- script = executable
6
- puts "excutable: #{script}"
7
- fork do
8
- exec "#{script}"
9
- end
10
- Process.wait
1
+ class BowerVendor::Check < BowerVendor::Base
2
+ def execute
3
+ Dir.chdir(work_dir) do
4
+ script = executable
5
+ puts "excutable: #{script}"
6
+ fork do
7
+ exec "#{script}"
11
8
  end
9
+ Process.wait
12
10
  end
11
+ end
13
12
 
14
- def executable
15
- f = "#{local_node_bin}/bcu"
16
- puts "BCU: #{f}"
17
- File.exists?(f) ? f : 'bcu'
18
- end
13
+ def executable
14
+ f = "#{local_node_bin}/bcu"
15
+ puts "BCU: #{f}"
16
+ File.exists?(f) ? f : 'bcu'
19
17
  end
20
18
  end
@@ -1,11 +1,9 @@
1
- module BowerVendor
2
- class Clean < Base
3
- def initialize
4
- end
1
+ class BowerVendor::Clean < BowerVendor::Base
2
+ def initialize
3
+ end
5
4
 
6
- def execute
7
- FileUtils.rm_rf "#{work_dir}/bower_components"
8
- FileUtils.rm_f "#{work_dir}/bower.json"
9
- end
5
+ def execute
6
+ FileUtils.rm_rf "#{work_dir}/bower_components"
7
+ FileUtils.rm_f "#{work_dir}/bower.json"
10
8
  end
11
9
  end
@@ -1,104 +1,102 @@
1
- module BowerVendor
2
- class Copy < Base
3
- def execute
4
- vendors.each do |asset_key, asset_data|
5
- src_dir = full_asset_key_src_dir(asset_key)
6
- msg 0, "processing: #{src_dir}"
7
-
8
- run_build_scripts(asset_key, asset_data, 1)
9
- copy_assets(asset_key, asset_data, 1)
10
- end
1
+ class BowerVendor::Copy < BowerVendor::Base
2
+ def execute
3
+ vendors.each do |asset_key, asset_data|
4
+ src_dir = full_asset_key_src_dir(asset_key)
5
+ msg 0, "processing: #{src_dir}"
6
+
7
+ run_build_scripts(asset_key, asset_data, 1)
8
+ copy_assets(asset_key, asset_data, 1)
11
9
  end
10
+ end
12
11
 
13
- def run_build_scripts(asset_key, asset_data, level)
14
- scripts = (asset_data['build'] || [])
15
- return if scripts.empty?
12
+ def run_build_scripts(asset_key, asset_data, level)
13
+ scripts = (asset_data['build'] || [])
14
+ return if scripts.empty?
16
15
 
17
- src_dir = full_asset_key_src_dir(asset_key)
16
+ src_dir = full_asset_key_src_dir(asset_key)
18
17
 
19
- msg level, "building..."
20
- scripts.each do |cmd|
21
- msg level + 1, "cd #{src_dir} && #{cmd}"
18
+ msg level, "building..."
19
+ scripts.each do |cmd|
20
+ msg level + 1, "cd #{src_dir} && #{cmd}"
22
21
 
23
- pid = fork do
24
- Dir.chdir src_dir
25
- puts `#{cmd}`
26
- end
27
- Process.wait pid
22
+ pid = fork do
23
+ Dir.chdir src_dir
24
+ puts `#{cmd}`
28
25
  end
26
+ Process.wait pid
29
27
  end
28
+ end
29
+
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
30
34
 
31
- def copy_assets(asset_key, asset_data, level)
32
- msg level, "copying: #{asset_key}..."
33
- copy_asset(asset_key, asset_data, asset_data['assets'], '', level + 1)
35
+ def copy_asset(asset_key, asset_data, assets, target_path = '', level)
36
+ assets ||= []
37
+ if assets.empty?
38
+ msg level, "WARN: ASSETS MISSING"
34
39
  end
35
40
 
36
- def copy_asset(asset_key, asset_data, assets, target_path = '', level)
37
- assets ||= []
38
- if assets.empty?
39
- msg level, "WARN: ASSETS MISSING"
40
- end
41
+ assets.each do |asset|
42
+ if asset.is_a? Hash
43
+ sub_asset = asset.keys.first
44
+ sub_target_path = target_path.empty? ? sub_asset : target_path + '/' + sub_asset
45
+ copy_asset(asset_key, asset_data, asset[sub_asset], sub_target_path, level + 1)
46
+ else
47
+ msg level, asset
48
+
49
+ version = asset_data['version'].to_s
50
+ raise "VERSION MISSING: #{asset_data.inspect}" if version.empty?
41
51
 
42
- assets.each do |asset|
43
- if asset.is_a? Hash
44
- sub_asset = asset.keys.first
45
- sub_target_path = target_path.empty? ? sub_asset : target_path + '/' + sub_asset
46
- copy_asset(asset_key, asset_data, asset[sub_asset], sub_target_path, level + 1)
47
- else
48
- msg level, asset
49
-
50
- version = asset_data['version'].to_s
51
- raise "VERSION MISSING: #{asset_data.inspect}" if version.empty?
52
-
53
- asset_path = asset.gsub("{{VERSION}}", version)
54
- src = "#{full_asset_key_src_dir(asset_key)}/#{asset_path}"
55
-
56
- files = Dir[src].sort!
57
- raise "NOT_FOUND: #{src}" if files.empty?
58
- files.each do |src_path|
59
- copy_src_file asset_key, asset_data, asset, src_path, target_path, level + 1
60
- end
52
+ asset_path = asset.gsub("{{VERSION}}", version)
53
+ src = "#{full_asset_key_src_dir(asset_key)}/#{asset_path}"
54
+
55
+ files = Dir[src].sort!
56
+ raise "NOT_FOUND: #{src}" if files.empty?
57
+ files.each do |src_path|
58
+ copy_src_file asset_key, asset_data, asset, src_path, target_path, level + 1
61
59
  end
62
60
  end
63
61
  end
62
+ end
64
63
 
65
- def copy_src_file(asset_key, asset_data, orig_path, full_src_file, target_path, level)
66
- if !File.exist? full_src_file
67
- raise "NOT_FOUND: #{full_src_file}"
68
- end
64
+ def copy_src_file(asset_key, asset_data, orig_path, full_src_file, target_path, level)
65
+ if !File.exist? full_src_file
66
+ raise "NOT_FOUND: #{full_src_file}"
67
+ end
69
68
 
70
- version = asset_data['version'].to_s
71
- src_file = full_src_file.split('/').last
72
- ext = src_file.split('.').last
73
- dst_file = src_file
69
+ version = asset_data['version'].to_s
70
+ src_file = full_src_file.split('/').last
71
+ ext = src_file.split('.').last
72
+ dst_file = src_file
74
73
 
75
- base_dst_dir = self.dst_dirs[ext]
76
- raise "NOT_FOUND_EXT: #{ext}" unless base_dst_dir
74
+ base_dst_dir = self.dst_dirs[ext]
75
+ raise "NOT_FOUND_EXT: #{ext}" unless base_dst_dir
77
76
 
78
- dst_dir = "#{base_dst_dir}/#{asset_key}-#{version}"
79
- dst_dir = "#{dst_dir}/#{target_path}" unless target_path.empty?
80
- full_dst_file = "#{dst_dir}/#{dst_file}"
77
+ dst_dir = "#{base_dst_dir}/#{asset_key}-#{version}"
78
+ dst_dir = "#{dst_dir}/#{target_path}" unless target_path.empty?
79
+ full_dst_file = "#{dst_dir}/#{dst_file}"
81
80
 
82
- msg level, "#{full_src_file} => #{full_dst_file}"
83
- if !Dir.exist? dst_dir
84
- FileUtils.mkdir_p dst_dir
85
- end
86
- FileUtils.cp full_src_file, full_dst_file
81
+ msg level, "#{full_src_file} => #{full_dst_file}"
82
+ if !Dir.exist? dst_dir
83
+ FileUtils.mkdir_p dst_dir
87
84
  end
85
+ FileUtils.cp full_src_file, full_dst_file
86
+ end
88
87
 
89
- def dst_dirs
90
- @dst_dirs ||= setup_dst_dirs
91
- end
88
+ def dst_dirs
89
+ @dst_dirs ||= setup_dst_dirs
90
+ end
92
91
 
93
- def setup_dst_dirs
94
- base_dir = config['base_dir']
95
- config['dst_dirs'].map do |k, v|
96
- [k, "#{base_dir}/#{v}"]
97
- end.to_h
98
- end
92
+ def setup_dst_dirs
93
+ base_dir = config['base_dir']
94
+ config['dst_dirs'].map do |k, v|
95
+ [k, "#{base_dir}/#{v}"]
96
+ end.to_h
97
+ end
99
98
 
100
- def msg(level, msg)
101
- puts "#{' ' * level}#{msg}"
102
- end
99
+ def msg(level, msg)
100
+ puts "#{' ' * level}#{msg}"
103
101
  end
104
102
  end
@@ -1,20 +1,18 @@
1
- module BowerVendor
2
- class Fetch < Base
3
- def execute
4
- script = executable
5
- puts "excutable: #{script}"
1
+ class BowerVendor::Fetch < BowerVendor::Base
2
+ def execute
3
+ script = executable
4
+ puts "excutable: #{script}"
6
5
 
7
- Dir.chdir(work_dir) do
8
- fork do
9
- exec "#{script} install"
10
- end
11
- Process.wait
6
+ Dir.chdir(work_dir) do
7
+ fork do
8
+ exec "#{script} install"
12
9
  end
10
+ Process.wait
13
11
  end
12
+ end
14
13
 
15
- def executable
16
- f = "#{local_node_bin}/bower"
17
- File.exists?(f) ? f : 'bower'
18
- end
14
+ def executable
15
+ f = "#{local_node_bin}/bower"
16
+ File.exists?(f) ? f : 'bower'
19
17
  end
20
18
  end
@@ -1,7 +1,5 @@
1
- module BowerVendor
2
- class Railtie < Rails::Railtie
3
- rake_tasks do
4
- BowerVendor.load_tasks
5
- end
1
+ class BowerVendor::Railtie < Rails::Railtie
2
+ rake_tasks do
3
+ BowerVendor.load_tasks
6
4
  end
7
5
  end