vendorer 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Readme.md +10 -3
- data/lib/vendorer/version.rb +1 -1
- data/lib/vendorer.rb +33 -12
- data/spec/vendorer_spec.rb +173 -76
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -20,23 +20,30 @@ Add a `Vendorfile` to your project root:
|
|
20
20
|
# execute a block after updates
|
21
21
|
file 'public/javascripts/jquery.js', 'http://code.jquery.com/jquery.js' do |path|
|
22
22
|
puts "Do something useful with #{path}"
|
23
|
+
rewrite(path){|content| content.gsub(/\r\n/,\n).gsub(/\t/,' ') }
|
23
24
|
end
|
24
25
|
|
25
26
|
# checkout a specific :ref/:tag/:branch
|
26
27
|
folder 'vendor/plugins/parallel_tests', 'https://github.com/grosser/parallel_tests.git', :tag => 'v0.6.10'
|
27
28
|
|
29
|
+
# DRY folders
|
30
|
+
folder 'public/javascripts' do
|
31
|
+
file 'jquery.js', 'http://code.jquery.com/jquery-latest.js'
|
32
|
+
end
|
33
|
+
|
28
34
|
Call `vendorer`
|
29
35
|
|
30
36
|
If you added something new: `vendorer`
|
31
37
|
|
32
|
-
|
38
|
+
Update all dependencies: `vendorer update`
|
39
|
+
|
40
|
+
Update one dependencies: `vendorer update public/javascripts/jquery.min.js`
|
33
41
|
|
34
|
-
|
42
|
+
Update everything in a folder: `vendorer update public/javascripts`
|
35
43
|
|
36
44
|
|
37
45
|
TODO
|
38
46
|
====
|
39
|
-
- `folder 'vendor' do` which will remove everything that is not vendored via Vendorfile on `vendorer update` or `vendorer update vendor`
|
40
47
|
- nice error message when no Vendorfile was found
|
41
48
|
|
42
49
|
Author
|
data/lib/vendorer/version.rb
CHANGED
data/lib/vendorer.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
1
3
|
class Vendorer
|
2
4
|
def initialize(options)
|
3
5
|
@options = options
|
6
|
+
@sub_path = []
|
4
7
|
eval(File.read('Vendorfile'))
|
5
8
|
end
|
6
9
|
|
7
|
-
private
|
8
|
-
|
9
10
|
def file(path, url)
|
11
|
+
path = complete_path(path)
|
10
12
|
update_or_not path do
|
11
13
|
run "mkdir -p #{File.dirname(path)}"
|
12
14
|
run "curl '#{url}' -o #{path}"
|
@@ -15,23 +17,38 @@ class Vendorer
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
def folder(path, url, options={})
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
run "
|
20
|
+
def folder(path, url=nil, options={})
|
21
|
+
if url
|
22
|
+
path = complete_path(path)
|
23
|
+
update_or_not path do
|
24
|
+
run "rm -rf #{path}"
|
25
|
+
run "mkdir -p #{File.dirname(path)}"
|
26
|
+
run "git clone '#{url}' #{path}"
|
27
|
+
if commit = (options[:ref] || options[:tag] || options[:branch])
|
28
|
+
run "cd #{path} && git checkout '#{commit}'"
|
29
|
+
end
|
30
|
+
run "rm -rf #{path}/.git"
|
31
|
+
yield path if block_given?
|
24
32
|
end
|
25
|
-
|
26
|
-
|
33
|
+
else
|
34
|
+
@sub_path << path
|
35
|
+
yield
|
36
|
+
@sub_path.pop
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
40
|
+
def rewrite(path)
|
41
|
+
content = File.read(path)
|
42
|
+
result = yield content
|
43
|
+
File.open(path,'w'){|f| f.write(result) }
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
30
48
|
def update_or_not(path)
|
31
|
-
update_requested = (@options[:update] and (@options[:update] == true or @options[:update] ==
|
49
|
+
update_requested = (@options[:update] and (@options[:update] == true or path.start_with?(@options[:update]+'/') or path == @options[:update]))
|
32
50
|
if update_requested or not File.exist?(path)
|
33
51
|
puts "updating #{path}"
|
34
|
-
run "rm -rf #{path}"
|
35
52
|
yield
|
36
53
|
else
|
37
54
|
puts "keeping #{path}"
|
@@ -47,4 +64,8 @@ class Vendorer
|
|
47
64
|
end
|
48
65
|
raise output unless $?.success?
|
49
66
|
end
|
67
|
+
|
68
|
+
def complete_path(path)
|
69
|
+
(@sub_path + [path]).join('/')
|
70
|
+
end
|
50
71
|
end
|
data/spec/vendorer_spec.rb
CHANGED
@@ -22,11 +22,17 @@ describe Vendorer do
|
|
22
22
|
File.size("spec/tmp/#{file}")
|
23
23
|
end
|
24
24
|
|
25
|
+
def run(cmd)
|
26
|
+
result = `cd spec/tmp && #{cmd} 2>&1`
|
27
|
+
raise result unless $?.success?
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
25
31
|
def ls(path)
|
26
32
|
`ls spec/tmp/#{path} 2>&1`.split("\n")
|
27
33
|
end
|
28
34
|
|
29
|
-
def
|
35
|
+
def vendorer(args='', options={})
|
30
36
|
out = `cd spec/tmp && bundle exec ../../bin/vendorer #{args} 2>&1`
|
31
37
|
raise out if $?.success? == !!options[:raise]
|
32
38
|
out
|
@@ -38,70 +44,95 @@ describe Vendorer do
|
|
38
44
|
end
|
39
45
|
|
40
46
|
it "shows its version via -v" do
|
41
|
-
|
47
|
+
vendorer('-v').should == "#{Vendorer::VERSION}\n"
|
42
48
|
end
|
43
49
|
|
44
50
|
it "shows its version via --version" do
|
45
|
-
|
51
|
+
vendorer('--version').should == "#{Vendorer::VERSION}\n"
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
55
|
describe 'help' do
|
50
56
|
it "shows help via -h" do
|
51
|
-
|
57
|
+
vendorer('-h').should include("Usage")
|
52
58
|
end
|
53
59
|
|
54
60
|
it "shows help via --help" do
|
55
|
-
|
61
|
+
vendorer('--help').should include("Usage")
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
59
65
|
describe '.file' do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
run
|
64
|
-
end
|
66
|
+
def simple_vendorfile
|
67
|
+
write 'Vendorfile', "file 'public/javascripts/jquery.min.js', 'http://code.jquery.com/jquery-latest.min.js'"
|
68
|
+
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
it "can download a new file" do
|
71
|
+
simple_vendorfile
|
72
|
+
vendorer
|
73
|
+
ls('public/javascripts').should == ["jquery.min.js"]
|
74
|
+
read('public/javascripts/jquery.min.js').should include('jQuery')
|
75
|
+
end
|
70
76
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
77
|
+
it "does not update an existing file" do
|
78
|
+
simple_vendorfile
|
79
|
+
vendorer
|
80
|
+
write('public/javascripts/jquery.min.js', 'Foo')
|
81
|
+
vendorer
|
82
|
+
read('public/javascripts/jquery.min.js').should == 'Foo'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "fails with a nice message if the Vendorfile is broken" do
|
86
|
+
write 'Vendorfile', "file 'xxx.js', 'http://NOTFOUND'"
|
87
|
+
result = vendorer '', :raise => true
|
88
|
+
# different errors on travis / local
|
89
|
+
raise result unless result.include?("resolve host 'NOTFOUND'") or result.include?('Downloaded empty file')
|
90
|
+
end
|
76
91
|
|
77
|
-
|
92
|
+
describe "with update" do
|
93
|
+
it "updates all files when update is called" do
|
94
|
+
simple_vendorfile
|
95
|
+
vendorer
|
78
96
|
write('public/javascripts/jquery.min.js', 'Foo')
|
79
|
-
|
97
|
+
vendorer 'update'
|
80
98
|
read('public/javascripts/jquery.min.js').should include('jQuery')
|
81
99
|
end
|
82
100
|
|
83
|
-
|
84
|
-
|
85
|
-
|
101
|
+
context "with multiple files" do
|
102
|
+
before do
|
103
|
+
write 'Vendorfile', "
|
86
104
|
file 'public/javascripts/jquery.js', 'http://code.jquery.com/jquery-latest.js'
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
105
|
+
file 'public/javascripts/jquery.js.min', 'http://code.jquery.com/jquery-latest.min.js'
|
106
|
+
"
|
107
|
+
vendorer
|
108
|
+
read('public/javascripts/jquery.js').should include('jQuery')
|
109
|
+
read('public/javascripts/jquery.js.min').should include('jQuery')
|
110
|
+
|
111
|
+
write('public/javascripts/jquery.js', 'Foo')
|
112
|
+
write('public/javascripts/jquery.js.min', 'Foo')
|
113
|
+
end
|
114
|
+
|
115
|
+
it "updates a single file when update is called with the file" do
|
116
|
+
vendorer 'update public/javascripts/jquery.js.min'
|
117
|
+
size('public/javascripts/jquery.js.min').should > 300
|
118
|
+
size('public/javascripts/jquery.js').should == 3
|
119
|
+
end
|
120
|
+
|
121
|
+
it "does not update a file that starts with the same path" do
|
122
|
+
vendorer 'update public/javascripts/jquery.js'
|
123
|
+
size('public/javascripts/jquery.js').should > 300
|
124
|
+
size('public/javascripts/jquery.js.min').should == 3
|
125
|
+
end
|
97
126
|
end
|
98
|
-
end
|
99
127
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
128
|
+
it "does not change file modes" do
|
129
|
+
simple_vendorfile
|
130
|
+
vendorer
|
131
|
+
run 'chmod 711 public/javascripts/jquery.min.js'
|
132
|
+
lambda{
|
133
|
+
vendorer 'update'
|
134
|
+
}.should_not change{ run('ls -l public/javascripts').split("\n") }
|
135
|
+
end
|
105
136
|
end
|
106
137
|
|
107
138
|
context "with a passed block" do
|
@@ -111,67 +142,70 @@ describe Vendorer do
|
|
111
142
|
end
|
112
143
|
|
113
144
|
it "runs the block after update" do
|
114
|
-
|
145
|
+
vendorer.should include(@output)
|
115
146
|
end
|
116
147
|
|
117
148
|
it "does not run the block when not updating" do
|
118
|
-
|
119
|
-
|
149
|
+
vendorer
|
150
|
+
vendorer.should_not include(@output)
|
120
151
|
end
|
121
152
|
end
|
122
153
|
end
|
123
154
|
|
124
155
|
describe '.folder' do
|
125
|
-
|
156
|
+
before do
|
157
|
+
write 'Vendorfile', "folder 'its_recursive', '../../.git'"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "can download from remote" do
|
126
161
|
write 'Vendorfile', "folder 'vendor/plugins/parallel_tests', 'https://github.com/grosser/parallel_tests.git'"
|
127
|
-
|
162
|
+
vendorer
|
128
163
|
ls('vendor/plugins').should == ["parallel_tests"]
|
129
164
|
read('vendor/plugins/parallel_tests/Gemfile').should include('parallel')
|
130
165
|
end
|
131
166
|
|
132
167
|
it "reports errors when the Vendorfile is broken" do
|
133
168
|
write 'Vendorfile', "folder 'vendor/plugins/parallel_tests', 'https://blob'"
|
134
|
-
output =
|
169
|
+
output = vendorer '', :raise => true
|
135
170
|
# different errors on travis / local
|
136
171
|
raise unless output.include?('Connection refused') or output.include?('resolve host')
|
137
172
|
end
|
138
173
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
it "can download" do
|
146
|
-
ls('').should == ["its_recursive", "Vendorfile"]
|
147
|
-
read('its_recursive/Gemfile').should include('rake')
|
148
|
-
end
|
174
|
+
it "can download from local" do
|
175
|
+
vendorer
|
176
|
+
ls('').should == ["its_recursive", "Vendorfile"]
|
177
|
+
read('its_recursive/Gemfile').should include('rake')
|
178
|
+
end
|
149
179
|
|
150
|
-
|
151
|
-
|
152
|
-
|
180
|
+
it "does not keep .git folder so everything can be checked in" do
|
181
|
+
vendorer
|
182
|
+
ls('its_recursive/.git').first.should include('cannot access')
|
183
|
+
end
|
153
184
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
185
|
+
it "does not update an existing folder" do
|
186
|
+
vendorer
|
187
|
+
write('its_recursive/Gemfile', 'Foo')
|
188
|
+
vendorer
|
189
|
+
read('its_recursive/Gemfile').should == 'Foo'
|
190
|
+
end
|
159
191
|
|
160
|
-
|
192
|
+
describe 'update' do
|
193
|
+
it "updates a folder" do
|
194
|
+
vendorer
|
161
195
|
write('its_recursive/Gemfile', 'Foo')
|
162
|
-
|
196
|
+
vendorer 'update'
|
163
197
|
read('its_recursive/Gemfile').should include('rake')
|
164
198
|
end
|
165
199
|
|
166
|
-
it "can update a
|
200
|
+
it "can update a specific folder" do
|
167
201
|
write 'Vendorfile', "
|
168
202
|
folder 'its_recursive', '../../.git'
|
169
203
|
folder 'its_really_recursive', '../../.git'
|
170
204
|
"
|
171
|
-
|
205
|
+
vendorer
|
172
206
|
write('its_recursive/Gemfile', 'Foo')
|
173
207
|
write('its_really_recursive/Gemfile', 'Foo')
|
174
|
-
|
208
|
+
vendorer 'update its_recursive'
|
175
209
|
size('its_really_recursive/Gemfile').should == 3
|
176
210
|
size('its_recursive/Gemfile').should > 30
|
177
211
|
end
|
@@ -180,37 +214,100 @@ describe Vendorer do
|
|
180
214
|
describe "git options" do
|
181
215
|
it "can checkout by :ref" do
|
182
216
|
write 'Vendorfile', "folder 'its_recursive', '../../.git', :ref => 'b1e6460'"
|
183
|
-
|
217
|
+
vendorer
|
184
218
|
read('its_recursive/Readme.md').should include('CODE EXAMPLE')
|
185
219
|
end
|
186
220
|
|
187
221
|
it "can checkout by :branch" do
|
188
222
|
write 'Vendorfile', "folder 'its_recursive', '../../.git', :branch => 'b1e6460'"
|
189
|
-
|
223
|
+
vendorer
|
190
224
|
read('its_recursive/Readme.md').should include('CODE EXAMPLE')
|
191
225
|
end
|
192
226
|
|
193
227
|
it "can checkout by :tag" do
|
194
228
|
write 'Vendorfile', "folder 'its_recursive', '../../.git', :tag => 'b1e6460'"
|
195
|
-
|
229
|
+
vendorer
|
196
230
|
read('its_recursive/Readme.md').should include('CODE EXAMPLE')
|
197
231
|
end
|
198
232
|
end
|
199
233
|
|
200
|
-
context "with
|
234
|
+
context "with an execute after update block" do
|
201
235
|
before do
|
202
236
|
write 'Vendorfile', "folder('its_recursive', '../../.git'){|path| puts 'THE PATH IS ' + path }"
|
203
237
|
@output = 'THE PATH IS its_recursive'
|
204
238
|
end
|
205
239
|
|
206
240
|
it "runs the block after update" do
|
207
|
-
|
241
|
+
vendorer.should include(@output)
|
208
242
|
end
|
209
243
|
|
210
244
|
it "does not run the block when not updating" do
|
211
|
-
|
212
|
-
|
245
|
+
vendorer
|
246
|
+
vendorer.should_not include(@output)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "with folder scoping" do
|
251
|
+
before do
|
252
|
+
write 'Vendorfile', "
|
253
|
+
folder 'public/javascripts' do
|
254
|
+
file 'jquery.js', 'http://code.jquery.com/jquery-latest.min.js'
|
255
|
+
end
|
256
|
+
"
|
257
|
+
end
|
258
|
+
|
259
|
+
it "can download a nested file" do
|
260
|
+
vendorer
|
261
|
+
read('public/javascripts/jquery.js').should include('jQuery')
|
262
|
+
end
|
263
|
+
|
264
|
+
it "can update a nested file" do
|
265
|
+
vendorer
|
266
|
+
write('public/javascripts/jquery.js','Foo')
|
267
|
+
vendorer 'update'
|
268
|
+
read('public/javascripts/jquery.js').should include('jQuery')
|
269
|
+
end
|
270
|
+
|
271
|
+
it "can update a whole folder" do
|
272
|
+
write 'Vendorfile', "
|
273
|
+
folder 'public/javascripts' do
|
274
|
+
file 'jquery.js', 'http://code.jquery.com/jquery-latest.min.js'
|
275
|
+
end
|
276
|
+
file 'xxx.js', 'http://code.jquery.com/jquery-latest.min.js'
|
277
|
+
"
|
278
|
+
vendorer
|
279
|
+
write('public/javascripts/jquery.js','Foo')
|
280
|
+
write('xxx.js','Foo')
|
281
|
+
vendorer 'update public/javascripts'
|
282
|
+
read('xxx.js').should == "Foo"
|
283
|
+
read('public/javascripts/jquery.js').should include('jQuery')
|
284
|
+
end
|
285
|
+
|
286
|
+
it "can be nested multiple times" do
|
287
|
+
write 'Vendorfile', "
|
288
|
+
folder 'public' do
|
289
|
+
folder 'javascripts' do
|
290
|
+
file 'jquery.js', 'http://code.jquery.com/jquery-latest.min.js'
|
291
|
+
end
|
292
|
+
end
|
293
|
+
"
|
294
|
+
vendorer
|
295
|
+
read('public/javascripts/jquery.js').should include('jQuery')
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe 'rewrite' do
|
301
|
+
it "can rewrite a file to change stuff" do
|
302
|
+
write "Vendorfile", "
|
303
|
+
file 'public/javascripts/jquery.min.js', 'http://code.jquery.com/jquery-latest.min.js' do |path|
|
304
|
+
rewrite(path){|content| content.gsub('j','h') }
|
213
305
|
end
|
306
|
+
"
|
307
|
+
vendorer
|
308
|
+
content = read('public/javascripts/jquery.min.js')[0..100]
|
309
|
+
content.should_not include('jQuery')
|
310
|
+
content.should include('hQuery')
|
214
311
|
end
|
215
312
|
end
|
216
313
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vendorer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: michael@grosser.it
|
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
44
|
version: '0'
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
hash:
|
47
|
+
hash: 138779027
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
segments:
|
55
55
|
- 0
|
56
|
-
hash:
|
56
|
+
hash: 138779027
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
59
|
rubygems_version: 1.8.10
|