bpm 1.0.0.beta.6 → 1.0.0.beta.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG.md +26 -0
  2. data/TODO.md +0 -3
  3. data/lib/bpm/cli/base.rb +3 -3
  4. data/lib/bpm/default.json +5 -1
  5. data/lib/bpm/errors.rb +8 -0
  6. data/lib/bpm/generator.rb +8 -0
  7. data/lib/bpm/init_generator.rb +1 -1
  8. data/lib/bpm/package.rb +113 -11
  9. data/lib/bpm/pipeline/format_processor.rb +28 -0
  10. data/lib/bpm/pipeline/generated_asset.rb +2 -2
  11. data/lib/bpm/pipeline/package_pipeline.rb +79 -0
  12. data/lib/bpm/pipeline/plugin_asset.rb +7 -8
  13. data/lib/bpm/pipeline/plugin_processor.rb +52 -0
  14. data/lib/bpm/pipeline.rb +89 -26
  15. data/lib/bpm/project.rb +55 -29
  16. data/lib/bpm/version.rb +1 -1
  17. data/lib/bpm.rb +3 -1
  18. data/spec/cli/list_spec.rb +1 -0
  19. data/spec/cli/pack_spec.rb +125 -103
  20. data/spec/fixtures/projects/coffee/coffee.json +17 -0
  21. data/spec/fixtures/projects/coffee/index.html.handlebars +1 -0
  22. data/spec/fixtures/projects/coffee/lib/main.coffee +1 -0
  23. data/spec/fixtures/projects/coffee/packages/coffee-script/compiler.js +4 -0
  24. data/spec/fixtures/projects/coffee/packages/coffee-script/lib/main.js +1 -0
  25. data/spec/fixtures/projects/coffee/packages/coffee-script/package.json +15 -0
  26. data/spec/fixtures/projects/coffee/packages/handlebars/format.js +6 -0
  27. data/spec/fixtures/projects/coffee/packages/handlebars/lib/main.js +2 -0
  28. data/spec/fixtures/projects/coffee/packages/handlebars/package.json +16 -0
  29. data/spec/fixtures/projects/coffee/packages/spade/lib/main.js +1 -0
  30. data/spec/fixtures/projects/coffee/packages/spade/package.json +14 -0
  31. data/spec/fixtures/projects/coffee/packages/spade/transport.js +3 -0
  32. data/spec/fixtures/projects/coffee/templates/section.handlebars +1 -0
  33. data/spec/fixtures/projects/minitrans/packages/transport/package.json +5 -1
  34. data/spec/fixtures/projects/transporter/packages/transport/package.json +5 -1
  35. data/spec/package_pipeline_spec.rb +30 -0
  36. data/spec/package_spec.rb +328 -316
  37. data/spec/plugins/format_spec.rb +38 -0
  38. data/spec/plugins/transport_spec.rb +1 -1
  39. data/spec/support/matchers.rb +1 -2
  40. metadata +57 -24
data/spec/package_spec.rb CHANGED
@@ -1,308 +1,320 @@
1
1
  require "spec_helper"
2
2
 
