-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
98 lines (80 loc) · 2.45 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require "bundler/gem_tasks"
desc "Set up and run tests"
task :default => [:test, :"jasmine:ci"]
desc "Run tests"
task :test do
sh "bundle exec rspec spec"
end
task :travis do
["rake test", "rake jasmine:ci"].each do |cmd|
puts "Starting to run #{cmd}..."
system("export DISPLAY=:99.0 && bundle exec #{cmd}")
raise "#{cmd} failed!" unless $?.exitstatus == 0
end
end
desc "Autobuild JS/SCSS"
task :watch do
require "bundler/setup"
require "fssm"
monitor = FSSM::Monitor.new
monitor.path "coffee", "**/*.coffee" do
compile_block = lambda do |basename, filename|
puts "Compiling coffee to minified js..."
coffee_file = "coffee/#{filename}"
puts "\t#{coffee_file}"
Rake::Task["js:compile_cs"].tap(&:reenable).invoke
Rake::Task["js:minify_js"].tap(&:reenable).invoke
end
update &compile_block
delete &compile_block
create &compile_block
end
monitor.run
end
namespace :js do
desc "Compiles CS & minifies JS"
task :compile do
puts "Compiling coffee to minified js..."
Rake::Task["js:compile_cs"].tap(&:reenable).invoke()
Rake::Task["js:minify_js"].tap(&:reenable).invoke()
puts "\t\t->done\n\n"
end
task :compile_cs, :filename do |t, args|
require "coffee-script"
coffee_script = ""
%w{bloomfilter bitarray zlib}.each do |library|
filename = "coffee/#{library}.coffee"
puts "\t#{filename}"
coffee_script += File.read(filename) + "\n"
end
js_file = "js/json-bloomfilter.js"
directory_name = File.dirname js_file
FileUtils.mkdir_p(directory_name) unless File.exists? directory_name
puts "\t\t->#{js_file}"
File.open(js_file, "w+") do |f|
f.print CoffeeScript.compile(coffee_script, :no_wrap => true)
end
end
task :minify_js, :filename do |t, args|
require "yui/compressor"
filename = args[:filename]
compressor = YUI::JavaScriptCompressor.new
js_file = "js/json-bloomfilter.js"
min_file = "js/json-bloomfilter.min.js"
puts "\t\t->#{min_file}"
directory_name = File.dirname min_file
FileUtils.mkdir_p(directory_name) unless File.exists? directory_name
File.open(min_file, "w+") do |f|
f.print compressor.compress(File.read(js_file))
end
File.delete js_file
end
end
begin
require 'jasmine'
load 'jasmine/tasks/jasmine.rake'
rescue LoadError
task :jasmine do
abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
end
end