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 +5 -5
- data/README.md +29 -1
- data/lib/bower_vendor.rb +1 -0
- data/lib/bower_vendor/base.rb +45 -47
- data/lib/bower_vendor/check.rb +13 -15
- data/lib/bower_vendor/clean.rb +6 -8
- data/lib/bower_vendor/copy.rb +77 -79
- data/lib/bower_vendor/fetch.rb +12 -14
- data/lib/bower_vendor/railtie.rb +3 -5
- data/lib/bower_vendor/setup.rb +38 -40
- data/lib/bower_vendor/version.rb +1 -1
- data/lib/bower_vendor/yarn.rb +46 -0
- data/lib/tasks/bower_vendor.rake +6 -1
- data/package.json +6 -1
- data/vendor_yarn.yml +24 -0
- data/yarn.lock +1532 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b417d3edd915d7fde1d0881d3beda3307c347e6782e42a5d440dd0479578304
|
4
|
+
data.tar.gz: 4dd3926b2c96f3ba301f34b0b3cf3d223f30b2a4c181ad10a62f29a5b7bbcc1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/bower_vendor.rb
CHANGED
data/lib/bower_vendor/base.rb
CHANGED
@@ -1,60 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
1
|
+
class BowerVendor::Base
|
2
|
+
def initialize
|
3
|
+
end
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def vendors
|
6
|
+
@vendors ||= load_vendors
|
7
|
+
validate_vendors
|
8
|
+
@vendors
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def full_asset_key_src_dir(asset_key)
|
33
|
+
"#{self.work_dir}/bower_components/#{asset_key}"
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def work_dir
|
37
|
+
"#{self.root_dir}/tmp"
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def local_node_bin
|
41
|
+
"#{self.root_dir}/node_modules/.bin"
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
data/lib/bower_vendor/check.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
data/lib/bower_vendor/clean.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
1
|
+
class BowerVendor::Clean < BowerVendor::Base
|
2
|
+
def initialize
|
3
|
+
end
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/lib/bower_vendor/copy.rb
CHANGED
@@ -1,104 +1,102 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def run_build_scripts(asset_key, asset_data, level)
|
13
|
+
scripts = (asset_data['build'] || [])
|
14
|
+
return if scripts.empty?
|
16
15
|
|
17
|
-
|
16
|
+
src_dir = full_asset_key_src_dir(asset_key)
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
msg level, "building..."
|
19
|
+
scripts.each do |cmd|
|
20
|
+
msg level + 1, "cd #{src_dir} && #{cmd}"
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
74
|
+
base_dst_dir = self.dst_dirs[ext]
|
75
|
+
raise "NOT_FOUND_EXT: #{ext}" unless base_dst_dir
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
88
|
+
def dst_dirs
|
89
|
+
@dst_dirs ||= setup_dst_dirs
|
90
|
+
end
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
101
|
-
|
102
|
-
end
|
99
|
+
def msg(level, msg)
|
100
|
+
puts "#{' ' * level}#{msg}"
|
103
101
|
end
|
104
102
|
end
|
data/lib/bower_vendor/fetch.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
puts "excutable: #{script}"
|
1
|
+
class BowerVendor::Fetch < BowerVendor::Base
|
2
|
+
def execute
|
3
|
+
script = executable
|
4
|
+
puts "excutable: #{script}"
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
def executable
|
15
|
+
f = "#{local_node_bin}/bower"
|
16
|
+
File.exists?(f) ? f : 'bower'
|
19
17
|
end
|
20
18
|
end
|
data/lib/bower_vendor/railtie.rb
CHANGED