rake-pipeline-fork 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/.yardopts +2 -0
- data/GETTING_STARTED.md +268 -0
- data/Gemfile +14 -0
- data/LICENSE +20 -0
- data/README.markdown +11 -0
- data/README.yard +178 -0
- data/Rakefile +21 -0
- data/bin/rakep +4 -0
- data/examples/copying_files.md +12 -0
- data/examples/minifying_files.md +37 -0
- data/examples/modifying_pipelines.md +67 -0
- data/examples/multiple_pipelines.md +77 -0
- data/lib/generators/rake/pipeline/install/install_generator.rb +70 -0
- data/lib/rake-pipeline.rb +462 -0
- data/lib/rake-pipeline/cli.rb +56 -0
- data/lib/rake-pipeline/dsl.rb +9 -0
- data/lib/rake-pipeline/dsl/pipeline_dsl.rb +246 -0
- data/lib/rake-pipeline/dsl/project_dsl.rb +108 -0
- data/lib/rake-pipeline/dynamic_file_task.rb +194 -0
- data/lib/rake-pipeline/error.rb +17 -0
- data/lib/rake-pipeline/file_wrapper.rb +182 -0
- data/lib/rake-pipeline/filter.rb +249 -0
- data/lib/rake-pipeline/filters.rb +4 -0
- data/lib/rake-pipeline/filters/concat_filter.rb +63 -0
- data/lib/rake-pipeline/filters/gsub_filter.rb +56 -0
- data/lib/rake-pipeline/filters/ordering_concat_filter.rb +38 -0
- data/lib/rake-pipeline/filters/pipeline_finalizing_filter.rb +21 -0
- data/lib/rake-pipeline/graph.rb +178 -0
- data/lib/rake-pipeline/manifest.rb +86 -0
- data/lib/rake-pipeline/manifest_entry.rb +34 -0
- data/lib/rake-pipeline/matcher.rb +141 -0
- data/lib/rake-pipeline/middleware.rb +72 -0
- data/lib/rake-pipeline/precompile.rake +8 -0
- data/lib/rake-pipeline/project.rb +335 -0
- data/lib/rake-pipeline/rails_plugin.rb +10 -0
- data/lib/rake-pipeline/railtie.rb +34 -0
- data/lib/rake-pipeline/reject_matcher.rb +29 -0
- data/lib/rake-pipeline/server.rb +15 -0
- data/lib/rake-pipeline/sorted_pipeline.rb +19 -0
- data/lib/rake-pipeline/version.rb +6 -0
- data/rails/init.rb +2 -0
- data/rake-pipeline.gemspec +24 -0
- data/spec/cli_spec.rb +71 -0
- data/spec/concat_filter_spec.rb +37 -0
- data/spec/dsl/pipeline_dsl_spec.rb +165 -0
- data/spec/dsl/project_dsl_spec.rb +41 -0
- data/spec/dynamic_file_task_spec.rb +119 -0
- data/spec/encoding_spec.rb +106 -0
- data/spec/file_wrapper_spec.rb +132 -0
- data/spec/filter_spec.rb +332 -0
- data/spec/graph_spec.rb +56 -0
- data/spec/gsub_filter_spec.rb +87 -0
- data/spec/manifest_entry_spec.rb +46 -0
- data/spec/manifest_spec.rb +67 -0
- data/spec/matcher_spec.rb +141 -0
- data/spec/middleware_spec.rb +199 -0
- data/spec/ordering_concat_filter_spec.rb +42 -0
- data/spec/pipeline_spec.rb +232 -0
- data/spec/project_spec.rb +295 -0
- data/spec/rake_acceptance_spec.rb +738 -0
- data/spec/rake_tasks_spec.rb +21 -0
- data/spec/reject_matcher_spec.rb +31 -0
- data/spec/sorted_pipeline_spec.rb +27 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/spec_helpers/file_utils.rb +35 -0
- data/spec/support/spec_helpers/filters.rb +37 -0
- data/spec/support/spec_helpers/input_helpers.rb +23 -0
- data/spec/support/spec_helpers/memory_file_wrapper.rb +31 -0
- data/spec/support/spec_helpers/memory_manifest.rb +19 -0
- data/tools/perfs +101 -0
- metadata +215 -0
@@ -0,0 +1,738 @@
|
|
1
|
+
require "rake-pipeline/filters"
|
2
|
+
|
3
|
+
describe "A realistic project" do
|
4
|
+
|
5
|
+
INPUTS = {
|
6
|
+
|
7
|
+
"app/javascripts/jquery.js" => <<-HERE,
|
8
|
+
var jQuery = {};
|
9
|
+
HERE
|
10
|
+
|
11
|
+
"app/javascripts/sproutcore.js" => <<-HERE,
|
12
|
+
var SC = {};
|
13
|
+
assert(SC);
|
14
|
+
SC.hi = function() { console.log("hi"); };
|
15
|
+
HERE
|
16
|
+
|
17
|
+
"app/stylesheets/jquery.css" => <<-HERE,
|
18
|
+
#jquery {
|
19
|
+
color: red;
|
20
|
+
}
|
21
|
+
HERE
|
22
|
+
|
23
|
+
"app/stylesheets/sproutcore.css" => <<-HERE,
|
24
|
+
#sproutcore {
|
25
|
+
color: green;
|
26
|
+
}
|
27
|
+
HERE
|
28
|
+
|
29
|
+
"app/index.html" => <<-HERE,
|
30
|
+
<html></html>
|
31
|
+
HERE
|
32
|
+
|
33
|
+
"app/junk.txt" => <<-HERE,
|
34
|
+
junk
|
35
|
+
HERE
|
36
|
+
|
37
|
+
"app/main.dynamic" => <<-HERE,
|
38
|
+
# main.dynamic
|
39
|
+
static content
|
40
|
+
@import("variables")
|
41
|
+
HERE
|
42
|
+
|
43
|
+
"variables.import" => <<-HERE,
|
44
|
+
$rakep = awesome
|
45
|
+
HERE
|
46
|
+
}
|
47
|
+
|
48
|
+
EXPECTED_JS_OUTPUT = <<-HERE
|
49
|
+
var jQuery = {};
|
50
|
+
var SC = {};
|
51
|
+
|
52
|
+
SC.hi = function() { console.log("hi"); };
|
53
|
+
HERE
|
54
|
+
|
55
|
+
EXPECTED_CSS_OUTPUT = <<-HERE
|
56
|
+
#jquery {
|
57
|
+
color: red;
|
58
|
+
}
|
59
|
+
#sproutcore {
|
60
|
+
color: green;
|
61
|
+
}
|
62
|
+
HERE
|
63
|
+
|
64
|
+
EXPECTED_HTML_OUTPUT = <<-HERE
|
65
|
+
<html></html>
|
66
|
+
HERE
|
67
|
+
|
68
|
+
EXPECTED_DYNAMIC_OUTPUT = <<-HERE
|
69
|
+
# main.dynamic
|
70
|
+
static content
|
71
|
+
@import("variables")
|
72
|
+
$rakep = awesome
|
73
|
+
HERE
|
74
|
+
|
75
|
+
def input_wrapper(path)
|
76
|
+
Rake::Pipeline::FileWrapper.new(tmp, path)
|
77
|
+
end
|
78
|
+
|
79
|
+
def output_should_exist(expected = EXPECTED_JS_OUTPUT)
|
80
|
+
output = File.join(tmp, "public/javascripts/application.js")
|
81
|
+
temp = File.join(tmp, "temporary")
|
82
|
+
|
83
|
+
File.exists?(output).should be_true
|
84
|
+
File.exists?(temp).should be_true
|
85
|
+
|
86
|
+
File.read(output).should == expected
|
87
|
+
end
|
88
|
+
|
89
|
+
concat_filter = Rake::Pipeline::ConcatFilter
|
90
|
+
dynamic_import_filter = Rake::Pipeline::SpecHelpers::Filters::DynamicImportFilter
|
91
|
+
strip_asserts_filter = Rake::Pipeline::SpecHelpers::Filters::StripAssertsFilter
|
92
|
+
memory_manifest = Rake::Pipeline::SpecHelpers::MemoryManifest
|
93
|
+
|
94
|
+
def copy_files
|
95
|
+
INPUTS.each do |name, string|
|
96
|
+
mkdir_p File.dirname(File.join(tmp, name))
|
97
|
+
File.open(File.join(tmp, name), "w") { |file| file.write(string) }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def delete_files
|
102
|
+
FileUtils.rm_rf File.join(tmp, "app/javascripts/jquery.js")
|
103
|
+
end
|
104
|
+
|
105
|
+
before do
|
106
|
+
Rake.application = Rake::Application.new
|
107
|
+
copy_files
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "a pipeline" do
|
111
|
+
it "can successfully apply filters" do
|
112
|
+
concat = concat_filter.new
|
113
|
+
concat.manifest = memory_manifest.new
|
114
|
+
concat.last_manifest = memory_manifest.new
|
115
|
+
concat.input_files = INPUTS.keys.select { |key| key =~ /javascript/ }.map { |file| input_wrapper(file) }
|
116
|
+
concat.output_root = File.join(tmp, "temporary", "concat_filter")
|
117
|
+
concat.output_name_generator = proc { |input| "javascripts/application.js" }
|
118
|
+
|
119
|
+
strip_asserts = strip_asserts_filter.new
|
120
|
+
strip_asserts.manifest = memory_manifest.new
|
121
|
+
strip_asserts.last_manifest = memory_manifest.new
|
122
|
+
strip_asserts.input_files = concat.output_files
|
123
|
+
strip_asserts.output_root = File.join(tmp, "public")
|
124
|
+
strip_asserts.output_name_generator = proc { |input| input }
|
125
|
+
|
126
|
+
concat.generate_rake_tasks
|
127
|
+
Rake::Task.define_task(:default => strip_asserts.generate_rake_tasks)
|
128
|
+
Rake.application[:default].invoke
|
129
|
+
|
130
|
+
output_should_exist
|
131
|
+
end
|
132
|
+
|
133
|
+
it "supports filters with multiple outputs per input" do
|
134
|
+
concat = concat_filter.new
|
135
|
+
concat.manifest = memory_manifest.new
|
136
|
+
concat.last_manifest = memory_manifest.new
|
137
|
+
concat.input_files = INPUTS.keys.select { |key| key =~ /javascript/ }.map { |file| input_wrapper(file) }
|
138
|
+
concat.output_root = File.join(tmp, "temporary", "concat_filter")
|
139
|
+
concat.output_name_generator = proc { |input| [ "javascripts/application.js", input.sub(/^app\//, '') ] }
|
140
|
+
|
141
|
+
strip_asserts = strip_asserts_filter.new
|
142
|
+
strip_asserts.manifest = memory_manifest.new
|
143
|
+
strip_asserts.last_manifest = memory_manifest.new
|
144
|
+
strip_asserts.input_files = concat.output_files
|
145
|
+
strip_asserts.output_root = File.join(tmp, "public")
|
146
|
+
strip_asserts.output_name_generator = proc { |input| input }
|
147
|
+
|
148
|
+
concat.generate_rake_tasks
|
149
|
+
Rake::Task.define_task(:default => strip_asserts.generate_rake_tasks)
|
150
|
+
Rake.application[:default].invoke
|
151
|
+
|
152
|
+
output_should_exist
|
153
|
+
|
154
|
+
expected_files = {
|
155
|
+
"javascripts/jquery.js" => "var jQuery = {};\n",
|
156
|
+
"javascripts/sproutcore.js" => "var SC = {};\n\nSC.hi = function() { console.log(\"hi\"); };\n"
|
157
|
+
}
|
158
|
+
|
159
|
+
expected_files.each do |file, expected|
|
160
|
+
output_file = File.join(tmp, "public", file)
|
161
|
+
output = nil
|
162
|
+
|
163
|
+
lambda { output = File.read(output_file) }.should_not raise_error
|
164
|
+
output.should == expected
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
it "can be configured using the pipeline" do
|
169
|
+
pipeline = Rake::Pipeline.new
|
170
|
+
pipeline.project = Rake::Pipeline::Project.new
|
171
|
+
pipeline.add_input tmp, 'app/javascripts/*.js'
|
172
|
+
pipeline.output_root = File.expand_path("public")
|
173
|
+
pipeline.tmpdir = "temporary"
|
174
|
+
|
175
|
+
concat = concat_filter.new
|
176
|
+
concat.manifest = memory_manifest.new
|
177
|
+
concat.last_manifest = memory_manifest.new
|
178
|
+
concat.output_name_generator = proc { |input| "javascripts/application.js" }
|
179
|
+
|
180
|
+
strip_asserts = strip_asserts_filter.new
|
181
|
+
strip_asserts.manifest = memory_manifest.new
|
182
|
+
strip_asserts.last_manifest = memory_manifest.new
|
183
|
+
strip_asserts.output_name_generator = proc { |input| input }
|
184
|
+
|
185
|
+
pipeline.add_filters(concat, strip_asserts)
|
186
|
+
pipeline.invoke
|
187
|
+
|
188
|
+
output_should_exist
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "using the pipeline DSL" do
|
194
|
+
attr_reader :project
|
195
|
+
|
196
|
+
shared_examples_for "the pipeline DSL" do
|
197
|
+
it "can be configured using the pipeline DSL" do
|
198
|
+
project.invoke
|
199
|
+
output_should_exist
|
200
|
+
end
|
201
|
+
|
202
|
+
it "can be configured using the pipeline DSL with an alternate Rake application" do
|
203
|
+
project.pipelines.first.rake_application = Rake::Application.new
|
204
|
+
project.invoke
|
205
|
+
output_should_exist
|
206
|
+
end
|
207
|
+
|
208
|
+
it "can be invoked repeatedly to reflected updated changes" do
|
209
|
+
project.invoke
|
210
|
+
age_existing_files
|
211
|
+
|
212
|
+
if respond_to?(:update_jquery)
|
213
|
+
update_jquery
|
214
|
+
else
|
215
|
+
File.open(File.join(tmp, "app/javascripts/jquery.js"), "w") do |file|
|
216
|
+
file.write "var jQuery = {};\njQuery.trim = function() {};\n"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
expected = <<-HERE.gsub(/^ {10}/, '')
|
221
|
+
var jQuery = {};
|
222
|
+
jQuery.trim = function() {};
|
223
|
+
var SC = {};
|
224
|
+
|
225
|
+
SC.hi = function() { console.log("hi"); };
|
226
|
+
HERE
|
227
|
+
|
228
|
+
project.invoke
|
229
|
+
|
230
|
+
output_should_exist(expected)
|
231
|
+
end
|
232
|
+
|
233
|
+
it "can be restarted to reflect new files" do
|
234
|
+
project.invoke
|
235
|
+
age_existing_files
|
236
|
+
|
237
|
+
if respond_to?(:update_history)
|
238
|
+
update_history
|
239
|
+
else
|
240
|
+
File.open(File.join(tmp, "app/javascripts/history.js"), "w") do |file|
|
241
|
+
file.write "var History = {};\n"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
project.invoke
|
246
|
+
|
247
|
+
expected = <<-HERE.gsub(/^ {10}/, '')
|
248
|
+
var History = {};
|
249
|
+
var jQuery = {};
|
250
|
+
var SC = {};
|
251
|
+
|
252
|
+
SC.hi = function() { console.log("hi"); };
|
253
|
+
HERE
|
254
|
+
|
255
|
+
output_should_exist(expected)
|
256
|
+
end
|
257
|
+
|
258
|
+
it "does not generate new files when things haven't changed" do
|
259
|
+
output_file = File.join(tmp, "public/javascripts/application.js")
|
260
|
+
|
261
|
+
project.invoke
|
262
|
+
previous_mtime = File.mtime(output_file)
|
263
|
+
|
264
|
+
sleep 1
|
265
|
+
|
266
|
+
project.invoke
|
267
|
+
File.mtime(output_file).should == previous_mtime
|
268
|
+
end
|
269
|
+
|
270
|
+
it "handles deleted files" do
|
271
|
+
output_file = File.join(tmp, "public/javascripts/application.js")
|
272
|
+
|
273
|
+
project.invoke
|
274
|
+
content = File.read output_file
|
275
|
+
|
276
|
+
delete_files
|
277
|
+
project.invoke
|
278
|
+
|
279
|
+
content.should_not == File.read(output_file)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "the raw pipeline DSL (with block strip_asserts_filter)" do
|
284
|
+
it_behaves_like "the pipeline DSL"
|
285
|
+
|
286
|
+
before do
|
287
|
+
@project = Rake::Pipeline::Project.build do
|
288
|
+
tmpdir "temporary"
|
289
|
+
output "public"
|
290
|
+
|
291
|
+
input tmp, "app/javascripts/*.js" do
|
292
|
+
concat "javascripts/application.js"
|
293
|
+
filter(strip_asserts_filter) { |input| input }
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
describe "the raw pipeline DSL (with before_filter)" do
|
300
|
+
it_behaves_like "the pipeline DSL"
|
301
|
+
|
302
|
+
before do
|
303
|
+
@project = Rake::Pipeline::Project.build do
|
304
|
+
tmpdir "temporary"
|
305
|
+
output "public"
|
306
|
+
|
307
|
+
before_filter Rake::Pipeline::ConcatFilter, "javascripts/application.js"
|
308
|
+
|
309
|
+
input tmp, "app/javascripts/*.js" do
|
310
|
+
filter strip_asserts_filter
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe "the raw pipeline DSL (with simple strip_asserts_filter)" do
|
317
|
+
it_behaves_like "the pipeline DSL"
|
318
|
+
|
319
|
+
before do
|
320
|
+
@project = Rake::Pipeline::Project.build do
|
321
|
+
tmpdir "temporary"
|
322
|
+
output "public"
|
323
|
+
|
324
|
+
input tmp, "app/javascripts/*.js" do
|
325
|
+
concat "javascripts/application.js"
|
326
|
+
filter strip_asserts_filter
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe "using the matcher spec" do
|
333
|
+
def output_should_exist(expected=EXPECTED_JS_OUTPUT)
|
334
|
+
super
|
335
|
+
|
336
|
+
css = File.join(tmp, "public/stylesheets/application.css")
|
337
|
+
|
338
|
+
File.exists?(css).should be_true
|
339
|
+
File.read(css).should == EXPECTED_CSS_OUTPUT
|
340
|
+
|
341
|
+
html = File.join(tmp, "public/index.html")
|
342
|
+
File.exists?(html).should be_true
|
343
|
+
File.read(html).should == EXPECTED_HTML_OUTPUT
|
344
|
+
|
345
|
+
junk = File.join(tmp, "public/junk.txt")
|
346
|
+
File.exists?(junk).should be_false
|
347
|
+
end
|
348
|
+
|
349
|
+
it_behaves_like "the pipeline DSL"
|
350
|
+
|
351
|
+
before do
|
352
|
+
@project = Rake::Pipeline::Project.build do
|
353
|
+
tmpdir "temporary"
|
354
|
+
output "public"
|
355
|
+
|
356
|
+
input File.join(tmp, "app") do
|
357
|
+
match "**/*.js" do
|
358
|
+
filter strip_asserts_filter
|
359
|
+
concat "javascripts/application.js"
|
360
|
+
end
|
361
|
+
|
362
|
+
match "**/*.css" do
|
363
|
+
concat "stylesheets/application.css"
|
364
|
+
end
|
365
|
+
|
366
|
+
match "**/*.html" do
|
367
|
+
concat
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
describe "using multiple pipelines (with after_filters)" do
|
375
|
+
def output_should_exist(expected=EXPECTED_JS_OUTPUT)
|
376
|
+
super
|
377
|
+
|
378
|
+
css = File.join(tmp, "public/stylesheets/application.css")
|
379
|
+
|
380
|
+
File.exists?(css).should be_true
|
381
|
+
File.read(css).should == EXPECTED_CSS_OUTPUT
|
382
|
+
|
383
|
+
html = File.join(tmp, "public/index.html")
|
384
|
+
File.exists?(html).should be_true
|
385
|
+
File.read(html).should == EXPECTED_HTML_OUTPUT
|
386
|
+
|
387
|
+
junk = File.join(tmp, "public/junk.txt")
|
388
|
+
File.exists?(junk).should be_false
|
389
|
+
end
|
390
|
+
|
391
|
+
it_behaves_like "the pipeline DSL"
|
392
|
+
|
393
|
+
before do
|
394
|
+
@project = Rake::Pipeline::Project.build do
|
395
|
+
tmpdir "temporary"
|
396
|
+
output "public"
|
397
|
+
|
398
|
+
app_dir = File.join(tmp, "app")
|
399
|
+
|
400
|
+
after_filter Rake::Pipeline::ConcatFilter do |input|
|
401
|
+
ext = File.extname(input)
|
402
|
+
|
403
|
+
case ext
|
404
|
+
when ".js"
|
405
|
+
"javascripts/application.js"
|
406
|
+
when ".css"
|
407
|
+
"stylesheets/application.css"
|
408
|
+
when ".html"
|
409
|
+
input
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
input app_dir, "**/*.js" do
|
414
|
+
filter strip_asserts_filter
|
415
|
+
end
|
416
|
+
|
417
|
+
input app_dir, "**/*.css"
|
418
|
+
|
419
|
+
input app_dir, "**/*.html"
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
describe "using multiple pipelines" do
|
425
|
+
def output_should_exist(expected=EXPECTED_JS_OUTPUT)
|
426
|
+
super
|
427
|
+
|
428
|
+
css = File.join(tmp, "public/stylesheets/application.css")
|
429
|
+
|
430
|
+
File.exists?(css).should be_true
|
431
|
+
File.read(css).should == EXPECTED_CSS_OUTPUT
|
432
|
+
|
433
|
+
html = File.join(tmp, "public/index.html")
|
434
|
+
File.exists?(html).should be_true
|
435
|
+
File.read(html).should == EXPECTED_HTML_OUTPUT
|
436
|
+
|
437
|
+
junk = File.join(tmp, "public/junk.txt")
|
438
|
+
File.exists?(junk).should be_false
|
439
|
+
end
|
440
|
+
|
441
|
+
it_behaves_like "the pipeline DSL"
|
442
|
+
|
443
|
+
before do
|
444
|
+
@project = Rake::Pipeline::Project.build do
|
445
|
+
tmpdir "temporary"
|
446
|
+
output "public"
|
447
|
+
|
448
|
+
app_dir = File.join(tmp, "app")
|
449
|
+
|
450
|
+
input app_dir, "**/*.js" do
|
451
|
+
filter strip_asserts_filter
|
452
|
+
concat "javascripts/application.js"
|
453
|
+
end
|
454
|
+
|
455
|
+
input app_dir, "**/*.css" do
|
456
|
+
concat "stylesheets/application.css"
|
457
|
+
end
|
458
|
+
|
459
|
+
input app_dir, "**/*.html" do
|
460
|
+
concat
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
describe "using the matcher spec (with multiple inputs to a single pipeline)" do
|
467
|
+
it_behaves_like "the pipeline DSL"
|
468
|
+
|
469
|
+
def tmp1
|
470
|
+
File.join(tmp, 'tmp1')
|
471
|
+
end
|
472
|
+
|
473
|
+
def tmp2
|
474
|
+
File.join(tmp, 'tmp2')
|
475
|
+
end
|
476
|
+
|
477
|
+
def update_jquery
|
478
|
+
File.open(File.join(tmp1, "app/javascripts/jquery.js"), "w") do |file|
|
479
|
+
file.write "var jQuery = {};\njQuery.trim = function() {};\n"
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
def update_history
|
484
|
+
File.open(File.join(tmp1, "app/javascripts/history.js"), "w") do |file|
|
485
|
+
file.write "var History = {};\n"
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
def copy_files
|
490
|
+
INPUTS.each do |name, string|
|
491
|
+
file = name =~ /\.js$/ ? File.join(tmp1, name) : File.join(tmp2, name)
|
492
|
+
|
493
|
+
mkdir_p File.dirname(file)
|
494
|
+
File.open(file, "w") { |f| f.write(string) }
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
def output_should_exist(expected=EXPECTED_JS_OUTPUT)
|
499
|
+
super
|
500
|
+
|
501
|
+
css = File.join(tmp, "public/stylesheets/application.css")
|
502
|
+
|
503
|
+
File.exists?(css).should be_true
|
504
|
+
File.read(css).should == EXPECTED_CSS_OUTPUT
|
505
|
+
|
506
|
+
html = File.join(tmp, "public/index.html")
|
507
|
+
File.exists?(html).should be_true
|
508
|
+
File.read(html).should == EXPECTED_HTML_OUTPUT
|
509
|
+
|
510
|
+
junk = File.join(tmp, "public/junk.txt")
|
511
|
+
File.exists?(junk).should be_false
|
512
|
+
end
|
513
|
+
|
514
|
+
def delete_files
|
515
|
+
FileUtils.rm_rf File.join(tmp1, "app/javascripts/jquery.js")
|
516
|
+
end
|
517
|
+
|
518
|
+
before do
|
519
|
+
tmp1 = self.tmp1
|
520
|
+
tmp2 = self.tmp2
|
521
|
+
|
522
|
+
@project = Rake::Pipeline::Project.build do
|
523
|
+
tmpdir "temporary"
|
524
|
+
output "public"
|
525
|
+
|
526
|
+
inputs [File.join(tmp1, "app"), File.join(tmp2, "app")] do
|
527
|
+
match "**/*.js" do
|
528
|
+
filter strip_asserts_filter
|
529
|
+
concat "javascripts/application.js"
|
530
|
+
end
|
531
|
+
|
532
|
+
match "**/*.css" do
|
533
|
+
concat "stylesheets/application.css"
|
534
|
+
end
|
535
|
+
|
536
|
+
match "**/*.html" do
|
537
|
+
concat
|
538
|
+
end
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
describe "Dynamic dependencies" do
|
546
|
+
shared_examples_for "a pipeline with dynamic files" do
|
547
|
+
it "should handle changes in dynamic imports" do
|
548
|
+
project.invoke
|
549
|
+
|
550
|
+
content = File.read output_file
|
551
|
+
|
552
|
+
content.should == EXPECTED_DYNAMIC_OUTPUT
|
553
|
+
|
554
|
+
sleep 1
|
555
|
+
|
556
|
+
imported_file = File.join tmp, "variables.import"
|
557
|
+
|
558
|
+
File.open imported_file, "w" do |f|
|
559
|
+
f.write "true to trance"
|
560
|
+
end
|
561
|
+
|
562
|
+
project.invoke
|
563
|
+
content = File.read output_file
|
564
|
+
|
565
|
+
content.should include("true to trance")
|
566
|
+
end
|
567
|
+
|
568
|
+
it "should handle changes in dynamic source files" do
|
569
|
+
project.invoke
|
570
|
+
|
571
|
+
content = File.read output_file
|
572
|
+
|
573
|
+
content.should == EXPECTED_DYNAMIC_OUTPUT
|
574
|
+
|
575
|
+
sleep 1
|
576
|
+
|
577
|
+
imported_file = File.join tmp, "app/main.dynamic"
|
578
|
+
|
579
|
+
File.open imported_file, "w" do |f|
|
580
|
+
f.write "true to trance"
|
581
|
+
end
|
582
|
+
|
583
|
+
project.invoke
|
584
|
+
content = File.read output_file
|
585
|
+
|
586
|
+
content.should == "true to trance"
|
587
|
+
end
|
588
|
+
|
589
|
+
it "should handle dynamic dependencies being deleted" do
|
590
|
+
project.invoke
|
591
|
+
|
592
|
+
content = File.read output_file
|
593
|
+
|
594
|
+
content.should == EXPECTED_DYNAMIC_OUTPUT
|
595
|
+
|
596
|
+
sleep 1
|
597
|
+
|
598
|
+
imported_file = File.join tmp, "variables.import"
|
599
|
+
|
600
|
+
File.exists?(imported_file).should be_true
|
601
|
+
|
602
|
+
FileUtils.rm_rf imported_file
|
603
|
+
|
604
|
+
project.invoke
|
605
|
+
end
|
606
|
+
|
607
|
+
it "should not regenerate files when nothing changes" do
|
608
|
+
project.invoke
|
609
|
+
previous_mtime = File.mtime output_file
|
610
|
+
sleep 1 ; project.invoke
|
611
|
+
|
612
|
+
File.mtime(output_file).should == previous_mtime
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
616
|
+
describe "direct dependencies" do
|
617
|
+
let(:project) do
|
618
|
+
Rake::Pipeline::Project.build do
|
619
|
+
tmpdir "temporary"
|
620
|
+
output "public"
|
621
|
+
|
622
|
+
input tmp, "app/*.dynamic" do
|
623
|
+
filter dynamic_import_filter
|
624
|
+
end
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
628
|
+
let(:output_file) { File.join tmp, "public", "app/main.dynamic" }
|
629
|
+
|
630
|
+
it_should_behave_like "a pipeline with dynamic files"
|
631
|
+
end
|
632
|
+
|
633
|
+
describe "transitive dependencies" do
|
634
|
+
let(:project) do
|
635
|
+
Rake::Pipeline::Project.build do
|
636
|
+
tmpdir "temporary"
|
637
|
+
output "public"
|
638
|
+
|
639
|
+
input tmp, "app/*.dynamic" do
|
640
|
+
filter dynamic_import_filter
|
641
|
+
concat "application.dyn"
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
let(:output_file) { File.join tmp, "public", "application.dyn" }
|
647
|
+
|
648
|
+
it_should_behave_like "a pipeline with dynamic files"
|
649
|
+
end
|
650
|
+
end
|
651
|
+
|
652
|
+
it "should work with nested matchers" do
|
653
|
+
project = Rake::Pipeline::Project.build do
|
654
|
+
tmpdir "temporary"
|
655
|
+
output "public"
|
656
|
+
|
657
|
+
input tmp, "app/**/*.js" do
|
658
|
+
match "**/*" do
|
659
|
+
match "**/*.js" do
|
660
|
+
filter strip_asserts_filter
|
661
|
+
concat "javascripts/application.js"
|
662
|
+
end
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
667
|
+
project.invoke
|
668
|
+
|
669
|
+
output_should_exist
|
670
|
+
end
|
671
|
+
|
672
|
+
describe "Handling mistakes" do
|
673
|
+
it "should raise an error when the tmp dir is added directly" do
|
674
|
+
project = Rake::Pipeline::Project.build do
|
675
|
+
output "public"
|
676
|
+
tmpdir "app"
|
677
|
+
|
678
|
+
input "app", "**/*" do
|
679
|
+
concat "tmp.js"
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
expect {
|
684
|
+
project.invoke ; project.invoke
|
685
|
+
}.to raise_error(Rake::Pipeline::TmpInputError)
|
686
|
+
end
|
687
|
+
|
688
|
+
it "should raise an error when the tmp dir is matched" do
|
689
|
+
project = Rake::Pipeline::Project.build do
|
690
|
+
output "public"
|
691
|
+
tmpdir "app/tmp"
|
692
|
+
|
693
|
+
input "app" do
|
694
|
+
# to generate temporary files
|
695
|
+
# which can be matched in the second invocation
|
696
|
+
match "**/*.js" do
|
697
|
+
concat "app.js"
|
698
|
+
end
|
699
|
+
|
700
|
+
match "tmp/**/*" do
|
701
|
+
concat "tmp.js"
|
702
|
+
end
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
expect {
|
707
|
+
project.invoke ; project.invoke
|
708
|
+
}.to raise_error(Rake::Pipeline::TmpInputError)
|
709
|
+
end
|
710
|
+
|
711
|
+
it "should not raise an error for internal temporary files" do
|
712
|
+
# Create a project with multiple filters and build
|
713
|
+
# steps to create intermediate build files
|
714
|
+
project = Rake::Pipeline::Project.build do
|
715
|
+
output "public"
|
716
|
+
tmpdir "temporary"
|
717
|
+
|
718
|
+
input tmp, "app/**/*" do
|
719
|
+
match "*.js" do
|
720
|
+
concat "application.js"
|
721
|
+
end
|
722
|
+
|
723
|
+
match "*.css" do
|
724
|
+
concat "application.css"
|
725
|
+
end
|
726
|
+
|
727
|
+
match "*.{js,css}" do
|
728
|
+
concat "every_file.application"
|
729
|
+
end
|
730
|
+
end
|
731
|
+
end
|
732
|
+
|
733
|
+
expect {
|
734
|
+
project.invoke
|
735
|
+
}.to_not raise_error(Rake::Pipeline::TmpInputError)
|
736
|
+
end
|
737
|
+
end
|
738
|
+
end
|