3
- # describe BPM::Package do
4
- # it "should have 'lib' as default lib_path'" do
5
- # subject.send(:lib_path).should == 'lib'
6
- # end
7
- #
8
- # it "should have 'tests' as default tests_path'" do
9
- # subject.send(:tests_path).should == 'tests'
10
- # end
11
- # end
12
- #
13
- # describe BPM::Package, "#to_spec" do
14
- # let(:email) { "user@example.com" }
15
- #
16
- # before do
17
- # cd(home)
18
- # FileUtils.mkdir_p(home("lib"))
19
- # FileUtils.mkdir_p(home("resources"))
20
- # FileUtils.mkdir_p(home("tests"))
21
- # end
22
- #
23
- # subject do
24
- # package = BPM::Package.new(nil, email)
25
- # package.json_path = package_fixture("core-test", "package.json")
26
- # if spec = package.to_spec
27
- # spec
28
- # else
29
- # puts "Errors: #{package.errors}"
30
- # nil
31
- # end
32
- # end
33
- #
34
- # def expand_sort(files)
35
- # files.map { |f| File.expand_path(f) }.sort
36
- # end
37
- #
38
- # it "transforms the name" do
39
- # subject.name.should == "core-test"
40
- # end
41
- #
42
- # it "transforms the version" do
43
- # subject.version.should == LibGems::Version.new("0.4.9")
44
- # end
45
- #
46
- # it "transforms the author" do
47
- # subject.authors.should == ["Charles Jolley"]
48
- # end
49
- #
50
- # it "transforms the email" do
51
- # subject.email.should == email
52
- # end
53
- #
54
- # it "transforms the homepage" do
55
- # subject.homepage.should == "https://github.com/strobecorp/core-test"
56
- # end
57
- #
58
- # it "transforms the description" do
59
- # subject.description.should == "Flexible testing library for JavaScript."
60
- # end
61
- #
62
- # it "transforms the description" do
63
- # subject.summary.should == "A fully featured asynchronous testing library for JavaScript, compatible with other frameworks."
64
- # end
65
- #
66
- # it "transforms the dependencies" do
67
- # subject.dependencies.map{|d| [d.name, d.requirement]}.should == [["ivory", "= 0.0.1"], ["optparse", "= 1.0.1"]]
68
- # end
69
- #
70
- # it "packs metadata into requirements" do
71
- # metadata = JSON.parse(subject.requirements.first)
72
- # metadata["licenses"].should == [
73
- # {"type" => "MIT",
74
- # "url" => "https://github.com/strobecorp/core-test/raw/master/LICENSE"}
75
- # ]
76
- # metadata["engines"].should == ["browser", "all"]
77
- # metadata["main"].should == "./lib/main"
78
- # metadata["bin"].should == {"cot" => "./bin/cot"}
79
- # end
80
- #
81
- # it "expands paths from the directories and bpm:build" do
82
- # others = ["tmp/blah.js", "tmp/whee.txt"]
83
- # files = ["bin/cot", "lib/main.js", "lib/core.js", "lib/test.js", "package.json", "resources/additions.css", "resources/runner.css", "index.html", "extras/extra_file.html"]
84
- # test_files = ["tests/apis/core-test.js", "tests/system/test/assert-test.js"]
85
- #
86
- # FileUtils.mkdir_p(["bin/", "resources/", "lib/", "tests/apis", "tests/system/test", "tmp/", "extras/"])
87
- # FileUtils.touch(files + test_files + others)
88
- #
89
- # expand_sort(subject.files).should == expand_sort(files + test_files)
90
- # expand_sort(subject.test_files).should == expand_sort(test_files)
91
- # end
92
- #
93
- # it "hacks the file name to return .bpkg" do
94
- # subject.file_name.should == "core-test-0.4.9.bpkg"
95
- # end
96
- #
97
- # it "sets the rubyforge_project to appease older versions of rubygems" do
98
- # subject.rubyforge_project.should == "bpm"
99
- # end
100
- # end
101
- #
102
- # describe BPM::Package, "#to_s" do
103
- # let(:email) { "user@example.com" }
104
- #
105
- # subject do
106
- # package = BPM::Package.new
107
- # package.json_path = package_fixture("core-test","package.json")
108
- # package.valid?
109
- # package
110
- # end
111
- #
112
- # it "gives the name and version" do
113
- # subject.full_name.should == "core-test-0.4.9"
114
- # end
115
- # end
116
- #
117
- # describe BPM::Package, "converting" do
118
- # before do
119
- # cd(home)
120
- # end
121
- #
122
- # subject do
123
- # package = BPM::Package.new
124
- # package.fill_from_gemspec(fixtures('gems', "core-test-0.4.9.bpkg"))
125
- # package.as_json
126
- # end
127
- #
128
- # it "can recreate the same package.json from the package" do
129
- # # These don't come out in the same order
130
- # actual = Hash[subject.sort]
131
- # expected = Hash[JSON.parse(File.read(package_fixture("core-test", "package.json"))).sort].reject{|k,v| v.empty? }
132
- # actual.should == expected
133
- # end
134
- # end
135
- #
136
- # describe BPM::Package, "validating" do
137
- # before do
138
- # cd(home)
139
- # end
140
- #
141
- # subject { BPM::Package.new }
142
- #
143
- # shared_examples_for "a good parser" do
144
- # it "had a problem parsing package.json" do
145
- # subject.should have_error("There was a problem parsing package.json")
146
- # end
147
- # end
148
- #
149
- # context "with a blank file" do
150
- # before do
151
- # FileUtils.touch("package.json")
152
- # subject.json_path = "package.json"
153
- # end
154
- # it_should_behave_like "a good parser"
155
- # end
156
- #
157
- # context "with bad json" do
158
- # before do
159
- # File.open("package.json", "w") do |f|
160
- # f.write "---bad json---"
161
- # end
162
- # subject.json_path = "package.json"
163
- # end
164
- # it_should_behave_like "a good parser"
165
- # end
166
- #
167
- # context "json can't be read" do
168
- # before do
169
- # FileUtils.cp package_fixture("core-test", "package.json"), "."
170
- # FileUtils.chmod 0000, "package.json"
171
- # subject.json_path = "package.json"
172
- # end
173
- # it_should_behave_like "a good parser"
174
- # end
175
- #
176
- # context "json can't be found" do
177
- # before do
178
- # subject.json_path = "package.json"
179
- # end
180
- # it_should_behave_like "a good parser"
181
- # end
182
- #
183
- # end
184
- #
185
- # describe BPM::Package, "validation errors" do
186
- # let(:email) { "user@example.com" }
187
- #
188
- # before do
189
- # cd(home)
190
- # FileUtils.mkdir_p(home("lib"))
191
- # FileUtils.mkdir_p(home("tests"))
192
- # end
193
- #
194
- # subject do
195
- # BPM::Package.new(nil, email)
196
- # end
197
- #
198
- # def write_package
199
- # path = home("package.json")
200
- # package = JSON.parse(File.read(package_fixture("core-test","package.json")))
201
- # yield package
202
- # File.open(path, "w") do |file|
203
- # file.write package.to_json
204
- # end
205
- # subject.json_path = path
206
- # end
207
- #
208
- # %w[name description summary homepage author version directories].each do |field|
209
- # it "is invalid without a #{field} field" do
210
- # write_package do |package|
211
- # package.delete(field)
212
- # end
213
- #
214
- # subject.should have_error("Package requires a '#{field}' field")
215
- # end
216
- #
217
- # it "is invalid with a blank #{field} field" do
218
- # write_package do |package|
219
- # package[field] = ""
220
- # end
221
- #
222
- # subject.should have_error("Package requires a '#{field}' field")
223
- # end
224
- # end
225
- #
226
- # it "is invalid without a proper version number" do
227
- # write_package do |package|
228
- # package["version"] = "bad"
229
- # end
230
- #
231
- # subject.should have_error("Malformed version number string bad")
232
- # end
233
- #
234
- # it "is valid without specifying a test directory" do
235
- # write_package do |package|
236
- # package["directories"].delete("tests")
237
- # end
238
- #
239
- # subject.should be_valid
240
- # subject.to_spec.test_files.should == []
241
- # end
242
- #
243
- # it "is valid and has files without specifying bin" do
244
- # write_package do |package|
245
- # package.delete("bin")
246
- # end
247
- #
248
- # subject.should be_valid
249
- # subject.to_spec.files.should == ["package.json"]
250
- # end
251
- #
252
- # %w(lib tests).each do |dir|
253
- # it "is invalid if #{dir} points to a file" do
254
- # FileUtils.touch(home("somefile"))
255
- # write_package do |package|
256
- # package["directories"][dir] = "./somefile"
257
- # end
258
- #
259
- # subject.should have_error("'./somefile', specified for #{dir} directory, is not a directory")
260
- # end
261
- #
262
- # it "is invalid with a #{dir} directory that doesn't exist" do
263
- # write_package do |package|
264
- # package["directories"][dir] = "nope"
265
- # end
266
- #
267
- # subject.should have_error("'nope', specified for #{dir} directory, is not a directory")
268
- # end
269
- #
270
- # it "is valid with a #{dir} directory that exists" do
271
- # FileUtils.mkdir_p(home("somewhere", "else"))
272
- # write_package do |package|
273
- # package["directories"][dir] = "./somewhere/else"
274
- # end
275
- #
276
- # subject.should be_valid
277
- # end
278
- # end
279
- #
280
- # it "is valid with a lib directory array" do
281
- # FileUtils.mkdir_p(home("vendor/lib"))
282
- # write_package do |package|
283
- # package["directories"]["lib"] = ["./lib", "./vendor/lib"]
284
- # end
285
- #
286
- # subject.should be_valid
287
- # end
288
- #
289
- # it "is invalid if any lib directories don't exist" do
290
- # write_package do |package|
291
- # package["directories"]["lib"] = ["./lib", "./fake"]
292
- # end
293
- #
294
- # subject.should have_error "'./fake', specified for lib directory, is not a directory"
295
- # end
296
- #
297
- # it "is invalid if the lib directory array is empty" do
298
- # write_package do |package|
299
- # package["directories"]["lib"] = []
300
- # end
301
- #
302
- # subject.should have_error("A lib directory is required")
303
- # end
304
- #
305
- # end
3
+ describe BPM::Package do
4
+ it "should have 'lib' as default lib_path'" do
5
+ subject.send(:lib_path).should == 'lib'
6
+ end
7
+
8
+ it "should have 'tests' as default tests_path'" do
9
+ subject.send(:tests_path).should == 'tests'
10
+ end
11
+ end
12
+
13
+ describe BPM::Package, "#to_spec" do
14
+ let(:email) { "user@example.com" }
15
+
16
+ before do
17
+ FileUtils.mkdir_p(home("core-test", "lib"))
18
+ FileUtils.mkdir_p(home("core-test", "resources"))
19
+ FileUtils.mkdir_p(home("core-test", "tests"))
20
+ cd home('core-test')
21
+ end
22
+
23
+ subject do
24
+ package = BPM::Package.new(nil, email)
25
+ package.json_path = package_fixture("core-test", "package.json")
26
+ if spec = package.to_spec
27
+ spec
28
+ else
29
+ puts "Errors: #{package.errors}"
30
+ nil
31
+ end
32
+ end
33
+
34
+ def expand_sort(files)
35
+ files.map { |f| File.expand_path(f) }.sort
36
+ end
37
+
38
+ it "transforms the name" do
39
+ subject.name.should == "core-test"
40
+ end
41
+
42
+ it "transforms the version" do
43
+ subject.version.should == LibGems::Version.new("0.4.9")
44
+ end
45
+
46
+ it "transforms the author" do
47
+ subject.authors.should == ["Charles Jolley"]
48
+ end
49
+
50
+ it "transforms the email" do
51
+ subject.email.should == email
52
+ end
53
+
54
+ it "transforms the homepage" do
55
+ subject.homepage.should == "https://github.com/strobecorp/core-test"
56
+ end
57
+
58
+ it "transforms the description" do
59
+ subject.description.should == "Flexible testing library for JavaScript."
60
+ end
61
+
62
+ it "transforms the description" do
63
+ subject.summary.should == "A fully featured asynchronous testing library for JavaScript, compatible with other frameworks."
64
+ end
65
+
66
+ it "transforms the dependencies" do
67
+ subject.dependencies.map{|d| [d.name, d.requirement]}.should == [["ivory", "= 0.0.1"], ["optparse", "= 1.0.1"]]
68
+ end
69
+
70
+ it "packs metadata into requirements" do
71
+ metadata = JSON.parse(subject.requirements.first)
72
+ metadata["licenses"].should == [
73
+ {"type" => "MIT",
74
+ "url" => "https://github.com/strobecorp/core-test/raw/master/LICENSE"}
75
+ ]
76
+ metadata["engines"].should == ["browser", "all"]
77
+ metadata["main"].should == "./lib/main"
78
+ metadata["bin"].should == {"cot" => "./bin/cot"}
79
+ end
80
+
81
+ it "expands paths from the directories and bpm:build" do
82
+ others = ["tmp/blah.js", "tmp/whee.txt"]
83
+ files = ["bin/cot", "lib/main.js", "lib/core.js", "lib/test.js", "package.json", "resources/additions.css", "resources/runner.css", "index.html", "extras/extra_file.html"]
84
+ test_files = ["tests/apis/core-test.js", "tests/system/test/assert-test.js"]
85
+
86
+ FileUtils.mkdir_p(["bin/", "resources/", "lib/", "tests/apis", "tests/system/test", "tmp/", "extras/"])
87
+ FileUtils.touch(files + test_files + others)
88
+
89
+ expand_sort(subject.files).should == expand_sort(files + test_files)
90
+ expand_sort(subject.test_files).should == expand_sort(test_files)
91
+ end
92
+
93
+ it "hacks the file name to return .bpkg" do
94
+ subject.file_name.should == "core-test-0.4.9.bpkg"
95
+ end
96
+
97
+ it "sets the rubyforge_project to appease older versions of rubygems" do
98
+ subject.rubyforge_project.should == "bpm"
99
+ end
100
+ end
101
+
102
+ describe BPM::Package, "#to_s" do
103
+ let(:email) { "user@example.com" }
104
+
105
+ subject do
106
+ package = BPM::Package.new package_fixture('core-test')
107
+ package.valid?
108
+ package
109
+ end
110
+
111
+ it "gives the name and version" do
112
+ subject.full_name.should == "core-test-0.4.9"
113
+ end
114
+ end
115
+
116
+ describe BPM::Package, "converting" do
117
+ before do
118
+ cd(home)
119
+ end
120
+
121
+ subject do
122
+ package = BPM::Package.new
123
+ package.fill_from_gemspec(fixtures('gems', "core-test-0.4.9.bpkg"))
124
+ package.as_json
125
+ end
126
+
127
+ it "can recreate the same package.json from the package" do
128
+ # These don't come out in the same order
129
+ actual = Hash[subject.sort]
130
+ expected = Hash[JSON.parse(File.read(package_fixture("core-test", "package.json"))).sort].reject{|k,v| v.empty? }
131
+ actual.should == expected
132
+ end
133
+ end
134
+
135
+ describe BPM::Package, "validating" do
136
+ before do
137
+ FileUtils.mkdir_p home('core-test')
138
+ cd home('core-test')
139
+ end
140
+
141
+ subject { BPM::Package.new }
142
+
143
+ shared_examples_for "a good parser" do
144
+ it "had a problem parsing package.json" do
145
+ lambda {
146
+ subject.load_json
147
+ }.should raise_error
148
+ end
149
+ end
150
+
151
+ context "with a blank file" do
152
+ before do
153
+ FileUtils.touch("package.json")
154
+ subject.json_path = "package.json"
155
+ end
156
+ it_should_behave_like "a good parser"
157
+ end
158
+
159
+ context "with bad json" do
160
+ before do
161
+ File.open("package.json", "w") do |f|
162
+ f.write "---bad json---"
163
+ end
164
+ subject.json_path = "package.json"
165
+ end
166
+ it_should_behave_like "a good parser"
167
+ end
168
+
169
+ context "json can't be read" do
170
+ before do
171
+ FileUtils.cp package_fixture("core-test", "package.json"), "."
172
+ FileUtils.chmod 0000, "package.json"
173
+ subject.json_path = "package.json"
174
+ end
175
+ it_should_behave_like "a good parser"
176
+ end
177
+
178
+ context "json can't be found" do
179
+ before do
180
+ subject.json_path = "package.json"
181
+ end
182
+ it_should_behave_like "a good parser"
183
+ end
184
+
185
+ end
186
+
187
+ describe BPM::Package, "validation errors" do
188
+ let(:email) { "user@example.com" }
189
+
190
+ before do
191
+ FileUtils.mkdir_p home("core-test", "lib")
192
+ FileUtils.mkdir_p home("core-test", "tests")
193
+ cd home("core-test")
194
+ end
195
+
196
+ subject do
197
+ BPM::Package.new(nil, email)
198
+ end
199
+
200
+ def write_package
201
+ path = home("core-test", "package.json")
202
+ package = JSON.parse(File.read(package_fixture("core-test","package.json")))
203
+ yield package
204
+ File.open(path, "w") do |file|
205
+ file.write package.to_json
206
+ end
207
+ subject.json_path = path
208
+ end
209
+
210
+ %w[name description summary homepage author version].each do |field|
211
+ it "is invalid without a #{field} field" do
212
+ write_package do |package|
213
+ if %w(description summary).include?(field)
214
+ package.delete 'description'
215
+ package.delete 'summary'
216
+ else
217
+ package.delete(field)
218
+ end
219
+ end
220
+
221
+ subject.should have_error("Package requires a '#{field}' field")
222
+ end
223
+
224
+ it "is invalid with a blank #{field} field" do
225
+ write_package do |package|
226
+ if %w(description summary).include?(field)
227
+ package['description'] = package['summary'] = ''
228
+ else
229
+ package[field] = ''
230
+ end
231
+ end
232
+
233
+ subject.should have_error("Package requires a '#{field}' field")
234
+ end
235
+ end
236
+
237
+ it "is invalid without a proper version number" do
238
+ write_package do |package|
239
+ package["version"] = "bad"
240
+ end
241
+
242
+ subject.should have_error("Malformed version number string bad")
243
+ end
244
+
245
+ it "is valid without specifying a test directory" do
246
+ write_package do |package|
247
+ package["directories"].delete("tests")
248
+ end
249
+
250
+ subject.should be_valid
251
+ subject.to_spec.test_files.should == []
252
+ end
253
+
254
+ it "is valid and has files without specifying bin" do
255
+ write_package do |package|
256
+ package.delete("bin")
257
+ end
258
+
259
+ subject.should be_valid
260
+ subject.to_spec.files.should == ["package.json"]
261
+ end
262
+
263
+ %w(lib tests).each do |dir|
264
+ it "is invalid if #{dir} points to a file" do
265
+ FileUtils.touch(home("core-test", "somefile"))
266
+ write_package do |package|
267
+ package["directories"][dir] = "./somefile"
268
+ end
269
+
270
+ subject.should have_error("'./somefile', specified for #{dir} directory, is not a directory")
271
+ end
272
+
273
+ it "is invalid with a #{dir} directory that doesn't exist" do
274
+ write_package do |package|
275
+ package["directories"][dir] = "nope"
276
+ end
277
+
278
+ subject.should have_error("'nope', specified for #{dir} directory, is not a directory")
279
+ end
280
+
281
+ it "is valid with a #{dir} directory that exists" do
282
+ FileUtils.mkdir_p(home("core-test", "somewhere", "else"))
283
+ write_package do |package|
284
+ package["directories"][dir] = "./somewhere/else"
285
+ end
286
+
287
+ subject.should be_valid
288
+ end
289
+ end
290
+
291
+ it "is valid with a lib directory array" do
292
+ FileUtils.mkdir_p(home("core-test", "vendor", "lib"))
293
+ write_package do |package|
294
+ package["directories"]["lib"] = ["./lib", "./vendor/lib"]
295
+ end
296
+
297
+ subject.valid?
298
+ subject.should be_valid
299
+ end
300
+
301
+ it "is invalid if any lib directories don't exist" do
302
+ write_package do |package|
303
+ package["directories"]["lib"] = ["./lib", "./fake"]
304
+ end
305
+
306
+ subject.should have_error "'./fake', specified for lib directory, is not a directory"
307
+ end
308
+
309
+ it "is invalid if the lib directory array is empty" do
310
+ write_package do |package|
311
+ package["directories"]["lib"] = []
312
+ end
313
+
314
+ subject.should have_error("A lib directory is required")
315
+ end
316
+
317
+ end
306
318
 
307
319
  describe BPM::Package, 'InvalidPackageError' do
308
320
 
@@ -332,16 +344,16 @@ describe BPM::Package, 'InvalidPackageError' do
332
344
 
333
345
  end
334
346
 
335
- # describe BPM::Package, "templates" do
336
- #
337
- # subject do
338
- # package = BPM::Package.new(package_fixture("custom_generator"))
339
- # package.load_json
340
- # package
341
- # end
342
- #
343
- # it "should have project template" do
344
- # subject.template_path('project').should == package_fixture("custom_generator", "templates", "project").to_s
345
- # end
346
- #
347
- # end
347
+ describe BPM::Package, "templates" do
348
+
349
+ subject do
350
+ package = BPM::Package.new(package_fixture("custom_generator"))
351
+ package.load_json
352
+ package
353
+ end
354
+
355
+ it "should have project template" do
356
+ subject.template_path('project').should == package_fixture("custom_generator", "templates", "project").to_s
357
+ end
358
+
359
+ end